CatapultServer  v0.5.0.1 (Elephant)
catapult::consumers::RecentHashCache Class Reference

A hash cache that holds recently seen hashes. More...

Collaboration diagram for catapult::consumers::RecentHashCache:

Public Member Functions

 RecentHashCache (const chain::TimeSupplier &timeSupplier, const HashCheckOptions &options)
 Creates a recent hash cache around timeSupplier and options. More...
 
size_t size () const
 Gets the size of the cache. More...
 
bool add (const Hash256 &hash)
 
bool contains (const Hash256 &hash) const
 Returns true if the cache contains hash, false otherwise. More...
 

Private Member Functions

bool checkAndUpdateExisting (const Hash256 &hash, const Timestamp &time)
 
void pruneCache (const Timestamp &time)
 
void tryAddToCache (const Hash256 &hash, const Timestamp &time)
 

Private Attributes

chain::TimeSupplier m_timeSupplier
 
HashCheckOptions m_options
 
Timestamp m_lastPruneTime
 
std::unordered_map< Hash256, Timestamp, utils::ArrayHasher< Hash256 > > m_cache
 

Detailed Description

A hash cache that holds recently seen hashes.

Constructor & Destructor Documentation

◆ RecentHashCache()

catapult::consumers::RecentHashCache::RecentHashCache ( const chain::TimeSupplier timeSupplier,
const HashCheckOptions options 
)

Creates a recent hash cache around timeSupplier and options.

Member Function Documentation

◆ add()

bool catapult::consumers::RecentHashCache::add ( const Hash256 hash)

Checks if hash is already in the cache and adds it to the cache if it is unknown.

Note
This also prunes the hash cache.
Here is the call graph for this function:

◆ checkAndUpdateExisting()

bool catapult::consumers::RecentHashCache::checkAndUpdateExisting ( const Hash256 hash,
const Timestamp time 
)
private
Here is the caller graph for this function:

◆ contains()

bool catapult::consumers::RecentHashCache::contains ( const Hash256 hash) const

Returns true if the cache contains hash, false otherwise.

◆ pruneCache()

void catapult::consumers::RecentHashCache::pruneCache ( const Timestamp time)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

size_t catapult::consumers::RecentHashCache::size ( ) const

Gets the size of the cache.

◆ tryAddToCache()

void catapult::consumers::RecentHashCache::tryAddToCache ( const Hash256 hash,
const Timestamp time 
)
private
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_cache

std::unordered_map<Hash256, Timestamp, utils::ArrayHasher<Hash256> > catapult::consumers::RecentHashCache::m_cache
private

◆ m_lastPruneTime

Timestamp catapult::consumers::RecentHashCache::m_lastPruneTime
private

◆ m_options

HashCheckOptions catapult::consumers::RecentHashCache::m_options
private

◆ m_timeSupplier

chain::TimeSupplier catapult::consumers::RecentHashCache::m_timeSupplier
private

The documentation for this class was generated from the following files: