Represents in-memory storage. More...
#include <in-memory-storage.hpp>
Classes | |
class | const_iterator |
Represents a self-defined const_iterator for the in-memory storage. More... | |
class | Error |
Represents an error might be thrown during reduce the current capacity of the in-memory storage through function setCapacity(size_t nMaxPackets). More... | |
Public Types | |
typedef boost::multi_index_container< InMemoryStorageEntry *, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< byFullName >, boost::multi_index::const_mem_fun< InMemoryStorageEntry, const Name &,&InMemoryStorageEntry::getFullName >, std::less< Name > > > > | Cache |
Public Member Functions | |
InMemoryStorage (size_t limit=std::numeric_limits< size_t >::max()) | |
virtual | ~InMemoryStorage () |
void | insert (const Data &data) |
Inserts a Data packet. More... | |
shared_ptr< const Data > | find (const Interest &interest) |
Finds the best match Data for an Interest. More... | |
shared_ptr< const Data > | find (const Name &name) |
Finds the best match Data for a Name with or without the implicit digest. More... | |
void | erase (const Name &prefix, const bool isPrefix=true) |
Deletes in-memory storage entry by prefix by default. More... | |
size_t | getLimit () const |
size_t | size () const |
InMemoryStorage::const_iterator | begin () const |
Returns begin iterator of the in-memory storage ordering by name with digest. More... | |
InMemoryStorage::const_iterator | end () const |
Returns end iterator of the in-memory storage ordering by name with digest. More... | |
virtual void | afterInsert (InMemoryStorageEntry *entry) |
Update the entry or other data structures after a entry is successfully inserted according to derived class implemented replacement policy. More... | |
virtual void | beforeErase (InMemoryStorageEntry *entry) |
Update the entry or other data structures before a entry is successfully erased according to derived class implemented replacement policy. More... | |
virtual bool | evictItem ()=0 |
Removes one Data packet from in-memory storage based on derived class implemented replacement policy. More... | |
size_t | getCapacity () const |
returns current capacity of in-memory storage (in packets) More... | |
bool | isFull () const |
returns true if the in-memory storage uses up the current capacity, false otherwise More... | |
void | eraseImpl (const Name &name) |
deletes in-memory storage entries by the Name with implicit digest. More... | |
void | printCache (std::ostream &os) const |
Prints contents of the in-memory storage. More... | |
InMemoryStorageEntry * | selectChild (const Interest &interest, Cache::index< byFullName >::type::iterator startingPoint) const |
Implements child selector (leftmost, rightmost, undeclared). More... | |
Public Attributes | |
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED | __pad0__: virtual void afterAccess(InMemoryStorageEntry* entry) |
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED | __pad1__: void setCapacity(size_t nMaxPackets) |
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE | __pad2__: Cache::iterator freeEntry(Cache::iterator it) |
Represents in-memory storage.
Definition at line 46 of file in-memory-storage.hpp.
typedef boost::multi_index_container< InMemoryStorageEntry*, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag<byFullName>, boost::multi_index::const_mem_fun<InMemoryStorageEntry, const Name&, &InMemoryStorageEntry::getFullName>, std::less<Name> > > > ndn::util::InMemoryStorage::Cache |
Definition at line 50 of file in-memory-storage.hpp.
|
explicit |
Definition at line 86 of file in-memory-storage.cpp.
Referenced by ndn::util::InMemoryStorage::Error::Error().
|
virtual |
Definition at line 102 of file in-memory-storage.cpp.
References evictItem(), and size().
Referenced by ndn::util::InMemoryStorage::Error::Error().
void ndn::util::InMemoryStorage::insert | ( | const Data & | data | ) |
Inserts a Data packet.
Definition at line 149 of file in-memory-storage.cpp.
References afterInsert(), evictItem(), find(), getCapacity(), ndn::Data::getFullName(), getLimit(), and isFull().
Referenced by ndn::util::InMemoryStorage::Error::Error().
Finds the best match Data for an Interest.
Definition at line 202 of file in-memory-storage.cpp.
References ndn::util::InMemoryStorageEntry::getData(), ndn::Interest::getName(), and selectChild().
Referenced by ndn::util::InMemoryStorageLfu::afterAccess(), ndn::util::InMemoryStorageFifo::beforeErase(), ndn::util::InMemoryStorageLru::beforeErase(), ndn::util::InMemoryStorageLfu::beforeErase(), erase(), eraseImpl(), ndn::util::InMemoryStorage::Error::Error(), and insert().
Finds the best match Data for a Name with or without the implicit digest.
If packets with the same name but different digests exist and the Name supplied is the one without implicit digest, a packet will be arbitrarily chosen to return.
Definition at line 183 of file in-memory-storage.cpp.
References ndn::Name::isPrefixOf().
void ndn::util::InMemoryStorage::erase | ( | const Name & | prefix, |
const bool | isPrefix = true |
||
) |
Deletes in-memory storage entry by prefix by default.
[in] | isPrefix | If it is clear, the function will only delete the entry completely matched with the prefix according to canonical ordering. For this case, user should substitute the prefix with full name. |
Definition at line 332 of file in-memory-storage.cpp.
References beforeErase(), find(), getCapacity(), ndn::Name::isPrefixOf(), and size().
Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), and ndn::util::InMemoryStorage::Error::Error().
|
inline |
Definition at line 174 of file in-memory-storage.hpp.
Referenced by insert().
|
inline |
Definition at line 182 of file in-memory-storage.hpp.
References begin(), end(), and NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED.
Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), erase(), isFull(), and ~InMemoryStorage().
InMemoryStorage::const_iterator ndn::util::InMemoryStorage::begin | ( | ) | const |
Returns begin iterator of the in-memory storage ordering by name with digest.
Definition at line 370 of file in-memory-storage.cpp.
Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), and size().
InMemoryStorage::const_iterator ndn::util::InMemoryStorage::end | ( | ) | const |
Returns end iterator of the in-memory storage ordering by name with digest.
Definition at line 378 of file in-memory-storage.cpp.
Referenced by selectChild(), and size().
|
virtual |
Update the entry or other data structures after a entry is successfully inserted according to derived class implemented replacement policy.
Reimplemented in ndn::util::InMemoryStorageLfu, ndn::util::InMemoryStorageLru, and ndn::util::InMemoryStorageFifo.
Definition at line 388 of file in-memory-storage.cpp.
Referenced by insert().
|
virtual |
Update the entry or other data structures before a entry is successfully erased according to derived class implemented replacement policy.
Reimplemented in ndn::util::InMemoryStorageLfu, ndn::util::InMemoryStorageLru, and ndn::util::InMemoryStorageFifo.
Definition at line 393 of file in-memory-storage.cpp.
Referenced by erase().
|
pure virtual |
Removes one Data packet from in-memory storage based on derived class implemented replacement policy.
Please do not use this function directly in any derived class to erase entry in the cache, use eraseHelper instead.
Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), insert(), ~InMemoryStorage(), and ndn::util::InMemoryStoragePersistent::~InMemoryStoragePersistent().
|
inline |
returns current capacity of in-memory storage (in packets)
Definition at line 244 of file in-memory-storage.hpp.
|
inline |
returns true if the in-memory storage uses up the current capacity, false otherwise
Definition at line 252 of file in-memory-storage.hpp.
References eraseImpl(), NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE, printCache(), and size().
Referenced by insert().
void ndn::util::InMemoryStorage::eraseImpl | ( | const Name & | name | ) |
deletes in-memory storage entries by the Name with implicit digest.
This is the function one should use to erase entry in the cache in derived class. It won't invoke beforeErase(shared_ptr<Entry>).
Definition at line 359 of file in-memory-storage.cpp.
References find().
Referenced by ndn::util::InMemoryStorageFifo::afterInsert(), ndn::util::InMemoryStorageLru::afterInsert(), ndn::util::InMemoryStorageLfu::afterInsert(), and isFull().
void ndn::util::InMemoryStorage::printCache | ( | std::ostream & | os | ) | const |
Prints contents of the in-memory storage.
Definition at line 403 of file in-memory-storage.cpp.
Referenced by isFull().
InMemoryStorageEntry * ndn::util::InMemoryStorage::selectChild | ( | const Interest & | interest, |
Cache::index< byFullName >::type::iterator | startingPoint | ||
) | const |
Implements child selector (leftmost, rightmost, undeclared).
Operates on the first layer of a skip list.
startingPoint must be less than Interest Name. startingPoint can be equal to Interest Name only when the item is in the begin() position.
Iterates toward greater Names, terminates when application cache entry falls out of Interest prefix. When childSelector = leftmost, returns first application cache entry that satisfies other selectors. When childSelector = rightmost, it goes till the end, and returns application cache entry that satisfies other selectors. Returned application cache entry is the leftmost child of the rightmost child.
Definition at line 238 of file in-memory-storage.cpp.
References ndn::Name::empty(), end(), ndn::Interest::getChildSelector(), ndn::Interest::getName(), ndn::Name::getPrefix(), ndn::Name::isPrefixOf(), ndn::Interest::matchesData(), and ndn::Name::size().
Referenced by find().
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED ndn::util::InMemoryStorage::__pad0__ |
Definition at line 208 of file in-memory-storage.hpp.
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED ndn::util::InMemoryStorage::__pad1__ |
Definition at line 238 of file in-memory-storage.hpp.
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE ndn::util::InMemoryStorage::__pad2__ |
Definition at line 276 of file in-memory-storage.hpp.