Skip to content

Instantly share code, notes, and snippets.

@sausheong
Created May 3, 2022 03:03
Show Gist options
  • Select an option

  • Save sausheong/b539b8f1b38c57c11b86edff4e511a78 to your computer and use it in GitHub Desktop.

Select an option

Save sausheong/b539b8f1b38c57c11b86edff4e511a78 to your computer and use it in GitHub Desktop.
mst
type Heap []NodePair
func (h Heap) Len() int { return len(h) }
func (h Heap) Less(i, j int) bool { return h[i].edge.weight < h[j].edge.weight }
func (h Heap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x any) { *h = append(*h, x.(NodePair)) }
func (h *Heap) Pop() any {
old := *h
n := len(old)
item := old[n-1]
*h = old[0 : n-1]
return item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment