View Source PairingHeap.Node (pairing_heap v0.2.1)

Defines the PairingHeap.Node struct and functions for creating and combining nodes.

The functions PairingHeap.Node.merge/3 and ParingHeap.Node.merge/2 combine pairs and lists of nodes, respectively, in a way that preserves the heap property. Both of these functions take as an argument the predicate ordered?/2, where ordered?.(node1, node2) returns true if node1 is correctly ordered relatively to node2 according to the heap property.

Summary

Functions

Return true if any node in the tree defined by node contains data, and false otherwise.

Merge a list of nodes into a single node that satisfies the heap property.

Link a pair of nodes into a single node that satisfies the heap property.

Create a new pairing-heap node with associated data and a list of zero or more child nodes.

Types

@type data() :: any()
@type ordered_fn() :: (t(), t() -> boolean())
@type t() :: %PairingHeap.Node{children: [t()], data: data()}

Functions

Link to this function

member?(node, data, ordered?)

View Source
@spec member?(t(), any(), ordered_fn()) :: boolean()

Return true if any node in the tree defined by node contains data, and false otherwise.

This recuresively searches the children only if the data can be among the children according to the heap property.

@spec merge([t()], ordered_fn()) :: t()

Merge a list of nodes into a single node that satisfies the heap property.

The pairwise recursive merger follows the algorithm described in the original paper, which has O(log n) amortized run time.

Link to this function

merge(node1, node2, ordered?)

View Source
@spec merge(t(), t(), ordered_fn()) :: t()

Link a pair of nodes into a single node that satisfies the heap property.

One of the given nodes is a parent and the other is the child, as determined by ordered?/2. The child node is prepended to the list of child nodes for the parent. No other maintenance is required for the individual nodes in a pairing heap. It follows that meld runs in O(1) time.

@spec new(data(), [t()]) :: t()

Create a new pairing-heap node with associated data and a list of zero or more child nodes.