20 #ifndef RANDOM_POLICY_H_ 21 #define RANDOM_POLICY_H_ 25 #include "ns3/random-variable-stream.h" 27 #include <boost/intrusive/options.hpp> 28 #include <boost/intrusive/set.hpp> 37 struct random_policy_traits {
45 struct policy_hook_type :
public boost::intrusive::set_member_hook<> {
49 template<
class Container>
50 struct container_hook {
51 typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
55 template<
class Base,
class Container,
class Hook>
60 return static_cast<typename policy_container::value_traits::hook_type*
>(
61 policy_container::value_traits::to_node_ptr(*item))->randomOrder;
64 static const uint32_t&
65 get_order(
typename Container::const_iterator item)
67 return static_cast<const typename policy_container::value_traits::hook_type*
>(
68 policy_container::value_traits::to_node_ptr(*item))->randomOrder;
72 struct MemberHookLess {
74 operator()(
const Key& a,
const Key& b)
const 76 return get_order(&a) < get_order(&b);
80 typedef boost::intrusive::multiset<Container,
81 boost::intrusive::compare<MemberHookLess<Container>>,
82 Hook> policy_container;
85 class type :
public policy_container {
87 typedef policy policy_base;
88 typedef Container parent_trie;
92 , u_rand(CreateObject<UniformRandomVariable>())
95 u_rand->SetAttribute(
"Min", UintegerValue(0));
96 u_rand->SetAttribute(
"Max", UintegerValue(std::numeric_limits<uint32_t>::max()));
108 get_order(item) = u_rand->GetValue();
110 if (max_size_ != 0 && policy_container::size() >= max_size_) {
111 if (MemberHookLess<Container>()(*item, *policy_container::begin())) {
118 base_.erase(&(*policy_container::begin()));
122 policy_container::insert(*item);
135 policy_container::erase(policy_container::s_iterator_to(*item));
141 policy_container::clear();
145 set_max_size(
size_t max_size)
147 max_size_ = max_size;
158 : base_(*((Base*)0)){};
162 Ptr<UniformRandomVariable> u_rand;
174 #endif // RANDOM_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.