In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
[topic description]
LFU (Least Frequently Used) is a famous cache eviction algorithm.For a cache with capacity k, if the cache is full and need to evict a key in it, the key with the lease frequently used will be kicked out.Implement set and get method for LFU cache.
LFU is a famous caching algorithm. Implement set and get in LFU
[topic link]
Http://www.lintcode.com/en/problem/lfu-cache/
[topic Analysis]
This problem allows us to implement a LRU cache. LRU is an abbreviation for Least Recently Used, which means the least used recently. Then the cache mainly has two member functions, get and set, in which the get function obtains the value by typing key. If it is successfully obtained, the pair (key, value) rises to the most commonly used position in the cache (top), and returns-1 if key does not exist. The set function inserts a pair of new (key, value). If there is the key in the original buffer, you need to delete the original one and insert the new one at the top of the buffer. If it does not exist, insert it directly to the top. If the buffer exceeds the capacity after adding a new value, you need to delete the least commonly used value, that is, the value at the bottom. We need three private variables, cap, l and m, where cap is the capacity of the buffer, l is the list of buffer contents, m is the hash table, and the mapping between the iterator that stores the key value key and the buffer items is convenient for us to find the target item in O (1) time.
[reference answer]
Http://www.jiuzhang.com/solutions/lfu-cache/
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.