Guest User

Untitled

a guest
Jul 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. proc cmpCountTablePair[A](a, b: tuple[key: A, val: int]): int =
  2. ## compare proc for a data item of a CountTable
  3. if a.val > b.val: return -1
  4. if a.val < b.val: return 1
  5. return cmp(a.key, b.key)
  6.  
  7. proc sort*[A](t: var CountTable[A]) =
  8. ## sorts the count table so that the entry with the highest counter comes
  9. ## first. This is destructive! You must not modify `t` afterwards!
  10. ## You can use the iterators `pairs`, `keys`, and `values` to iterate over
  11. ## `t` in the sorted order.
  12. t.data.sort(cmp=cmpCountTablePair)
Add Comment
Please, Sign In to add comment