Re: "PriorityMap"
- From: Andreas Leitgeb <avl@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 31 Mar 2008 09:04:05 GMT
Patricia Shanahan <pats@xxxxxxx> wrote:
Andreas Leitgeb wrote:
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.
I'd use a PriorityQueue but with either a Comparable element type or a
Comparator that uses descending order of the key values. That way, the
head item is the one with the largest key, and the one that should be
removed when an insertion increases the queue size beyond 10.
Cool idea! I didn't think of that, but now it seems obvious :-)
Thanks a lot!
.
- References:
- "PriorityMap"
- From: Andreas Leitgeb
- Re: "PriorityMap"
- From: Patricia Shanahan
- "PriorityMap"
- Prev by Date: Re: JUnit on os x, CLASSPATH incorrect?
- Next by Date: Re: Where do you keep contants in Interfaces or in classes?
- Previous by thread: Re: "PriorityMap"
- Next by thread: Re: "PriorityMap"
- Index(es):
Relevant Pages
|
|