← All notes

Go container/heap: heap operations for a custom type

Answer: Heap operations in this package work with any type that implements Interface.

The heap property

In this tree, every node is the minimum-valued node of its subtree.

The minimum element in the tree is the root, at index 0.

Priority queues are a common use of a heap.

Push adds items. Pop takes the highest-priority item off the queue.

The interface

Init sets up the heap invariants.

After an element at an index changes, Fix puts the heap back in order.

Remove removes and returns the element at index i from the heap.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, container/heap package reference; Go, container/heap source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, container/heap package reference; Go, container/heap source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:d26x7dwn

iinventedlight. 2026. "Go container/heap: heap operations for a custom type." iinventedlight Library, iil:note:d26x7dwn, version of 2026-11-24. https://iinventedlight.com/library/notes/go-container-heap/. License: CC-BY-4.0.

@misc{iil_note_d26x7dwn,
  author = {{iinventedlight}},
  title = {{Go container/heap: heap operations for a custom type}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-24},
  url = {https://iinventedlight.com/library/notes/go-container-heap/},
  note = {Permanent ID iil:note:d26x7dwn. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-container-heap.md.