diff options
author | data-man <datamanrb@gmail.com> | 2018-06-07 19:29:40 +0300 |
---|---|---|
committer | data-man <datamanrb@gmail.com> | 2018-06-07 19:29:40 +0300 |
commit | 12f929e5822beeab2e1d60af9b4ef53d8339e11e (patch) | |
tree | 55aabbba3fe9e21053d586cb1438ff0f13691a0d | |
parent | cc63351a5a44ff5793195b59d961bc93257d879d (diff) | |
download | Nim-12f929e5822beeab2e1d60af9b4ef53d8339e11e.tar.gz |
Fixed bug in CritBitTree.inc. Fixes #7990.
-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 |