21 #ifndef RANDOM_POLICY_H_ 
   22 #define RANDOM_POLICY_H_ 
   24 #include "ns3/random-variable.h" 
   26 #include <boost/intrusive/options.hpp> 
   27 #include <boost/intrusive/set.hpp> 
   39   static std::string 
GetName () { 
return "Random"; }
 
   41   struct policy_hook_type : 
public boost::intrusive::set_member_hook<> { uint32_t randomOrder; };
 
   43   template<
class Container>
 
   46     typedef boost::intrusive::member_hook< Container,
 
   48                                            &Container::policy_hook_ > type;
 
   56     static uint32_t& get_order (
typename Container::iterator item)
 
   58       return static_cast<typename policy_container::value_traits::hook_type*
> 
   59         (policy_container::value_traits::to_node_ptr(*item))->randomOrder;
 
   62     static const uint32_t& get_order (
typename Container::const_iterator item)
 
   64       return static_cast<const typename policy_container::value_traits::hook_type*
> 
   65         (policy_container::value_traits::to_node_ptr(*item))->randomOrder;
 
   71       bool operator () (
const Key &a, 
const Key &b)
 const 
   73         return get_order (&a) < get_order (&b);
 
   77     typedef boost::intrusive::multiset< Container,
 
   78                                    boost::intrusive::compare< MemberHookLess< Container > >,
 
   79                                    Hook > policy_container;
 
   82     class type : 
public policy_container
 
   86       typedef Container parent_trie;
 
   90         , u_rand (0, std::numeric_limits<uint32_t>::max ())
 
   96       update (
typename parent_trie::iterator item)
 
  102       insert (
typename parent_trie::iterator item)
 
  104         get_order (item) = u_rand.GetValue ();
 
  106         if (max_size_ != 0 && policy_container::size () >= max_size_)
 
  117                 base_.erase (&(*policy_container::begin ()));
 
  121         policy_container::insert (*item);
 
  126       lookup (
typename parent_trie::iterator item)
 
  132       erase (
typename parent_trie::iterator item)
 
  134         policy_container::erase (policy_container::s_iterator_to (*item));
 
  140         policy_container::clear ();
 
  144       set_max_size (
size_t max_size)
 
  146         max_size_ = max_size;
 
  150       get_max_size ()
 const 
  156       type () : base_(*((Base*)0)) { };
 
  160       ns3::UniformVariable u_rand;
 
  170 #endif // RANDOM_POLICY_H 
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging) 
 
Traits for random replacement policy.