diff --git a/internal/servicecheck/neighbours.go b/internal/servicecheck/neighbours.go index aca6032..0f8145e 100644 --- a/internal/servicecheck/neighbours.go +++ b/internal/servicecheck/neighbours.go @@ -103,24 +103,6 @@ func (c *Checker) checkNeighbours(nh []*Neighbour) { } } -type Uint64Heap []uint64 - -func (h Uint64Heap) Len() int { return len(h) } -func (h Uint64Heap) Less(i, j int) bool { return h[i] > h[j] } // we want a max-heap, therefore the inversed condition -func (h Uint64Heap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } - -func (h *Uint64Heap) Push(x any) { - *h = append(*h, x.(uint64)) -} - -func (h *Uint64Heap) Pop() any { - n := len(*h) - x := (*h)[n-1] - *h = (*h)[0 : n-1] - - return x -} - func (c *Checker) filterNeighbours(nh []*Neighbour) []*Neighbour { m := make(map[uint64]*Neighbour, c.NeighbourLimit+1) @@ -155,3 +137,21 @@ func sha256Uint64(s string) uint64 { h := sha256.Sum256([]byte(s)) return binary.BigEndian.Uint64(h[:8]) } + +type Uint64Heap []uint64 + +func (h Uint64Heap) Len() int { return len(h) } +func (h Uint64Heap) Less(i, j int) bool { return h[i] > h[j] } // we want a max-heap, therefore the inversed condition +func (h Uint64Heap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } + +func (h *Uint64Heap) Push(x any) { + *h = append(*h, x.(uint64)) +} + +func (h *Uint64Heap) Pop() any { + n := len(*h) + x := (*h)[n-1] + *h = (*h)[0 : n-1] + + return x +}