gem5 v24.0.0.0
|
A trie is a tree-based data structure used for data retrieval. More...
#include <trie.hh>
Classes | |
struct | Node |
Public Types | |
typedef Node * | Handle |
Public Member Functions | |
Trie () | |
Handle | insert (Key key, unsigned width, Value *val) |
Method which inserts a key/value pair into the trie. | |
Value * | lookup (Key key) |
Method which looks up the Value corresponding to a particular key. | |
Value * | remove (Handle handle) |
Method to delete a value from the trie. | |
Value * | remove (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. | |
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.
Key | Type of the key of the tree nodes. Must be an integral type. |
Value | Type of the values associated to the keys. |
|
inline |
A debugging method which prints the contents of this trie.
title | An 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().
|
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.
orig | The original mask to extend. |
Definition at line 160 of file trie.hh.
References gem5::Trie< Key, Value >::MaxBits.
Referenced by gem5::Trie< Key, Value >::insert().
|
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.
parent | The node we're currently "at", which can be updated. |
kid | The node we may want to move to. |
key | The key we're looking for. |
new_mask | The mask to use when matching against the key. |
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().
|
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.
key | The key to look up. |
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().
|
protected |
Definition at line 110 of file trie.hh.
Referenced by gem5::Trie< Key, Value >::clear(), gem5::Trie< Key, Value >::dump(), gem5::Trie< Key, Value >::insert(), and gem5::Trie< Key, Value >::lookupHandle().