20 #ifndef RANDOM_POLICY_H_ 21 #define RANDOM_POLICY_H_ 25 #include "ns3/random-variable-stream.h" 26 #include "ns3/double.h" 28 #include <boost/intrusive/options.hpp> 29 #include <boost/intrusive/set.hpp> 38 struct random_policy_traits {
46 struct policy_hook_type :
public boost::intrusive::set_member_hook<> {
50 template<
class Container>
51 struct container_hook {
52 typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
56 template<
class Base,
class Container,
class Hook>
61 return static_cast<typename policy_container::value_traits::hook_type*
>(
62 policy_container::value_traits::to_node_ptr(*item))->randomOrder;
65 static const uint32_t&
66 get_order(
typename Container::const_iterator item)
68 return static_cast<const typename policy_container::value_traits::hook_type*
>(
69 policy_container::value_traits::to_node_ptr(*item))->randomOrder;
73 struct MemberHookLess {
75 operator()(
const Key& a,
const Key& b)
const 77 return get_order(&a) < get_order(&b);
81 typedef boost::intrusive::multiset<Container,
82 boost::intrusive::compare<MemberHookLess<Container>>,
83 Hook> policy_container;
86 class type :
public policy_container {
88 typedef policy policy_base;
89 typedef Container parent_trie;
93 , u_rand(CreateObject<UniformRandomVariable>())
96 u_rand->SetAttribute(
"Min", DoubleValue(0));
97 u_rand->SetAttribute(
"Max", DoubleValue(std::numeric_limits<uint32_t>::max()));
109 get_order(item) = u_rand->GetValue();
111 if (max_size_ != 0 && policy_container::size() >= max_size_) {
112 if (MemberHookLess<Container>()(*item, *policy_container::begin())) {
119 base_.erase(&(*policy_container::begin()));
123 policy_container::insert(*item);
136 policy_container::erase(policy_container::s_iterator_to(*item));
142 policy_container::clear();
146 set_max_size(
size_t max_size)
148 max_size_ = max_size;
159 : base_(*((Base*)0)){};
163 Ptr<UniformRandomVariable> u_rand;
175 #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.