Skip to content

Commit 12f929e

Browse files
committed
Fixed bug in CritBitTree.inc. Fixes #7990.
1 parent cc63351 commit 12f929e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/pure/collections/critbits.nim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ proc inc*(c: var CritBitTree[int]; key: string, val: int = 1) =
167167
## increments `c[key]` by `val`.
168168
let oldCount = c.count
169169
var n = rawInsert(c, key)
170-
if c.count == oldCount or oldCount == 0:
170+
if c.count >= oldCount or oldCount == 0:
171171
# not a new key:
172172
inc n.val, val
173173
@@ -366,3 +366,12 @@ when isMainModule:
366366

367367
c.inc("a", -5)
368368
assert c["a"] == 0
369+
370+
c.inc("b", 2)
371+
assert c["b"] == 2
372+
373+
c.inc("c", 3)
374+
assert c["c"] == 3
375+
376+
c.inc("a", 1)
377+
assert c["a"] == 1

0 commit comments

Comments
 (0)