tables.nim: Add named fields in smallest and largest (#14919)

The `smallest` and `largest` procs for `CountTable` returned a tuple
with named fields, but the same procs for `CountTableRef` returned an
anonymous tuple.

This commit makes those `CountTableRef` procs more consistent, and adds
a test.

Fixes: #14918
This commit is contained in:
ee7 2020-07-06 14:02:03 +02:00 • committed by GitHub
commit a754160d65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -2670,14 +2670,14 @@ proc inc*[A](t: CountTableRef[A], key: A, val = 1) =
doAssert a == newCountTable("aaabbbbbbbbbbb")
t[].inc(key, val)
proc smallest*[A](t: CountTableRef[A]): (A, int) =
proc smallest*[A](t: CountTableRef[A]): tuple[key: A, val: int] =
## Returns the ``(key, value)`` pair with the smallest ``val``. Efficiency: O(n)
##
## See also:
## * `largest proc<#largest,CountTableRef[A]>`_
t[].smallest
proc largest*[A](t: CountTableRef[A]): (A, int) =
proc largest*[A](t: CountTableRef[A]): tuple[key: A, val: int] =
## Returns the ``(key, value)`` pair with the largest ``val``. Efficiency: O(n)
##
## See also: