In Go, you can implement a heap as such: https://golang.org/src/container/heap/example_pq_test.go
You implement the sort.Interface
, Pop
, and Push
and you've got yourself a priority queue/heap. In the example of both Pop
and Push
implementations the heap.Fix
function isn't called. I see that heap.Init
is called, so I can understand some heap-ifying happening then. However, you are able to push and pop items, which runs your own code, and the heap property is maintained.
If you push or pop items after init without calling heap.fix
, how does the heap property get maintained?
Here's a playground of the example: https://play.golang.org/p/wE413xwmxE