This module implements a crit bit tree which is an efficient container for a sorted set of strings, or for a sorted mapping of strings. Based on the excellent paper by Adam Langley. (A crit bit tree is a form of radix tree or patricia trie.)
CritBitTree[T] = object root: Node[T] count: int
T
or as a set of strings if T
is void. proc len[T](c: CritBitTree[T]): int
proc contains[T](c: CritBitTree[T]; key: string): bool {.inline.}
proc hasKey[T](c: CritBitTree[T]; key: string): bool {.inline.}
proc containsOrIncl[T](c: var CritBitTree[T]; key: string; val: T): bool
c[key] = val
is performed. proc containsOrIncl(c: var CritBitTree[void]; key: string): bool {.raises: [], tags: [].}
proc inc(c: var CritBitTree[int]; key: string) {.raises: [], tags: [].}
proc incl(c: var CritBitTree[void]; key: string) {.raises: [], tags: [].}
proc `[]=`[T](c: var CritBitTree[T]; key: string; val: T)
proc `[]`[T](c: CritBitTree[T]; key: string): T {.inline, .}
c[key]
. If key is not in t, the KeyError
exception is raised. One can check with hasKey
whether the key exists. proc `[]`[T](c: var CritBitTree[T]; key: string): var T {.inline, .}
c[key]
. The value can be modified. If key is not in t, the KeyError
exception is raised. proc mget[T](c: var CritBitTree[T]; key: string): var T {.inline, deprecated.}
c[key]
. The value can be modified. If key is not in t, the KeyError
exception is raised. Use ```[]``` instead. proc excl[T](c: var CritBitTree[T]; key: string)
proc `$`[T](c: CritBitTree[T]): string
{keyA: value, keyB: value}
, {:}
If T is void the outputs look like: {keyA, keyB}
, {}
. iterator keys[T](c: CritBitTree[T]): string
iterator values[T](c: CritBitTree[T]): T
iterator mvalues[T](c: var CritBitTree[T]): var T
iterator items[T](c: CritBitTree[T]): string
iterator pairs[T](c: CritBitTree[T]): tuple[key: string, val: T]
iterator mpairs[T](c: var CritBitTree[T]): tuple[key: string, val: var T]
iterator itemsWithPrefix[T](c: CritBitTree[T]; prefix: string; longestMatch = false): string
iterator keysWithPrefix[T](c: CritBitTree[T]; prefix: string; longestMatch = false): string
iterator valuesWithPrefix[T](c: CritBitTree[T]; prefix: string; longestMatch = false): T
iterator mvaluesWithPrefix[T](c: var CritBitTree[T]; prefix: string; longestMatch = false): var T
iterator pairsWithPrefix[T](c: CritBitTree[T]; prefix: string; longestMatch = false): tuple[ key: string, val: T]
iterator mpairsWithPrefix[T](c: var CritBitTree[T]; prefix: string; longestMatch = false): tuple[key: string, val: var T]
© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/critbits.html