Fix counttable smallest loop start (#6917)

* Fix counttable smallest

* Fix counttable smallest loop start
This commit is contained in:
GULPF
2017-12-15 13:59:32 +01:00
committed by Andreas Rumpf
parent be87fe9176
commit cf9bee1702

View File

@@ -994,7 +994,7 @@ proc smallest*[A](t: CountTable[A]): tuple[key: A, val: int] =
## returns the (key,val)-pair with the smallest `val`. Efficiency: O(n)
assert t.len > 0
var minIdx = -1
for h in 1..high(t.data):
for h in 0..high(t.data):
if t.data[h].val > 0 and (minIdx == -1 or t.data[minIdx].val > t.data[h].val):
minIdx = h
result.key = t.data[minIdx].key
@@ -1332,5 +1332,5 @@ when isMainModule:
block: # CountTable.smallest
var t = initCountTable[int]()
for v in items([4, 4, 5, 5, 5]): t.inc(v)
doAssert t.smallest == (4, 2)
for v in items([0, 0, 5, 5, 5]): t.inc(v)
doAssert t.smallest == (0, 2)