Use a map to sort for significant performance improvements.

In my testing, a large table that previously took 50 seconds to sort
now takes ~110ms to sort.