LLVM 22.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 |
LLVM_ABI 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 67 of file TrieRawHashMap.h.
|
protecteddelete |
References LLVM_ABI, RHS, and ThreadSafeTrieRawHashMapBase().
Referenced by operator=(), operator=(), llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::ThreadSafeTrieRawHashMap(), ThreadSafeTrieRawHashMapBase(), ThreadSafeTrieRawHashMapBase(), ThreadSafeTrieRawHashMapBase(), and llvm::ThreadSafeTrieRawHashMapBase::ImplType::TrailingObjects.
|
protected |
Definition at line 331 of file TrieRawHashMap.cpp.
References assert(), DefaultNumRootBits, and DefaultNumSubtrieBits.
|
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 ThreadSafeTrieRawHashMapBase().
|
protecteddelete |
References ThreadSafeTrieRawHashMapBase().
|
protected |
Definition at line 362 of file TrieRawHashMap.cpp.
References llvm::dyn_cast_or_null(), I, and llvm::Next.
Referenced by llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::~ThreadSafeTrieRawHashMap().
LLVM_DUMP_METHOD void llvm::ThreadSafeTrieRawHashMapBase::dump | ( | ) | const |
References LLVM_DUMP_METHOD.
|
protected |
Find the stored content with hash.
Definition at line 231 of file TrieRawHashMap.cpp.
References assert(), llvm::cast(), llvm::dyn_cast(), llvm::ArrayRef< T >::empty(), llvm::TrieHashIndexGenerator::end(), llvm_unreachable, llvm::TrieHashIndexGenerator::next(), and llvm::TrieHashIndexGenerator::StartBit.
Referenced by llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::find(), and llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::find().
|
protected |
Definition at line 504 of file TrieRawHashMap.cpp.
References assert(), llvm::dyn_cast(), and P.
|
protected |
Definition at line 407 of file TrieRawHashMap.cpp.
References assert(), llvm::dyn_cast(), and P.
|
protected |
Definition at line 417 of file TrieRawHashMap.cpp.
References assert(), llvm::dyn_cast(), I, and P.
|
protected |
Definition at line 493 of file TrieRawHashMap.cpp.
|
protected |
Definition at line 390 of file TrieRawHashMap.cpp.
|
protected |
Definition at line 397 of file TrieRawHashMap.cpp.
References assert(), llvm::dyn_cast(), and P.
|
protected |
Definition at line 432 of file TrieRawHashMap.cpp.
References assert(), llvm::dyn_cast(), I, llvm::Next, llvm::Offset, P, llvm::Sub, llvm::StringRef::take_front(), llvm::toHex(), and llvm::toStringRef().
|
protected |
Insert and return the stored content.
Definition at line 259 of file TrieRawHashMap.cpp.
References assert(), llvm::cast(), llvm::dyn_cast(), llvm::ArrayRef< T >::empty(), llvm::TrieHashIndexGenerator::end(), llvm::TrieHashIndexGenerator::getCollidingBits(), llvm::TrieHashIndexGenerator::getNumBits(), llvm::TrieHashIndexGenerator::hint(), llvm_unreachable, llvm::TrieHashIndexGenerator::next(), and llvm::ArrayRef< T >::size().
Referenced by llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::insertLazy().
|
inline |
Definition at line 92 of file TrieRawHashMap.h.
References Ptr.
|
inlinestatic |
Definition at line 91 of file TrieRawHashMap.h.
References Size.
|
protecteddelete |
References LLVM_ABI, P, and ThreadSafeTrieRawHashMapBase().
|
protecteddelete |
References RHS, and ThreadSafeTrieRawHashMapBase().
LLVM_ABI void llvm::ThreadSafeTrieRawHashMapBase::print | ( | raw_ostream & | OS | ) | const |
References LLVM_ABI.
|
friend |
Definition at line 170 of file TrieRawHashMap.h.
References TrieRawHashMapTestHelper.
Referenced by TrieRawHashMapTestHelper.
|
staticconstexprprotected |
Definition at line 84 of file TrieRawHashMap.h.
Referenced by llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::ThreadSafeTrieRawHashMap().
|
staticconstexprprotected |
Definition at line 81 of file TrieRawHashMap.h.
Referenced by llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::ThreadSafeTrieRawHashMap().
|
staticconstexprprotected |
Definition at line 87 of file TrieRawHashMap.h.
Referenced by llvm::ThreadSafeTrieRawHashMap< DataT, sizeof(HashType)>::ThreadSafeTrieRawHashMap().
|
staticconstexpr |
Definition at line 70 of file TrieRawHashMap.h.
Referenced by ThreadSafeTrieRawHashMapBase().
|
staticconstexpr |
Definition at line 71 of file TrieRawHashMap.h.
Referenced by ThreadSafeTrieRawHashMapBase().
|
staticconstexpr |
Definition at line 69 of file TrieRawHashMap.h.