github.com/LdDl/ch@v1.7.8/heap_importance.go (about) 1 package ch 2 3 type importanceHeap []*Vertex 4 5 func (h importanceHeap) Len() int { return len(h) } 6 func (h importanceHeap) Less(i, j int) bool { return h[i].importance < h[j].importance } 7 func (h importanceHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } 8 func (h *importanceHeap) Push(x interface{}) { *h = append(*h, x.(*Vertex)) } 9 func (h *importanceHeap) Pop() interface{} { 10 heapSize := len(*h) 11 lastNode := (*h)[heapSize-1] 12 *h = (*h)[0 : heapSize-1] 13 return lastNode 14 } 15 func (h importanceHeap) Peek() *Vertex { 16 lastNode := h[0] 17 return lastNode 18 }