I came across priorityqueue example under heap.Interface package
Link: https://golang.org/pkg/container/heap/#Interface
For Push()
and Pop()
function required by heap.Interface
, the implementation is on pointer receiver. But for Swap()
function required by sort.Interface
, the implementation is on value.
Why this difference ?
As per my understanding, Push()
and Pop()
are implemented on pointer type, as they need to change the underlying data. But going by that logic, Swap()
should also be implemented on pointer type.
How and why does the Swap()
implementation work on value, but Push()
and Pop()
do not ?