* fix #12200, cannot 'inc' CountTable by a negative value * use Positive
This commit is contained in:
parent
ea8a049af3
commit
618316beb9
1 changed files with 5 additions and 2 deletions
|
|
@ -2181,7 +2181,7 @@ template ctget(t, key, default: untyped): untyped =
|
||||||
var index = rawGet(t, key)
|
var index = rawGet(t, key)
|
||||||
result = if index >= 0: t.data[index].val else: default
|
result = if index >= 0: t.data[index].val else: default
|
||||||
|
|
||||||
proc inc*[A](t: var CountTable[A], key: A, val = 1)
|
proc inc*[A](t: var CountTable[A], key: A, val: Positive = 1)
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -2246,8 +2246,11 @@ proc `[]=`*[A](t: var CountTable[A], key: A, val: int) =
|
||||||
else:
|
else:
|
||||||
insertImpl()
|
insertImpl()
|
||||||
|
|
||||||
proc inc*[A](t: var CountTable[A], key: A, val = 1) =
|
proc inc*[A](t: var CountTable[A], key: A, val: Positive = 1) =
|
||||||
## Increments ``t[key]`` by ``val`` (default: 1).
|
## Increments ``t[key]`` by ``val`` (default: 1).
|
||||||
|
##
|
||||||
|
## ``val`` must be a positive number. If you need to decrement a value,
|
||||||
|
## use a regular ``Table`` instead.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var a = toCountTable("aab")
|
var a = toCountTable("aab")
|
||||||
a.inc('a')
|
a.inc('a')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue