I use Emacs Lisp, but the cl package is loaded for some common lisp functions.
I have a hash table containing up to 50K entries, with integer keys mapped to triplets, something like this (but in the actual lisp):
{ 8 => '(9 300 12) 27 => '(5 125 9) 100 => '(10 242 14) }
The second value in the triplet is the estimate, which was calculated during the complex algorithm that built the hash table. I need to compile a regular lisp list with all the keys from the hash sorted by count (i.e., all keys sorted by frame values).
So, for the above, I need this list:
'(27 100 8)
I am currently doing this with two steps that feel less effective than it should be.
Is there a good way to do this?
My current solution uses maphash to collect keys and values ββinto two new lists, and then does sort usual way, referencing the list of ratings in the predicate. Looks like I could combine collecting and sorting together.
EDIT | I am also not tied to using a hash table, although I need a constant access time for whole keys that do not have linear diversity.
EDIT 2 | It looks like the binary tree sort implementation may work, where the labels in the tree are estimates and the values ββare keys ... so I do the sorting when I iterate over the hash.
... Continues reading wikipedia page on sorting algorithms
source share