15 #ifndef IMPALA_UTIL_LRU_CACHE_INLINE_H_
16 #define IMPALA_UTIL_LRU_CACHE_INLINE_H_
20 template <
typename Key,
typename Value>
22 for (
typename ListType::iterator b = lru_list_.begin(),
23 e = lru_list_.end(); b != e; ++b) {
24 deleter_(&(b->second));
28 template <
typename Key,
typename Value>
30 boost::lock_guard<SpinLock> g(
lock_);
31 if (lru_list_.size() >= capacity_) EvictValue();
32 const ValueType& kv_pair = std::make_pair(k, v);
33 const typename MapType::value_type& val =
34 std::make_pair(k, lru_list_.insert(lru_list_.end(), kv_pair));
36 typename MapType::iterator it = cache_.lower_bound(k);
37 if (it == cache_.end() || it->first != k) {
42 cache_.insert(it, val);
46 template <
typename Key,
typename Value>
48 boost::lock_guard<SpinLock> g(
lock_);
50 typename MapType::iterator it = cache_.lower_bound(k);
51 if (it == cache_.end() || it->first != k)
return false;
52 typename ListType::iterator lit = it->second;
59 template <
typename Key,
typename Value>
61 typename ListType::iterator to_evict = lru_list_.begin();
64 std::pair<typename MapType::iterator, typename MapType::iterator> range =
65 cache_.equal_range(to_evict->first);
67 while (range.first != range.second) {
68 if (range.first->second == to_evict) {
69 cache_.erase(range.first);
74 DCHECK(range.first != range.second);
75 deleter_(&(*to_evict).second);
76 lru_list_.erase(to_evict);
81 #endif // IMPALA_UTIL_LRU_CACHE_INLINE_H_
void Put(const Key &k, const Value &v)
bool Pop(const Key &k, Value *out)
boost::mutex lock_
protects all fields below
~FifoMultimap()
Walk the list of elements and call the deleter function for each element.
std::pair< Key, Value > ValueType