github.com/LdDl/ch@v1.7.8/heap_dist.go (about)

     1  package ch
     2  
     3  type vertexDist struct {
     4  	id   int64
     5  	dist float64
     6  }
     7  
     8  type vertexDistHeap []*vertexDist
     9  
    10  func (h vertexDistHeap) Len() int            { return len(h) }
    11  func (h vertexDistHeap) Less(i, j int) bool  { return h[i].dist < h[j].dist }
    12  func (h vertexDistHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
    13  func (h *vertexDistHeap) Push(x interface{}) { *h = append(*h, x.(*vertexDist)) }
    14  func (h *vertexDistHeap) Pop() interface{} {
    15  	heapSize := len(*h)
    16  	lastNode := (*h)[heapSize-1]
    17  	*h = (*h)[0 : heapSize-1]
    18  	return lastNode
    19  }