25 #include <boost/intrusive/options.hpp> 26 #include <boost/intrusive/set.hpp> 35 struct lfu_policy_traits {
43 struct policy_hook_type :
public boost::intrusive::set_member_hook<> {
47 template<
class Container>
48 struct container_hook {
49 typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
53 template<
class Base,
class Container,
class Hook>
58 return static_cast<policy_hook_type*>(policy_container::value_traits::to_node_ptr(*item))
63 get_order(
typename Container::const_iterator item)
65 return static_cast<const policy_hook_type*>(
66 policy_container::value_traits::to_node_ptr(*item))->frequency;
70 struct MemberHookLess {
72 operator()(
const Key& a,
const Key& b)
const 74 return get_order(&a) < get_order(&b);
78 typedef boost::intrusive::multiset<Container,
79 boost::intrusive::compare<MemberHookLess<Container>>,
80 Hook> policy_container;
83 class type :
public policy_container {
85 typedef policy policy_base;
86 typedef Container parent_trie;
97 policy_container::erase(policy_container::s_iterator_to(*item));
99 policy_container::insert(*item);
107 if (max_size_ != 0 && policy_container::size() >= max_size_) {
109 base_.erase(&(*policy_container::begin()));
112 policy_container::insert(*item);
119 policy_container::erase(policy_container::s_iterator_to(*item));
120 get_order(item) += 1;
121 policy_container::insert(*item);
127 policy_container::erase(policy_container::s_iterator_to(*item));
133 policy_container::clear();
137 set_max_size(
size_t max_size)
139 max_size_ = max_size;
150 : base_(*((Base*)0)){};
165 #endif // LFU_POLICY_H Copyright (c) 2011-2015 Regents of the University of California.
Table::const_iterator iterator
Copyright (c) 2011-2015 Regents of the University of California.