mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-20 07:51:32 +00:00
fixes #11344
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user