Add the val parameter for CritBitTree[T].incl (#7988)
* Add the val parameter for CritBitTree[T].incl * Updated changelog
This commit is contained in:
parent
e273ef4f5e
commit
fbd91a474a
2 changed files with 21 additions and 0 deletions
|
|
@ -85,6 +85,7 @@
|
||||||
- The `terminal` module now exports additional procs for generating ANSI color
|
- The `terminal` module now exports additional procs for generating ANSI color
|
||||||
codes as strings.
|
codes as strings.
|
||||||
- Added the parameter ``val`` for the ``CritBitTree[int].inc`` proc.
|
- 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
|
- An exception raised from ``test`` block of ``unittest`` now shows its type in
|
||||||
the error message
|
the error message
|
||||||
- The proc ``tgamma`` was renamed to ``gamma``. ``tgamma`` is deprecated.
|
- The proc ``tgamma`` was renamed to ``gamma``. ``tgamma`` is deprecated.
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,11 @@ proc incl*(c: var CritBitTree[void], key: string) =
|
||||||
## includes `key` in `c`.
|
## includes `key` in `c`.
|
||||||
discard rawInsert(c, key)
|
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) =
|
proc `[]=`*[T](c: var CritBitTree[T], key: string, val: T) =
|
||||||
## puts a (key, value)-pair into `t`.
|
## puts a (key, value)-pair into `t`.
|
||||||
var n = rawInsert(c, key)
|
var n = rawInsert(c, key)
|
||||||
|
|
@ -375,3 +380,18 @@ when isMainModule:
|
||||||
|
|
||||||
c.inc("a", 1)
|
c.inc("a", 1)
|
||||||
assert c["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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue