Skip to content

serializeHeapJson<A>(heap): SerializedHeap<A>

Defined in: packages/heap/src/serialization/json.ts:70

Capture a heap as a SerializedHeap. O(n) time and space — a copy of the internal node array plus the discriminants, nothing more.

The snapshot is faithful, not canonical: it records the exact internal layout, never the order function (functions do not serialize — restoring re-supplies it, see deserializeHeapJson), and never a reheapified equivalent. The nodes are copied defensively, so later mutation of either the heap or the payload cannot reach the other.

A

Heap<A>

SerializedHeap<A>

With code FOREIGN_STRUCTURE when heap was not produced by this package’s heap factories — including a priority queue passed by mistake, which carries the package’s state bridge but not a heap kind.