diff options
author | Araq <rumpf_a@web.de> | 2019-05-28 16:05:26 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-05-28 16:05:33 +0200 |
commit | 4a9e6361ceb43648678e0a3e6ec878f723fc6b71 (patch) | |
tree | 14b83c6da3d51a247181a62ffc98f7a176b4cc2c /lib/pure | |
parent | 35593700fa8639e12a53db25f4cc1a9d67b5ad6d (diff) | |
download | Nim-4a9e6361ceb43648678e0a3e6ec878f723fc6b71.tar.gz |
fixes #11344
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/collections/critbits.nim | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/pure/collections/critbits.nim b/lib/pure/collections/critbits.nim index af5a36cf2..4b7034471 100644 --- a/lib/pure/collections/critbits.nim +++ b/lib/pure/collections/critbits.nim @@ -15,7 +15,7 @@ include "system/inclrtl" type - NodeObj[T] = object {.acyclic.} + NodeObj[T] {.acyclic.} = object byte: int ## byte index of the difference otherbits: char case isLeaf: bool @@ -138,7 +138,7 @@ proc missingOrExcl*[T](c: var CritBitTree[T], key: string): bool = ## Returns true iff `c` does not contain the given `key`. If the key ## does exist, c.excl(key) is performed. let oldCount = c.count - var n = exclImpl(c, key) + discard exclImpl(c, key) result = c.count == oldCount proc containsOrIncl*[T](c: var CritBitTree[T], key: string, val: T): bool = @@ -154,7 +154,7 @@ proc containsOrIncl*(c: var CritBitTree[void], key: string): bool = ## returns true iff `c` contains the given `key`. If the key does not exist ## it is inserted into `c`. let oldCount = c.count - var n = rawInsert(c, key) + discard rawInsert(c, key) result = c.count == oldCount proc inc*(c: var CritBitTree[int]; key: string, val: int = 1) = @@ -249,7 +249,7 @@ proc allprefixedAux[T](c: CritBitTree[T], key: string; longestMatch: bool): Node if q.byte < key.len: top = p if not longestMatch: for i in 0 ..< key.len: - if p.key[i] != key[i]: return + if i >= p.key.len or p.key[i] != key[i]: return result = top iterator itemsWithPrefix*[T](c: CritBitTree[T], prefix: string; @@ -380,3 +380,8 @@ when isMainModule: assert cf.len == 3 cf.excl("c") assert cf.len == 2 + + var cb: CritBitTree[string] + cb.incl("help", "help") + for k in cb.keysWithPrefix("helpp"): + doAssert false, "there is no prefix helpp" |