performance - Retrieve N most relevant objects in Java TreeMap -
According to
I have ordered Java map
, as follows:
ValueComparator bvc = new standardmapper (originalmap); Click the & lt; String, integer & gt; Sorted map = new trendmark & lt; String, integer & gt; (BBC); SortedMap.putAll (originalMap);
Now, I want to remove the
most relevant values from the map, what is a highly efficient way of working without a map in the top fashion? is?
PS, some similar questions (e.g.,) ask for the solution of Top-1 recovery problem.
No, if you use map
You have to do it again.
Did you consider using the priority question
? This is the implementation of Java of a heap. It is efficient operation to insert arbitrary elements and remove "minimum". You can think of doing this here. Instead of a map
, you can place them according to the relevance in a priority question
, along with the most relevant route. After this, to remove the most relevant of , you can pop the elements from priority question
.
If you need the property (like string
to integer
from mapping), then you can write a class that is internally Priority Questions
and everything in both a Hashem
. When you insert, then insert it into both; When you remove the minimum element, you pop it from the priority question
, and then tells you which element you want to remove from your hashMap
it still Log-ins inserts and min-removal.
Comments
Post a Comment