diff options
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/collections/critbits.nim | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/pure/collections/critbits.nim b/lib/pure/collections/critbits.nim index 71615002e..eaba257ae 100644 --- a/lib/pure/collections/critbits.nim +++ b/lib/pure/collections/critbits.nim @@ -167,7 +167,7 @@ proc inc*(c: var CritBitTree[int]; key: string, val: int = 1) = ## increments `c[key]` by `val`. let oldCount = c.count var n = rawInsert(c, key) - if c.count == oldCount or oldCount == 0: + if c.count >= oldCount or oldCount == 0: # not a new key: inc n.val, val @@ -366,3 +366,12 @@ when isMainModule: c.inc("a", -5) assert c["a"] == 0 + + c.inc("b", 2) + assert c["b"] == 2 + + c.inc("c", 3) + assert c["c"] == 3 + + c.inc("a", 1) + assert c["a"] == 1 |