Fix tables.CountTable largest and smallest (#15115)
It needs to have len defined first because of the assert .len > 0. I just moved it up a bit to make them work.
This commit is contained in:
parent
20315637aa
commit
604f7461d7
1 changed files with 4 additions and 4 deletions
|
|
@ -2293,6 +2293,10 @@ proc inc*[A](t: var CountTable[A], key: A, val = 1) =
|
||||||
if val != 0:
|
if val != 0:
|
||||||
insertImpl()
|
insertImpl()
|
||||||
|
|
||||||
|
proc len*[A](t: CountTable[A]): int =
|
||||||
|
## Returns the number of keys in ``t``.
|
||||||
|
result = t.counter
|
||||||
|
|
||||||
proc smallest*[A](t: CountTable[A]): tuple[key: A, val: int] =
|
proc smallest*[A](t: CountTable[A]): tuple[key: A, val: int] =
|
||||||
## Returns the ``(key, value)`` pair with the smallest ``val``. Efficiency: O(n)
|
## Returns the ``(key, value)`` pair with the smallest ``val``. Efficiency: O(n)
|
||||||
##
|
##
|
||||||
|
|
@ -2345,10 +2349,6 @@ proc getOrDefault*[A](t: CountTable[A], key: A; default: int = 0): int =
|
||||||
## is in the table
|
## is in the table
|
||||||
ctget(t, key, default)
|
ctget(t, key, default)
|
||||||
|
|
||||||
proc len*[A](t: CountTable[A]): int =
|
|
||||||
## Returns the number of keys in ``t``.
|
|
||||||
result = t.counter
|
|
||||||
|
|
||||||
proc del*[A](t: var CountTable[A], key: A) {.since: (1, 1).} =
|
proc del*[A](t: var CountTable[A], key: A) {.since: (1, 1).} =
|
||||||
## Deletes ``key`` from table ``t``. Does nothing if the key does not exist.
|
## Deletes ``key`` from table ``t``. Does nothing if the key does not exist.
|
||||||
##
|
##
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue