NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Groups
Pages
lru-policy.h
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 University of California, Los Angeles
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19
*/
20
21
#ifndef LRU_POLICY_H_
22
#define LRU_POLICY_H_
23
24
#include <boost/intrusive/options.hpp>
25
#include <boost/intrusive/list.hpp>
26
27
namespace
ns3 {
28
namespace
ndn {
29
namespace
ndnSIM {
30
34
struct
lru_policy_traits
35
{
37
static
std::string
GetName
() {
return
"Lru"
; }
38
39
struct
policy_hook_type
:
public
boost::intrusive::list_member_hook<> {};
40
41
template
<
class
Container>
42
struct
container_hook
43
{
44
typedef
boost::intrusive::member_hook< Container,
45
policy_hook_type
,
46
&Container::policy_hook_ > type;
47
};
48
49
template
<
class
Base,
50
class
Container,
51
class
Hook>
52
struct
policy
53
{
54
typedef
typename
boost::intrusive::list< Container, Hook > policy_container;
55
56
// could be just typedef
57
class
type
:
public
policy_container
58
{
59
public
:
60
typedef
Container parent_trie;
61
62
type
(Base &base)
63
: base_ (base)
64
, max_size_ (100)
65
{
66
}
67
68
inline
void
69
update (
typename
parent_trie::iterator item)
70
{
71
// do relocation
72
policy_container::splice (policy_container::end (),
73
*
this
,
74
policy_container::s_iterator_to (*item));
75
}
76
77
inline
bool
78
insert (
typename
parent_trie::iterator item)
79
{
80
if
(max_size_ != 0 && policy_container::size () >= max_size_)
81
{
82
base_.erase (&(*policy_container::begin ()));
83
}
84
85
policy_container::push_back (*item);
86
return
true
;
87
}
88
89
inline
void
90
lookup (
typename
parent_trie::iterator item)
91
{
92
// do relocation
93
policy_container::splice (policy_container::end (),
94
*
this
,
95
policy_container::s_iterator_to (*item));
96
}
97
98
inline
void
99
erase (
typename
parent_trie::iterator item)
100
{
101
policy_container::erase (policy_container::s_iterator_to (*item));
102
}
103
104
inline
void
105
clear ()
106
{
107
policy_container::clear ();
108
}
109
110
inline
void
111
set_max_size (
size_t
max_size)
112
{
113
max_size_ = max_size;
114
}
115
116
inline
size_t
117
get_max_size ()
const
118
{
119
return
max_size_;
120
}
121
122
private
:
123
type
() : base_(*((Base*)0)) { };
124
125
private
:
126
Base &base_;
127
size_t
max_size_;
128
};
129
};
130
};
131
132
}
// ndnSIM
133
}
// ndn
134
}
// ns3
135
136
#endif
ns3::ndn::ndnSIM::lru_policy_traits
Traits for Least Recently Used replacement policy.
Definition:
lru-policy.h:34
ns3::ndn::ndnSIM::lru_policy_traits::GetName
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging)
Definition:
lru-policy.h:37
ns3::ndn::ndnSIM::lru_policy_traits::policy
Definition:
lru-policy.h:52
ns3::ndn::ndnSIM::lru_policy_traits::policy::type
Definition:
lru-policy.h:57
ns3::ndn::ndnSIM::lru_policy_traits::policy_hook_type
Definition:
lru-policy.h:39
ns3::ndn::ndnSIM::lru_policy_traits::container_hook
Definition:
lru-policy.h:42
ndnSIM
utils
trie
lru-policy.h
Generated on Mon Jan 19 2015 11:27:04 for ndnSIM by
1.8.7