Is this algorithm implementation LRU or MRU?

狂风中的少年 提交于 2019-12-05 18:37:57

It looks to me like an MRU implementation. Notice how searches start from the beginning of the linked list and go back, and whenever a node is accessed it's moved to the front of the list. In Add(), the node is added using AddFirst(), and in TryGetValue(), it removes the node and adds it to the front of the list.

Based on what is documented here: http://en.wikipedia.org/wiki/Cache_algorithms#Most_Recently_Used

It's LRU. Think about the items being a "ordered" list.

The most recently used item is at the "front". When a new item is added they call items.AddFirst(newNode); which adds it to the front of the list. When an item is "touched", they move it to the front of the list using these calls:

items.Remove(node);
items.AddFirst(node);

When the list is full, it pushes the "last" / "oldest" item from the list using items.RemoveLast();

The cache is removing the "least recently used" items first when it hits capacity.

Microsoft's "MRU" lists correctly use an LRU cache replacement algorithm.

Note that Microsoft in this case uses different terminology for MRU lists than the cache community.

The cache community uses MRU / LRU to talk about replacement (or eviction) strategies. When your cache is full, and you need to put a new item in the list, which item should be removed from the list?

Microsoft provides tools for getting the most recently used items, like for a drop down or a recent documents list.

This means that to correctly implement an MRU list, you need to implement an LRU Cache eviction strategy.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!