Immutable red-black tree. Can be used to implement data structures like map or set.
Procs
proc newRBTree*[K, V: NonVoid](): RBTree[K, V]
- Creates empty immutable red-black tree with keys of type K and values of type V Source Edit
proc newRBSet*[K](): RBTree[K, void]
- Creates empty immutable red-black tree with keys of type K and without values Source Edit
proc isEmpty*(t: RBTree): bool {.
inline.}- Checks if the tree t is empty. Source Edit
proc len*(t: RBTree): int
- Returns the number of elements in the tree Source Edit
proc add*[K, V: NonVoid](t: RBTree[K, V]; k: K; v: V): RBTree[K, V]
- Returns the new tree from t where key k is set to value v. Source Edit
proc add*[K](t: RBTree[K, void]; k: K): RBTree[K, void]
- Returns the new set from t where k is present. Source Edit
proc mkRBTree*[K, V: NonVoid](arr: openarray[(K, V)]): RBTree[K, V]
- Creates new tree from the key/value pairs arr. Source Edit
proc mkRBSet*[K](arr: openarray[K]): RBTree[K, void]
- Creates new set from the values arr. Source Edit
proc hasKey*[K, V](t: RBTree[K, V]; k: K): bool
- Checks if the tree t has the key k. Source Edit
proc getOrDefault*[K, V: NonVoid](t: RBTree[K, V]; k: K): V
- Returns the value associated with the key k or V(). Source Edit
proc maybeGet*[K, V: NonVoid](t: RBTree[K, V]; k: K; v: var V): bool
- Puts the value associated with the key k into v and returns true. If the key is absent, returns false. Source Edit
proc del*[K, V: NonVoid](t: RBTree[K, V]; k: K): RBTree[K, V]
- Returns the new tree from t where the key k is unset. Source Edit
proc del*[K](t: RBTree[K, void]; k: K): RBTree[K, void]
- Returns the new tree from t where the key k is unset. Source Edit
proc equals*[K, V: NonVoid](l, r: RBTree[K, V]): bool
- Checks for the equality of l and r. Source Edit
proc `==`*[K, V: NonVoid](l, r: RBTree[K, V]): bool
- Checks for the equality of l and r. Source Edit
proc equals*[K](l, r: RBTree[K, void]): bool
- Checks for the equality of l and r. Source Edit
proc `==`*[K](l, r: RBTree[K, void]): bool
- Checks for the equality of l and r. Source Edit
proc treeRepr*(t: RBTree): string
- Converts tree t to string. Source Edit
proc `$`*(t: RBTree): string
- Converts tree t to string. Source Edit
Iterators
iterator items*[K, V](t: RBTree[K, V]): K
- Iterates over the keys of the tree t. Source Edit
iterator keys*(t: RBTree): auto
- Iterates over the keys of the tree t. Source Edit
iterator pairs*[K, V: NonVoid](t: RBTree[K, V]): (K, V)
- Iterates over the key/value pairs of the tree t. Source Edit
iterator values*(t: RBTree): auto
- Iterates over the values of the tree t. Source Edit