A
Andreas Leitgeb
I'm in search of a data structure for the followig usecase:
Some algorithm spits out *lots* of pairs (k,v) of type (int,long).
I only want either those ten(*) pairs with the lowest keys, or all
pairs with the lowest ten(*) keys. (whichever is easier to achieve)
The keys (k) are not necessarily unique, in fact I usually get a
couple of different values (v) for each k, and I'm interested only
in the v's, that came with those ten(*) smallest k's. The actual
k's do not matter afterwards.
There are much too many to save them all and filter afterwards.
PriorityQueue and TreeMap do not seem to make it easy to
efficiently prune them beyond the first ten(*) entries
after each add().
Since it's called in a long loop, efficiency is an issue, but
the algorithm itself is also non-trivial, so I can afford some
extra cpu-cycles.
(*): I'd prefer if the "ten" does not need to be hardwired.
Some algorithm spits out *lots* of pairs (k,v) of type (int,long).
I only want either those ten(*) pairs with the lowest keys, or all
pairs with the lowest ten(*) keys. (whichever is easier to achieve)
The keys (k) are not necessarily unique, in fact I usually get a
couple of different values (v) for each k, and I'm interested only
in the v's, that came with those ten(*) smallest k's. The actual
k's do not matter afterwards.
There are much too many to save them all and filter afterwards.
PriorityQueue and TreeMap do not seem to make it easy to
efficiently prune them beyond the first ten(*) entries
after each add().
Since it's called in a long loop, efficiency is an issue, but
the algorithm itself is also non-trivial, so I can afford some
extra cpu-cycles.
(*): I'd prefer if the "ten" does not need to be hardwired.