summaryrefslogtreecommitdiff
path: root/worker/types/thread.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker/types/thread.go')
-rw-r--r--worker/types/thread.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/worker/types/thread.go b/worker/types/thread.go
index 18b31e9..48e4a00 100644
--- a/worker/types/thread.go
+++ b/worker/types/thread.go
@@ -17,14 +17,24 @@ type Thread struct {
}
func (t *Thread) AddChild(child *Thread) {
+ t.insertCmp(child, func(child, iter *Thread) bool { return true })
+}
+
+func (t *Thread) OrderedInsert(child *Thread) {
+ t.insertCmp(child, func(child, iter *Thread) bool { return child.Uid > iter.Uid })
+}
+
+func (t *Thread) insertCmp(child *Thread, cmp func(*Thread, *Thread) bool) {
if t.FirstChild == nil {
t.FirstChild = child
} else {
+ start := &Thread{Uid: t.FirstChild.Uid, NextSibling: t.FirstChild}
var iter *Thread
- for iter = t.FirstChild; iter.NextSibling != nil; iter = iter.NextSibling {
+ for iter = start; iter.NextSibling != nil && cmp(child, iter); iter = iter.NextSibling {
}
- child.PrevSibling = iter
+ child.NextSibling = iter.NextSibling
iter.NextSibling = child
+ t.FirstChild = start.NextSibling
}
child.Parent = t
}