Add the val parameter for CritBitTree[T].incl (#7988)

* Add the val parameter for CritBitTree[T].incl

* Updated changelog
This commit is contained in:
Dmitry Atamanov
2018-06-08 19:01:40 +03:00
committed by Varriount
parent e273ef4f5e
commit fbd91a474a
2 changed files with 21 additions and 0 deletions

View File

@@ -85,6 +85,7 @@
- The `terminal` module now exports additional procs for generating ANSI color
codes as strings.
- Added the parameter ``val`` for the ``CritBitTree[int].inc`` proc.
- Added the parameter ``val`` for the ``CritBitTree[T].incl`` proc.
- An exception raised from ``test`` block of ``unittest`` now shows its type in
the error message
- The proc ``tgamma`` was renamed to ``gamma``. ``tgamma`` is deprecated.

View File

@@ -175,6 +175,11 @@ proc incl*(c: var CritBitTree[void], key: string) =
## includes `key` in `c`.
discard rawInsert(c, key)
proc incl*[T](c: var CritBitTree[T], key: string, val: T) =
## inserts `key` with value `val` into `c`.
var n = rawInsert(c, key)
n.val = val
proc `[]=`*[T](c: var CritBitTree[T], key: string, val: T) =
## puts a (key, value)-pair into `t`.
var n = rawInsert(c, key)
@@ -375,3 +380,18 @@ when isMainModule:
c.inc("a", 1)
assert c["a"] == 1
var cf = CritBitTree[float]()
cf.incl("a", 1.0)
assert cf["a"] == 1.0
cf.incl("b", 2.0)
assert cf["b"] == 2.0
cf.incl("c", 3.0)
assert cf["c"] == 3.0
assert cf.len == 3
cf.excl("c")
assert cf.len == 2