diff options
author | Dmitry Atamanov <data-man@users.noreply.github.com> | 2018-06-08 19:01:40 +0300 |
---|---|---|
committer | Varriount <Varriount@users.noreply.github.com> | 2018-06-08 12:01:40 -0400 |
commit | fbd91a474a86a5a52fe495df00e9a0e1bfa000df (patch) | |
tree | d5e75519c47437d3c7f9da82dcbe4e852c70ca01 | |
parent | e273ef4f5e9ecbb015781fbbf62bbd72d69f47aa (diff) | |
download | Nim-fbd91a474a86a5a52fe495df00e9a0e1bfa000df.tar.gz |
Add the val parameter for CritBitTree[T].incl (#7988)
* Add the val parameter for CritBitTree[T].incl * Updated changelog
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | lib/pure/collections/critbits.nim | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md index 6fd12e62f..aae275c1c 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/lib/pure/collections/critbits.nim b/lib/pure/collections/critbits.nim index eaba257ae..2ab65f002 100644 --- a/lib/pure/collections/critbits.nim +++ b/lib/pure/collections/critbits.nim @@ -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 |