Mutable red-black tree. Can be used to implement data structures like map or set.
Procs
proc newRBTreeM*[K, V](): RBTreeM[K, V] {.
inline.}- Creates empty mutable red-black tree with keys of type K and values of type V Source Edit
proc newRBSetM*[K](): RBTreeM[K, void] {.
inline.}- Creates empty mutable red-black tree with keys of type K and without values Source Edit
proc isEmpty*(t: RBTreeM): bool {.
inline.}- Checks if the tree t is empty. Source Edit
proc len*(t: RBTreeM): int {.
inline.}- Returns the number of elements in the tree Source Edit
proc add*[K, V: NonVoid](t: RBTreeM[K, V]; k: K; v: V): RBTreeM[K, V] {.
discardable.}- Sets the key k to the value v in the tree t. Returns t. Source Edit
proc add*[K](t: RBTreeM[K, void]; k: K): RBTreeM[K, void] {.
discardable.}- Sets the value k in the set t. Returns t. Source Edit
proc mkRBTreeM*[K, V: NonVoid](arr: openarray[(K, V)]): RBTreeM[K, V]
- Creates new tree from the key/value pairs arr. Source Edit
proc mkRBSetM*[K](arr: openarray[K]): RBTreeM[K, void]
- Creates new set from the values arr. Source Edit
proc hasKey*[K, V](t: RBTreeM[K, V]; k: K): bool
- Checks if the tree t has the key k. Source Edit
proc getOrDefault*[K, V: NonVoid](t: RBTreeM[K, V]; k: K): V
- Returns the value associated with the key k or V(). Source Edit
proc maybeGet*[K, V: NonVoid](t: RBTreeM[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 min*[K, V](t: RBTreeM[K, V]): K
- Finds the minimal key value in t. Source Edit
proc max*[K, V](t: RBTreeM[K, V]): K
- Finds the maximal key value in t. Source Edit
proc equals*[K, V: NonVoid](l, r: RBTreeM[K, V]): bool
- Checks for the equality of l and r. Source Edit
proc `==`*[K, V: NonVoid](l, r: RBTreeM[K, V]): bool
- Checks for the equality of l and r. Source Edit
proc equals*[K](l, r: RBTreeM[K, void]): bool
- Checks for the equality of l and r. Source Edit
proc `==`*[K](l, r: RBTreeM[K, void]): bool
- Checks for the equality of l and r. Source Edit
proc del*[K, V](t: RBTreeM[K, V]; k: K): RBTreeM[K, V] {.
discardable.}- Returns the new tree from t where the key k is unset. Source Edit
proc treeRepr*(t: RBTreeM): string
- Converts tree t to string. Source Edit
proc `$`*(t: RBTreeM): string
- Converts tree t to string. Source Edit
Iterators
iterator items*[K, V](t: RBTreeM[K, V]): K
- Iterates over the keys of the tree t. Source Edit
iterator keys*(t: RBTreeM): auto
- Iterates over the keys of the tree t. Source Edit
iterator pairs*[K, V: NonVoid](t: RBTreeM[K, V]): (K, V)
- Iterates over the key/value pairs of the tree t. Source Edit
iterator mpairs*[K, V: NonVoid](t: var RBTreeM[K, V]): (K, var V)
- Iterates over the key/value pairs of the tree t where value is mutable. Source Edit
iterator values*(t: RBTreeM): auto
- Iterates over the values of the tree t. Source Edit
iterator mvalues*[K, V](t: var RBTreeM[K, V]): var V
- Iterates over the values of the tree t where value is mutable. Source Edit