summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/collections/critbits.nim13
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"