What's the fastest way how to iterate over linked hash map, I need 100 last keys and first 20 keys. The size of this map will be in most cases over 500-1500, thanks
LinkedHashMap<Integer, Float> doc_1 = service5.getMatchingValue(query);
What's the fastest way how to iterate over linked hash map, I need 100 last keys and first 20 keys. The size of this map will be in most cases over 500-1500, thanks
LinkedHashMap<Integer, Float> doc_1 = service5.getMatchingValue(query);
If you iterate over a HashMap you still would have O(n) runtime, as you would iterating over any other datastructure...
Iterating over a HashMap is just as time consuming as iterating over any DS.
If you only need specific entries of a hashmap, you might want to keep information on the required keys and only loop over those keys. Access to an element in a HashMap using its key is O(1) (or atleast amorized), accessing M entries (by their keys) using direct access results thus in O(M) runtime with O(M) << O(N).
You could perhaps keep the last 100 keys in a cache and just loop over (a copy) of the cache to have the best possible access (in terms of performance) in combination with your HashMap.