mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 03:02:31 +00:00
Add the val parameter for CritBitTree[T].incl (#7988)
* Add the val parameter for CritBitTree[T].incl * Updated changelog
This commit is contained in:
committed by
Varriount
parent
e273ef4f5e
commit
fbd91a474a
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user