0

Here's my problem i have two data structure one : countMark = new HashMap<Pair<String, String>, Integer>(); and the other which is the inverse orderMark = new TreeMap<Integer, List<Pair<String, String>>>();. I use the second one the quickly find the maximum value and the select a pair according to some rules.

But in my code i need to use orderMark.containsKey(counter) and that's not very efficient. As i increment the counter i also need to delete the specific pair. In consequence i have to do this orderMark.get(count - 1).remove(key);.

My question is i find that i could use MultiSet and MultiMap from Guava library but i didn't find the complexity about this data structure for add, contains, remove and get. And i would need a sorted map in order to select the pair which has the maximum value.

I hope that was sufficiently clear and thank you in advance for your answers.

jerem0808
  • 95
  • 1
  • 12
  • I just found this link : [link](http://stackoverflow.com/questions/4345633/simplest-way-to-iterate-through-a-multiset-in-the-order-of-element-frequency). I think i maybe could use only one multi set and use the `Multisets.copyHighestCountFirst()` in order to get the highest value but is it efficient or i should keep two seperate datastructure? – jerem0808 Oct 13 '14 at 07:58
  • 2
    How often do you need to pull out the maximum value? Also, you should _not_ be using `Pair`; you should write your own class that actually gives meaning to the fields. (AutoValue, also from the Guava folks, might help with that.) – Louis Wasserman Oct 13 '14 at 18:04
  • Thank you for your answer.The class Pair is a class that i wrote myself. I need to take the highest value quite a lot of time. It depends but it's planned to take few thousand times. – jerem0808 Oct 14 '14 at 18:30
  • 1
    Then you should probably just keep track of the "current max" and update that every time you update the multiset; trying to track the reverse mapping is not likely to pay for itself. – Louis Wasserman Oct 14 '14 at 19:13
  • Ok thank you i'll check that – jerem0808 Oct 14 '14 at 20:14

0 Answers0