]> git.giacomolli.uk - onechat/blobdiff - build_queue.go
Order daemon and storage declarations
[onechat] / build_queue.go
index 53e804df464a7f9477466ec81d2876c3778c72fe..540e396091f4023528d6d31edabcb61f438b8856 100644 (file)
@@ -14,14 +14,6 @@ const (
        buildLeafWindow = 8
 )
 
        buildLeafWindow = 8
 )
 
-func newBuildQueue() *BuildQueue {
-       return &BuildQueue{
-               queued:  make(map[NodeKey]bool),
-               running: make(map[NodeKey]bool),
-               failed:  make(map[NodeKey]bool),
-       }
-}
-
 // BuildQueue holds the nodes that wait for a model build. A leaf joins it when
 // its message is too long to be its own node. A merge joins it when both of its
 // children are built and their texts do not fit in one node. So the core never
 // BuildQueue holds the nodes that wait for a model build. A leaf joins it when
 // its message is too long to be its own node. A merge joins it when both of its
 // children are built and their texts do not fit in one node. So the core never
@@ -42,6 +34,17 @@ type BuildQueue struct {
        retry   []NodeKey
 }
 
        retry   []NodeKey
 }
 
+// BuildMergeHeap holds the merges that can start, by the end of their context.
+type BuildMergeHeap []NodeKey
+
+func newBuildQueue() *BuildQueue {
+       return &BuildQueue{
+               queued:  make(map[NodeKey]bool),
+               running: make(map[NodeKey]bool),
+               failed:  make(map[NodeKey]bool),
+       }
+}
+
 // AddLeaf adds the leaf of message id. The IDs must come in increasing order.
 func (q *BuildQueue) AddLeaf(id int) {
        q.leaves = append(q.leaves, id)
 // AddLeaf adds the leaf of message id. The IDs must come in increasing order.
 func (q *BuildQueue) AddLeaf(id int) {
        q.leaves = append(q.leaves, id)
@@ -82,8 +85,10 @@ func (q *BuildQueue) Next() (NodeKey, bool) {
 // Done removes a built node from the queue.
 func (q *BuildQueue) Done(key NodeKey) {
        delete(q.running, key)
 // Done removes a built node from the queue.
 func (q *BuildQueue) Done(key NodeKey) {
        delete(q.running, key)
+
        if key.level > 0 {
                delete(q.queued, key)
        if key.level > 0 {
                delete(q.queued, key)
+
                return
        }
 
                return
        }
 
@@ -96,6 +101,7 @@ func (q *BuildQueue) Done(key NodeKey) {
 // Fail keeps a node in the queue, but it cannot start until Retry.
 func (q *BuildQueue) Fail(key NodeKey) {
        delete(q.running, key)
 // Fail keeps a node in the queue, but it cannot start until Retry.
 func (q *BuildQueue) Fail(key NodeKey) {
        delete(q.running, key)
+
        if key.level > 0 {
                q.retry = append(q.retry, key)
                return
        if key.level > 0 {
                q.retry = append(q.retry, key)
                return
@@ -107,6 +113,7 @@ func (q *BuildQueue) Fail(key NodeKey) {
 // Retry lets the failed nodes start again.
 func (q *BuildQueue) Retry() {
        clear(q.failed)
 // Retry lets the failed nodes start again.
 func (q *BuildQueue) Retry() {
        clear(q.failed)
+
        for _, key := range q.retry {
                heap.Push(&q.merges, key)
        }
        for _, key := range q.retry {
                heap.Push(&q.merges, key)
        }
@@ -131,9 +138,6 @@ func (q *BuildQueue) nextLeaf() (NodeKey, bool) {
        return NodeKey{}, false
 }
 
        return NodeKey{}, false
 }
 
-// BuildMergeHeap holds the merges that can start, by the end of their context.
-type BuildMergeHeap []NodeKey
-
 func (h BuildMergeHeap) Len() int {
        return len(h)
 }
 func (h BuildMergeHeap) Len() int {
        return len(h)
 }