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
Post a Comment