Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc cmpCountTablePair[A](a, b: tuple[key: A, val: int]): int =
- ## compare proc for a data item of a CountTable
- if a.val > b.val: return -1
- if a.val < b.val: return 1
- return cmp(a.key, b.key)
- proc sort*[A](t: var CountTable[A]) =
- ## sorts the count table so that the entry with the highest counter comes
- ## first. This is destructive! You must not modify `t` afterwards!
- ## You can use the iterators `pairs`, `keys`, and `values` to iterate over
- ## `t` in the sorted order.
- t.data.sort(cmp=cmpCountTablePair)
Add Comment
Please, Sign In to add comment