`CountTable` is just a histogram and the sorting is by the bin counts not by the keys. Keys are visited in "hash order". `hashes` does use an identity hash for integers which could create some confusion from a simple test program if the modulo the table size post hash transform doesn't change the order (though it surely can).
Of course, the larger idea embedded in this suggestion is quite legitimate - you could use a `HashSet[int]` (from `sets`) to manage the set until you are ready to create a `seq[int]` via `HashSet.toSeq` and then sort that seq at once. This is probably the approach that most would use and is probably faster for most access patterns. The heap/tree approach would likely win if you had dynamism -- insert a bunch, sweep in key order, insert some more, sweep in key order again, etc. This complex dynamic pattern wasn't really specified in your question, though.
