24 #include <boost/intrusive/options.hpp>
25 #include <boost/intrusive/set.hpp>
37 static std::string
GetName () {
return "Lfu"; }
39 struct policy_hook_type :
public boost::intrusive::set_member_hook<> {
double frequency; };
41 template<
class Container>
44 typedef boost::intrusive::member_hook< Container,
46 &Container::policy_hook_ > type;
54 static double& get_order (
typename Container::iterator item)
57 (policy_container::value_traits::to_node_ptr(*item))->frequency;
60 static const double& get_order (
typename Container::const_iterator item)
63 (policy_container::value_traits::to_node_ptr(*item))->frequency;
69 bool operator () (
const Key &a,
const Key &b)
const
71 return get_order (&a) < get_order (&b);
75 typedef boost::intrusive::multiset< Container,
76 boost::intrusive::compare< MemberHookLess< Container > >,
77 Hook > policy_container;
80 class type :
public policy_container
84 typedef Container parent_trie;
93 update (
typename parent_trie::iterator item)
95 policy_container::erase (policy_container::s_iterator_to (*item));
96 get_order (item) += 1;
97 policy_container::insert (*item);
101 insert (
typename parent_trie::iterator item)
103 get_order (item) = 0;
105 if (max_size_ != 0 && policy_container::size () >= max_size_)
108 base_.erase (&(*policy_container::begin ()));
111 policy_container::insert (*item);
116 lookup (
typename parent_trie::iterator item)
118 policy_container::erase (policy_container::s_iterator_to (*item));
119 get_order (item) += 1;
120 policy_container::insert (*item);
124 erase (
typename parent_trie::iterator item)
126 policy_container::erase (policy_container::s_iterator_to (*item));
132 policy_container::clear ();
136 set_max_size (
size_t max_size)
138 max_size_ = max_size;
142 get_max_size ()
const
148 type () : base_(*((Base*)0)) { };
161 #endif // LFU_POLICY_H
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging)
Traits for LFU replacement policy.