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  virtual
48 
54  virtual bool
56 
60  virtual void
62 
65  virtual void
67 
71  virtual void
73 
74 private:
75  //binds frequency and entry together
76  struct CleanupEntry
77  {
78  InMemoryStorageEntry* entry;
79  uint64_t frequency;//could potentially be overflowed
80  };
81 
84  static inline void
85  incrementFrequency(CleanupEntry& cleanupEntry)
86  {
87  ++cleanupEntry.frequency;
88  }
89 
90 private:
91  //multi_index_container to implement LFU
92  class byFrequency;
93  class byEntity;
94 
95  typedef boost::multi_index_container<
96  CleanupEntry,
97  boost::multi_index::indexed_by<
98 
99  // by Entry itself
100  boost::multi_index::hashed_unique<
101  boost::multi_index::tag<byEntity>,
102  boost::multi_index::member<CleanupEntry, InMemoryStorageEntry*, &CleanupEntry::entry>
103  >,
104 
105  // by frequency (LFU)
106  boost::multi_index::ordered_non_unique<
107  boost::multi_index::tag<byFrequency>,
108  boost::multi_index::member<CleanupEntry, uint64_t, &CleanupEntry::frequency>,
109  std::less<uint64_t>
110  >
111 
112  >
113  > CleanupIndex;
114 
115  CleanupIndex m_cleanupIndex;
116 };
117 
118 } // namespace util
119 } // namespace ndn
120 
121 #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