-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorder bugfix: weak relationships were not releasing, prioritize reo…
…rder funcs (#33) * reorder bugfix: weak releationships were not releasing, prioritize reorder funcs * lint * do not run all actions twice
- Loading branch information
Showing
7 changed files
with
90 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: Test and coverage | ||
|
||
on: [push, pull_request] | ||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
on: [push, pull_request] | ||
on: [push] | ||
name: Unit Tests | ||
jobs: | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
package nject | ||
package nject | ||
|
||
import ( | ||
"container/heap" | ||
) | ||
|
||
// Code below originated with the container/heap documentation | ||
|
||
type IntHeap []int | ||
type IntsHeap [][2]int | ||
|
||
func (h IntHeap) Len() int { return len(h) } | ||
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] } | ||
func (h IntHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } | ||
func (h IntsHeap) Len() int { return len(h) } | ||
func (h IntsHeap) Less(i, j int) bool { return h[i][0] < h[j][0] } | ||
func (h IntsHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } | ||
|
||
func (h *IntHeap) Push(x interface{}) { | ||
func (h *IntsHeap) Push(x interface{}) { | ||
// Push and Pop use pointer receivers because they modify the slice's length, | ||
// not just its contents. | ||
*h = append(*h, x.(int)) | ||
*h = append(*h, x.([2]int)) | ||
} | ||
|
||
func (h *IntHeap) Pop() interface{} { | ||
func (h *IntsHeap) Pop() interface{} { | ||
old := *h | ||
n := len(old) | ||
x := old[n-1] | ||
*h = old[0 : n-1] | ||
return x | ||
} | ||
|
||
func push(h *IntsHeap, funcs []*provider, i int) { | ||
priority := i | ||
if i < len(funcs) && funcs[i].reorder { | ||
priority -= len(funcs) | ||
} | ||
heap.Push(h, [2]int{priority, i}) | ||
} | ||
|
||
func pop(h *IntsHeap) int { | ||
//nolint:errcheck // we trust the type | ||
x := heap.Pop(h).([2]int) | ||
return x[1] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters