Package-level declarations

Types

Link copied to clipboard
data class ImmutableTreeNode<T>(val value: T, val children: PersistentList<ImmutableTreeNode<T>> = persistentListOf())

A node in an immutable, persistent n-ary tree. Each node holds a value and an ordered PersistentList of children; nodes never carry a parent back-reference, so a subtree is a self-contained, acyclic value.

Functions

Link copied to clipboard

Returns the number of edges on the longest path between this node and a descendant leaf (0 for a leaf). Implemented iteratively, so it is safe on arbitrarily deep trees.

Link copied to clipboard

Returns this subtree's nodes in level-order (breadth-first: the receiver, then its children, then their children, and so on). Implemented iteratively, so it is safe on arbitrarily deep trees.

Link copied to clipboard

Counts all descendants of this node; the receiver itself is not counted (matching the core TreeNode.nodeCount). Implemented iteratively, so it is safe on arbitrarily deep trees.

Link copied to clipboard

Returns this subtree's nodes in post-order (each child subtree in order, then the receiver last). Implemented iteratively, so it is safe on arbitrarily deep trees.

Link copied to clipboard

Returns this subtree's nodes in pre-order (the receiver first, then each child subtree in order). Implemented iteratively, so it is safe on arbitrarily deep trees.