LLVM 20.0.0git
|
TrieRawHashMap - is a lock-free thread-safe trie that is can be used to store/index data based on a hash value. More...
#include "llvm/ADT/TrieRawHashMap.h"
Classes | |
class | ImplType |
class | PointerBase |
Result of a lookup. More... | |
Public Member Functions | |
void | operator delete (void *Ptr) |
LLVM_DUMP_METHOD void | dump () const |
void | print (raw_ostream &OS) const |
Static Public Member Functions | |
static void * | operator new (size_t Size) |
Static Public Attributes | |
static constexpr size_t | TrieContentBaseSize = 4 |
static constexpr size_t | DefaultNumRootBits = 6 |
static constexpr size_t | DefaultNumSubtrieBits = 4 |
Static Protected Attributes | |
template<class T > | |
static constexpr size_t | DefaultContentAllocSize = sizeof(AllocValueType<T>) |
template<class T > | |
static constexpr size_t | DefaultContentAllocAlign = alignof(AllocValueType<T>) |
template<class T > | |
static constexpr size_t | DefaultContentOffset |
Friends | |
class | TrieRawHashMapTestHelper |
TrieRawHashMap - is a lock-free thread-safe trie that is can be used to store/index data based on a hash value.
It can be customized to work with any hash algorithm or store any data.
Data structure: Data node stored in the Trie contains both hash and data: struct { HashT Hash; DataT Data; };
Data is stored/indexed via a prefix tree, where each node in the tree can be either the root, a sub-trie or a data node. Assuming a 4-bit hash and two data objects {0001, A} and {0100, B}, it can be stored in a trie (assuming Root has 2 bits, SubTrie has 1 bit): +-----—+ |Root[00]| -> {0001, A} | [01]| -> {0100, B} | [10]| (empty) | [11]| (empty) +-----—+
Inserting a new object {0010, C} will result in: +-----—+ +-------—+ |Root[00]| -> |SubTrie[0]| -> {0001, A} | | | [1]| -> {0010, C} | | +-------—+ | [01]| -> {0100, B} | [10]| (empty) | [11]| (empty) +-----—+ Note object A is sunk down to a sub-trie during the insertion. All the nodes are inserted through compare-exchange to ensure thread-safe and lock-free.
To find an object in the trie, walk the tree with prefix of the hash until the data node is found. Then the hash is compared with the hash stored in the data node to see if the is the same object.
Hash collision is not allowed so it is recommended to use trie with a "strong" hashing algorithm. A well-distributed hash can also result in better performance and memory usage.
It currently does not support iteration and deletion. Base class for a lock-free thread-safe hash-mapped trie.
Definition at line 66 of file TrieRawHashMap.h.
|
protecteddelete |
|
protected |
Definition at line 331 of file TrieRawHashMap.cpp.
References assert().
|
protected |
Destructor, which asserts if there's anything to do.
Subclasses should call destroyImpl().
Definition at line 358 of file TrieRawHashMap.cpp.
References assert().
|
protected |
Definition at line 348 of file TrieRawHashMap.cpp.
References RHS.
|
protecteddelete |
|
protected |
Definition at line 362 of file TrieRawHashMap.cpp.
Referenced by llvm::ThreadSafeTrieRawHashMap< T, NumHashBytes >::~ThreadSafeTrieRawHashMap().
LLVM_DUMP_METHOD void llvm::ThreadSafeTrieRawHashMapBase::dump | ( | ) | const |
|
protected |
Find the stored content with hash.
Definition at line 231 of file TrieRawHashMap.cpp.
References assert(), llvm::ArrayRef< T >::empty(), llvm::ThreadSafeTrieRawHashMapBase::ImplType::getRoot(), Index, and llvm_unreachable.
Referenced by llvm::ThreadSafeTrieRawHashMap< T, NumHashBytes >::find().
|
protected |
Definition at line 504 of file TrieRawHashMap.cpp.
|
protected |
Definition at line 407 of file TrieRawHashMap.cpp.
|
protected |
|
protected |
Definition at line 493 of file TrieRawHashMap.cpp.
References llvm::ThreadSafeTrieRawHashMapBase::ImplType::getRoot().
|
protected |
Definition at line 390 of file TrieRawHashMap.cpp.
References llvm::ThreadSafeTrieRawHashMapBase::ImplType::getRoot().
|
protected |
Definition at line 397 of file TrieRawHashMap.cpp.
|
protected |
Definition at line 432 of file TrieRawHashMap.cpp.
References assert(), Content, E, I, Index, llvm::Offset, P, and llvm::StringRef::take_front().
|
protected |
Insert and return the stored content.
Definition at line 259 of file TrieRawHashMap.cpp.
References assert(), Content, llvm::ThreadSafeTrieRawHashMapBase::ImplType::ContentAlloc, llvm::ArrayRef< T >::empty(), llvm::ThreadSafeTrieRawHashMapBase::ImplType::getRoot(), Index, llvm_unreachable, and llvm::ArrayRef< T >::size().
Referenced by llvm::ThreadSafeTrieRawHashMap< T, NumHashBytes >::insertLazy().
|
inline |
Definition at line 91 of file TrieRawHashMap.h.
References Ptr.
|
inlinestatic |
Definition at line 90 of file TrieRawHashMap.h.
References Size.
|
protecteddelete |
|
protecteddelete |
void llvm::ThreadSafeTrieRawHashMapBase::print | ( | raw_ostream & | OS | ) | const |
|
friend |
Definition at line 166 of file TrieRawHashMap.h.
|
staticconstexprprotected |
Definition at line 83 of file TrieRawHashMap.h.
|
staticconstexprprotected |
Definition at line 80 of file TrieRawHashMap.h.
|
staticconstexprprotected |
Definition at line 86 of file TrieRawHashMap.h.
|
staticconstexpr |
Definition at line 69 of file TrieRawHashMap.h.
|
staticconstexpr |
Definition at line 70 of file TrieRawHashMap.h.
|
staticconstexpr |
Definition at line 68 of file TrieRawHashMap.h.