General question: Suppose I have a `PriorityQueue...
# announcements
a
General question: Suppose I have a
PriorityQueue
, where each value
V
is sorted by according to a calculated
priority: K = calc(V, otherStuff)
. I want to be able to remove and add
V
to this priority queue based on equality. Should I 1. Have a
Map<V,K>
that the priority queue references in the sorting function and store the raw
V
in the priority queue 2. Use something like
NodeEqValue<K,V>
that has overridden equality for
V
3. Implemented some custom collection like
TreeMap
but that allows multiple equivalent keys 4. Add custom remove (probably the best)
n
I understand remove based on equality
What do you mean by add based on equality?
b
you can use kotlin extension fun that takes predicate for removing an element.
if you worry about complexity, 3️⃣ looks better, you can keep
TreeMap<K, Queue<V>>
but it depends on your usecase