gem5 v24.0.0.0
Loading...
Searching...
No Matches
gem5::Trie< Key, Value > Class Template Reference

A trie is a tree-based data structure used for data retrieval. More...

#include <trie.hh>

Classes

struct  Node
 

Public Types

typedef NodeHandle
 

Public Member Functions

 Trie ()
 
Handle insert (Key key, unsigned width, Value *val)
 Method which inserts a key/value pair into the trie.
 
Valuelookup (Key key)
 Method which looks up the Value corresponding to a particular key.
 
Valueremove (Handle handle)
 Method to delete a value from the trie.
 
Valueremove (Key key)
 Method to lookup a value from the trie and then delete it.
 
void clear ()
 A method which removes all key/value pairs from the trie.
 
void dump (const char *title, std::ostream &os=std::cout)
 A debugging method which prints the contents of this trie.
 

Static Public Attributes

static const unsigned MaxBits = sizeof(Key) * 8
 

Protected Attributes

Node head
 

Private Member Functions

bool goesAfter (Node **parent, Node *kid, Key key, Key new_mask)
 A utility method which checks whether the key being looked up lies beyond the Node being examined.
 
Key extendMask (Key orig)
 A utility method which extends a mask value one more bit towards the lsb.
 
Handle lookupHandle (Key key)
 Method which looks up the Handle corresponding to a particular key.
 

Detailed Description

template<class Key, class Value>
class gem5::Trie< Key, Value >

A trie is a tree-based data structure used for data retrieval.

It uses bits masked from the msb of the key to to determine a value's location, so its lookups have their worst case time dictated by the key's size.

Template Parameters
KeyType of the key of the tree nodes. Must be an integral type.
ValueType of the values associated to the keys.

Definition at line 54 of file trie.hh.

Member Function Documentation

◆ dump()

template<class Key , class Value >
void gem5::Trie< Key, Value >::dump ( const char * title,
std::ostream & os = std::cout )
inline

A debugging method which prints the contents of this trie.

Parameters
titleAn identifying title to put in the dump header.

Definition at line 378 of file trie.hh.

References gem5::ccprintf(), gem5::Trie< Key, Value >::Node::dump(), gem5::Trie< Key, Value >::head, and gem5::X86ISA::os.

Referenced by TrieTestData::dumpTrie().

◆ extendMask()

template<class Key , class Value >
Key gem5::Trie< Key, Value >::extendMask ( Key orig)
inlineprivate

A utility method which extends a mask value one more bit towards the lsb.

This is almost just a signed right shift, except that the shifted in bits are technically undefined. This is also slightly complicated by the zero case.

Parameters
origThe original mask to extend.
Returns
The extended mask.

Definition at line 160 of file trie.hh.

References gem5::Trie< Key, Value >::MaxBits.

Referenced by gem5::Trie< Key, Value >::insert().

◆ goesAfter()

template<class Key , class Value >
bool gem5::Trie< Key, Value >::goesAfter ( Node ** parent,
Node * kid,
Key key,
Key new_mask )
inlineprivate

A utility method which checks whether the key being looked up lies beyond the Node being examined.

If so, it returns true and advances the node being examined.

Parameters
parentThe node we're currently "at", which can be updated.
kidThe node we may want to move to.
keyThe key we're looking for.
new_maskThe mask to use when matching against the key.
Returns
Whether the current Node was advanced.

Definition at line 141 of file trie.hh.

References gem5::Trie< Key, Value >::Node::mask, and gem5::Trie< Key, Value >::Node::matches().

Referenced by gem5::Trie< Key, Value >::insert().

◆ lookupHandle()

template<class Key , class Value >
Handle gem5::Trie< Key, Value >::lookupHandle ( Key key)
inlineprivate

Method which looks up the Handle corresponding to a particular key.

This is useful if you want to delete the Handle corresponding to a key since the "remove" function takes a Handle as its argument.

Parameters
keyThe key to look up.
Returns
The first Handle matching this key, or NULL if none was found.

Definition at line 175 of file trie.hh.

References gem5::Trie< Key, Value >::head, gem5::Trie< Key, Value >::Node::kids, and gem5::Trie< Key, Value >::Node::value.

Referenced by gem5::Trie< Key, Value >::lookup(), and gem5::Trie< Key, Value >::remove().

Member Data Documentation

◆ head


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

Generated on Tue Jun 18 2024 16:24:15 for gem5 by doxygen 1.11.0