NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
lru-policy.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20
#ifndef LRU_POLICY_H_
21
#define LRU_POLICY_H_
22
24
25
#include <boost/intrusive/options.hpp>
26
#include <boost/intrusive/list.hpp>
27
28
namespace
ns3
{
29
namespace
ndn
{
30
namespace
ndnSIM
{
31
35
struct
lru_policy_traits {
37
static
std::string
38
GetName()
39
{
40
return
"Lru"
;
41
}
42
43
struct
policy_hook_type :
public
boost::intrusive::list_member_hook<> {
44
};
45
46
template
<
class
Container>
47
struct
container_hook {
48
typedef
boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
49
type;
50
};
51
52
template
<
class
Base,
class
Container,
class
Hook>
53
struct
policy {
54
typedef
typename
boost::intrusive::list<Container, Hook> policy_container;
55
56
// could be just typedef
57
class
type :
public
policy_container {
58
public
:
59
typedef
Container parent_trie;
60
61
type(Base& base)
62
: base_(base)
63
, max_size_(100)
64
{
65
}
66
67
inline
void
68
update(
typename
parent_trie::iterator
item)
69
{
70
// do relocation
71
policy_container::splice(policy_container::end(), *
this
,
72
policy_container::s_iterator_to(*item));
73
}
74
75
inline
bool
76
insert(
typename
parent_trie::iterator
item)
77
{
78
if
(max_size_ != 0 && policy_container::size() >= max_size_) {
79
base_.erase(&(*policy_container::begin()));
80
}
81
82
policy_container::push_back(*item);
83
return
true
;
84
}
85
86
inline
void
87
lookup(
typename
parent_trie::iterator
item)
88
{
89
// do relocation
90
policy_container::splice(policy_container::end(), *
this
,
91
policy_container::s_iterator_to(*item));
92
}
93
94
inline
void
95
erase(
typename
parent_trie::iterator
item)
96
{
97
policy_container::erase(policy_container::s_iterator_to(*item));
98
}
99
100
inline
void
101
clear()
102
{
103
policy_container::clear();
104
}
105
106
inline
void
107
set_max_size(
size_t
max_size)
108
{
109
max_size_ = max_size;
110
}
111
112
inline
size_t
113
get_max_size()
const
114
{
115
return
max_size_;
116
}
117
118
private
:
119
type()
120
: base_(*((Base*)0)){};
121
122
private
:
123
Base& base_;
124
size_t
max_size_;
125
};
126
};
127
};
128
129
}
// ndnSIM
130
}
// ndn
131
}
// ns3
132
134
135
#endif
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
nfd::cs::iterator
Table::const_iterator iterator
Definition:
cs-internal.hpp:41
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
content-store-impl.cpp:38
ndnSIM
ndnSIM
utils
trie
lru-policy.hpp
Generated on Sun Feb 25 2018 13:27:06 for ndnSIM by
1.8.14