java - Implement MRU Algorithm -


i want implement simple mru cache: i'll use queue:

get(object): 
  • check if queue contains object
    • yes: remove queue , insert @ beginning
    • no: forward request system, element , insert @ beginning

is approach okay? have seen many implementations use maps, don't understand why. why need key,value pair cache?!

because checking if collection contains element quicker map (theoretically o(1)), queue have iterate on existing elements , compare i.e. o(sizeofqueue)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -