]> git.giacomolli.uk - onechat/blobdiff - build_queue.go
Check Go names and declarations with revive
[onechat] / build_queue.go
index 2458f5a185100cfd43a8a33c0db42e0716030f28..53e804df464a7f9477466ec81d2876c3778c72fe 100644 (file)
@@ -16,9 +16,9 @@ const (
 
 func newBuildQueue() *BuildQueue {
        return &BuildQueue{
-               queued:  make(map[nodeKey]bool),
-               running: make(map[nodeKey]bool),
-               failed:  make(map[nodeKey]bool),
+               queued:  make(map[NodeKey]bool),
+               running: make(map[NodeKey]bool),
+               failed:  make(map[NodeKey]bool),
        }
 }
 
@@ -36,10 +36,10 @@ func newBuildQueue() *BuildQueue {
 type BuildQueue struct {
        leaves  []int
        merges  BuildMergeHeap
-       queued  map[nodeKey]bool
-       running map[nodeKey]bool
-       failed  map[nodeKey]bool
-       retry   []nodeKey
+       queued  map[NodeKey]bool
+       running map[NodeKey]bool
+       failed  map[NodeKey]bool
+       retry   []NodeKey
 }
 
 // AddLeaf adds the leaf of message id. The IDs must come in increasing order.
@@ -49,7 +49,7 @@ func (q *BuildQueue) AddLeaf(id int) {
 
 // AddMerge adds a merge whose children are built. A merge that is in the queue
 // already stays as it is.
-func (q *BuildQueue) AddMerge(key nodeKey) {
+func (q *BuildQueue) AddMerge(key NodeKey) {
        if q.queued[key] {
                return
        }
@@ -59,14 +59,14 @@ func (q *BuildQueue) AddMerge(key nodeKey) {
 }
 
 // Next returns the next node that can start, and marks it as running.
-func (q *BuildQueue) Next() (nodeKey, bool) {
+func (q *BuildQueue) Next() (NodeKey, bool) {
        if len(q.running) >= buildMax {
-               return nodeKey{}, false
+               return NodeKey{}, false
        }
 
        leaf, found := q.nextLeaf()
        if len(q.merges) > 0 && (!found || nodeEnd(q.merges[0].level, q.merges[0].index) <= leaf.index) {
-               key := heap.Pop(&q.merges).(nodeKey)
+               key := heap.Pop(&q.merges).(NodeKey)
                q.running[key] = true
 
                return key, true
@@ -80,7 +80,7 @@ func (q *BuildQueue) Next() (nodeKey, bool) {
 }
 
 // Done removes a built node from the queue.
-func (q *BuildQueue) Done(key nodeKey) {
+func (q *BuildQueue) Done(key NodeKey) {
        delete(q.running, key)
        if key.level > 0 {
                delete(q.queued, key)
@@ -94,7 +94,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) {
+func (q *BuildQueue) Fail(key NodeKey) {
        delete(q.running, key)
        if key.level > 0 {
                q.retry = append(q.retry, key)
@@ -120,19 +120,19 @@ func (q *BuildQueue) Running() int {
 }
 
 // nextLeaf returns the oldest leaf in the window that can start.
-func (q *BuildQueue) nextLeaf() (nodeKey, bool) {
+func (q *BuildQueue) nextLeaf() (NodeKey, bool) {
        for _, id := range q.leaves[:min(len(q.leaves), buildLeafWindow)] {
-               key := nodeKey{0, id}
+               key := NodeKey{0, id}
                if !q.running[key] && !q.failed[key] {
                        return key, true
                }
        }
 
-       return nodeKey{}, false
+       return NodeKey{}, false
 }
 
 // BuildMergeHeap holds the merges that can start, by the end of their context.
-type BuildMergeHeap []nodeKey
+type BuildMergeHeap []NodeKey
 
 func (h BuildMergeHeap) Len() int {
        return len(h)
@@ -147,7 +147,7 @@ func (h BuildMergeHeap) Swap(a, b int) {
 }
 
 func (h *BuildMergeHeap) Push(value any) {
-       *h = append(*h, value.(nodeKey))
+       *h = append(*h, value.(NodeKey))
 }
 
 func (h *BuildMergeHeap) Pop() any {