Recursively merges other into this tree. For overlapping keys, child subtrees are merged in turn. For keys present only in other, the corresponding subtree reference is adopted directly.
Returns true if the given value appears as a key anywhere in this tree (recursive).
Structural recursive equality. Order across siblings is irrelevant; two trees are equal if they have the same set of keys and each key's subtree is recursively equal.
Recursively searches the tree for the first subtree rooted at key.
the matching subtree, or undefined if absent.
Returns all keys whose subtrees are leaves.
Returns single-key trees representing each leaf key in this tree, preserving the original key-to-empty-subtree mapping.
Returns the keys at the given depth. Depth 0 returns the root keys. Negative depths or depths beyond the tree's height return an empty array.
Returns the existing child for key, or inserts and returns a new empty Tree if absent.
Returns the trees at the given depth. Depth 0 returns a singleton list containing this tree. Negative depths or depths beyond the tree's height return an empty array.
Returns true if the given key is an immediate child of this tree.
Returns true if this tree has no children. An empty tree is considered a leaf.
Returns the total number of nodes (keys) in the tree, counted recursively.
Produces a formatted string representation of the tree structure using a |-- ASCII style, Uses a |-- ASCII style with a 3-space indent per level and no trailing newline.
Returns the keys at the root of this tree.
Splits this tree into one tree per root key. If the tree has a single root, returns a singleton list containing this tree.
A tree data structure with a tree-shaped public API.
Children are kept in a private, ordered array of {key, value} entries (not a native Map, whose reference-identity keys would break value-equality). Access is only through the read API; lookups use treeKeysEqual, which compares keys by value and treats null/undefined as a distinct key.