NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
in-memory-storage-lfu.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
23 
24 namespace ndn {
25 namespace util {
26 
28  : InMemoryStorage(limit)
29 {
30 }
31 
32 InMemoryStorageLfu::InMemoryStorageLfu(boost::asio::io_service& ioService, size_t limit)
33  : InMemoryStorage(ioService, limit)
34 {
35 }
36 
37 void
39 {
40  BOOST_ASSERT(m_cleanupIndex.size() <= size());
41  CleanupEntry cleanupEntry;
42  cleanupEntry.entry = entry;
43  cleanupEntry.frequency = 0;
44  m_cleanupIndex.insert(cleanupEntry);
45 }
46 
47 bool
49 {
50  if (!m_cleanupIndex.get<byFrequency>().empty()) {
51  CleanupIndex::index<byFrequency>::type::iterator it = m_cleanupIndex.get<byFrequency>().begin();
52  eraseImpl(((*it).entry)->getFullName());
53  m_cleanupIndex.get<byFrequency>().erase(it);
54  return true;
55  }
56 
57  return false;
58 }
59 
60 void
62 {
63  CleanupIndex::index<byEntity>::type::iterator it = m_cleanupIndex.get<byEntity>().find(entry);
64  if (it != m_cleanupIndex.get<byEntity>().end())
65  m_cleanupIndex.get<byEntity>().erase(it);
66 }
67 
68 void
70 {
71  CleanupIndex::index<byEntity>::type::iterator it = m_cleanupIndex.get<byEntity>().find(entry);
72  m_cleanupIndex.get<byEntity>().modify(it, &incrementFrequency);
73 }
74 
75 } // namespace util
76 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
virtual void afterAccess(InMemoryStorageEntry *entry) override
Update the entry when the entry is returned by the find() function, increment the frequency according...
shared_ptr< const Data > find(const Interest &interest)
Finds the best match Data for an Interest.
virtual void beforeErase(InMemoryStorageEntry *entry) override
Update the entry or other data structures before a entry is successfully erased, erase it from the cl...
virtual bool evictItem()=0
Removes one Data packet from in-memory storage based on derived class implemented replacement policy...
void eraseImpl(const Name &name)
deletes in-memory storage entries by the Name with implicit digest.
Table::const_iterator iterator
Definition: cs-internal.hpp:41
InMemoryStorage::const_iterator begin() const
Returns begin iterator of the in-memory storage ordering by name with digest.
Represents in-memory storage.
Represents an in-memory storage entry.
virtual void afterInsert(InMemoryStorageEntry *entry) override
Update the entry after a entry is successfully inserted, add it to the cleanupIndex.
void erase(const Name &prefix, const bool isPrefix=true)
Deletes in-memory storage entry by prefix by default.