fixes #11344
This commit is contained in:
parent
35593700fa
commit
4a9e6361ce
1 changed files with 9 additions and 4 deletions
|
|
@ -15,7 +15,7 @@
|
||||||
include "system/inclrtl"
|
include "system/inclrtl"
|
||||||
|
|
||||||
type
|
type
|
||||||
NodeObj[T] = object {.acyclic.}
|
NodeObj[T] {.acyclic.} = object
|
||||||
byte: int ## byte index of the difference
|
byte: int ## byte index of the difference
|
||||||
otherbits: char
|
otherbits: char
|
||||||
case isLeaf: bool
|
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
|
## Returns true iff `c` does not contain the given `key`. If the key
|
||||||
## does exist, c.excl(key) is performed.
|
## does exist, c.excl(key) is performed.
|
||||||
let oldCount = c.count
|
let oldCount = c.count
|
||||||
var n = exclImpl(c, key)
|
discard exclImpl(c, key)
|
||||||
result = c.count == oldCount
|
result = c.count == oldCount
|
||||||
|
|
||||||
proc containsOrIncl*[T](c: var CritBitTree[T], key: string, val: T): bool =
|
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
|
## returns true iff `c` contains the given `key`. If the key does not exist
|
||||||
## it is inserted into `c`.
|
## it is inserted into `c`.
|
||||||
let oldCount = c.count
|
let oldCount = c.count
|
||||||
var n = rawInsert(c, key)
|
discard rawInsert(c, key)
|
||||||
result = c.count == oldCount
|
result = c.count == oldCount
|
||||||
|
|
||||||
proc inc*(c: var CritBitTree[int]; key: string, val: int = 1) =
|
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 q.byte < key.len: top = p
|
||||||
if not longestMatch:
|
if not longestMatch:
|
||||||
for i in 0 ..< key.len:
|
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
|
result = top
|
||||||
|
|
||||||
iterator itemsWithPrefix*[T](c: CritBitTree[T], prefix: string;
|
iterator itemsWithPrefix*[T](c: CritBitTree[T], prefix: string;
|
||||||
|
|
@ -380,3 +380,8 @@ when isMainModule:
|
||||||
assert cf.len == 3
|
assert cf.len == 3
|
||||||
cf.excl("c")
|
cf.excl("c")
|
||||||
assert cf.len == 2
|
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"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue