Skip to content

Commit

Permalink
Fix tables.CountTable largest and smallest (nim-lang#15115)
Browse files Browse the repository at this point in the history
It needs to have len defined first because of the assert .len > 0.  I just moved it up a bit to make them work.
  • Loading branch information
treeform authored and mildred committed Jan 11, 2021
1 parent 36af6f8 commit ff474f8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,10 @@ proc inc*[A](t: var CountTable[A], key: A, val = 1) =
if val != 0:
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] =
## Returns the ``(key, value)`` pair with the smallest ``val``. Efficiency: O(n)
##
Expand Down Expand Up @@ -2345,10 +2349,6 @@ proc getOrDefault*[A](t: CountTable[A], key: A; default: int = 0): int =
## is in the table
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).} =
## Deletes ``key`` from table ``t``. Does nothing if the key does not exist.
##
Expand Down

0 comments on commit ff474f8

Please sign in to comment.