NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
in-memory-storage-lfu.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_IN_MEMORY_STORAGE_LFU_HPP
23 #define NDN_UTIL_IN_MEMORY_STORAGE_LFU_HPP
24 
25 #include "in-memory-storage.hpp"
26 
27 #include <boost/multi_index/member.hpp>
28 #include <boost/multi_index_container.hpp>
29 #include <boost/multi_index/ordered_index.hpp>
30 #include <boost/multi_index/hashed_index.hpp>
31 #include <boost/multi_index/identity.hpp>
32 
33 namespace ndn {
34 namespace util {
35 
41 {
42 public:
43  explicit
44  InMemoryStorageLfu(size_t limit = 10);
45 
46  explicit
47  InMemoryStorageLfu(boost::asio::io_service& ioService, size_t limit = 10);
48 
49  virtual
51 
57  virtual bool
59 
63  virtual void
65 
68  virtual void
70 
74  virtual void
76 
77 private:
78  //binds frequency and entry together
79  struct CleanupEntry
80  {
81  InMemoryStorageEntry* entry;
82  uint64_t frequency;//could potentially be overflowed
83  };
84 
87  static inline void
88  incrementFrequency(CleanupEntry& cleanupEntry)
89  {
90  ++cleanupEntry.frequency;
91  }
92 
93 private:
94  //multi_index_container to implement LFU
95  class byFrequency;
96  class byEntity;
97 
98  typedef boost::multi_index_container<
99  CleanupEntry,
100  boost::multi_index::indexed_by<
101 
102  // by Entry itself
103  boost::multi_index::hashed_unique<
104  boost::multi_index::tag<byEntity>,
105  boost::multi_index::member<CleanupEntry, InMemoryStorageEntry*, &CleanupEntry::entry>
106  >,
107 
108  // by frequency (LFU)
109  boost::multi_index::ordered_non_unique<
110  boost::multi_index::tag<byFrequency>,
111  boost::multi_index::member<CleanupEntry, uint64_t, &CleanupEntry::frequency>,
112  std::less<uint64_t>
113  >
114 
115  >
116  > CleanupIndex;
117 
118  CleanupIndex m_cleanupIndex;
119 };
120 
121 } // namespace util
122 } // namespace ndn
123 
124 #endif // NDN_UTIL_IN_MEMORY_STORAGE_LFU_HPP
Copyright (c) 2011-2015 Regents of the University of California.
Provides an in-memory storage with Least Frequently Used (LFU) replacement policy.
virtual bool evictItem()=0
Removes one Data packet from in-memory storage based on derived class implemented replacement policy...
virtual void afterAccess(InMemoryStorageEntry *entry)
Update the entry when the entry is returned by the find() function, increment the frequency according...
Represents in-memory storage.
virtual void beforeErase(InMemoryStorageEntry *entry)
Update the entry or other data structures before a entry is successfully erased, erase it from the cl...
virtual void afterInsert(InMemoryStorageEntry *entry)
Update the entry after a entry is successfully inserted, add it to the cleanupIndex.
Represents an in-memory storage entry.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:42