34#ifndef _OPENLCB_ALIASCACHE_HXX_
35#define _OPENLCB_ALIASCACHE_HXX_
An mostly std::set<> compatible class that stores the internal data in a sorted vector.
void reserve(size_t sz)
Ensures that a given size can be reached without memory allocation.
Comparator object comparing the aliases stored in the pool.
bool operator()(uint16_t alias, PoolIdx e) const
Less-than action.
AliasComparator(AliasCache *parent)
Constructor.
AliasCache * parent_
AliasCache whose pool we are indexing into.
bool operator()(PoolIdx e, uint16_t alias) const
Less-than action.
bool operator()(PoolIdx a, PoolIdx b) const
Less-than action.
Comparator object comparing the aliases stored in the pool.
IdComparator(AliasCache *parent)
Constructor.
bool operator()(PoolIdx a, PoolIdx b) const
Less-than action.
bool operator()(PoolIdx e, NodeID id) const
Less-than action.
AliasCache * parent_
AliasCache whose pool we are indexing into.
bool operator()(NodeID id, PoolIdx e) const
Less-than action.
Encapsulation of a pointer into the pool array.
PoolIdx()
Constructor. Sets the pointer to invalid.
Metadata * deref(AliasCache *parent)
Dereferences a pool index as if it was a pointer.
uint16_t idx_
Indexes the pool of the AliasCache.
Cache of alias to node id mappings.
PoolIdx freeList
list of unused mapping entries (index into pool)
bool next_entry(NodeID bound, NodeID *node, NodeAlias *alias)
Retrieves the next entry by increasing node ID.
AliasCache(NodeID seed, size_t _entries, void(*remove_callback)(NodeID id, NodeAlias alias, void *)=NULL, void *context=NULL)
Constructor.
Metadata * pool
pointer to allocated Metadata pool
NodeAlias generate()
Generate a 12-bit pseudo-random alias for a given alias cache.
void remove(NodeAlias alias)
Remove an alias from an alias cache.
AliasMap aliasMap
Map of alias to corresponding Metadata.
void touch(Metadata *metadata)
Update the time stamp for a given entry.
size_t entries
How many metadata entries have we allocated.
~AliasCache()
Default destructor.
SortedListSet< PoolIdx, AliasComparator > AliasMap
Short hand for the alias Map type.
NodeAlias lookup(NodeID id)
Lookup a node's alias based on its Node ID.
void * context
context pointer to pass in with remove_callback
static constexpr uint16_t NONE_ENTRY
Sentinel entry for empty lists.
void for_each(void(*callback)(void *, NodeID, NodeAlias), void *context)
Call the given callback function once for each alias tracked.
PoolIdx newest
newest, most recently touched entry (index into pool)
IdMap idMap
Map of Node ID to corresponding Metadata.
void clear()
Reinitializes the entire map.
SortedListSet< PoolIdx, IdComparator > IdMap
Short hand for the ID Map type.
void(* removeCallback)(NodeID id, NodeAlias alias, void *)
callback function to be used when we remove an entry from the cache
PoolIdx oldest
oldest untouched entry (index into pool)
bool retrieve(unsigned entry, NodeID *node, NodeAlias *alias)
Retrieves an entry by index.
size_t size()
Returns the total number of aliases that can be cached.
NodeID seed
Seed for the generation of the next alias.
int check_consistency()
Visible for testing.
void add(NodeID id, NodeAlias alias)
Add an alias to an alias cache.
#define DASSERT(x)
Debug assertion facility.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
uint64_t NodeID
48-bit NMRAnet Node ID type
uint16_t NodeAlias
Alias to a 48-bit NMRAnet Node ID type.