Bitcoin ABC 0.30.5
P2P Digital Currency
|
This is a radix tree storing values identified by a unique key. More...
#include <radix.h>
Classes | |
struct | RadixElement |
struct | RadixNode |
Public Member Functions | |
RadixTree () | |
~RadixTree () | |
RadixTree (const RadixTree &src) | |
Copy semantic. More... | |
RadixTree & | operator= (const RadixTree &rhs) |
RadixTree (RadixTree &&src) | |
Move semantic. More... | |
RadixTree & | operator= (RadixTree &&rhs) |
bool | insert (const RCUPtr< T > &value) |
Insert a value into the tree. More... | |
RCUPtr< T > | get (const KeyType &key) |
Get the value corresponding to a key. More... | |
RCUPtr< const T > | get (const KeyType &key) const |
template<typename Callable > | |
bool | forEachLeaf (Callable &&func) const |
RCUPtr< T > | remove (const KeyType &key) |
Remove an element from the tree. More... | |
Private Types | |
using | KeyType = typename std::remove_reference< decltype(std::declval< Adapter & >().getId(std::declval< T & >()))>::type |
Private Member Functions | |
KeyType | getId (const T &value) const |
bool | insert (const KeyType &key, RCUPtr< T > value) |
template<typename Callable > | |
bool | forEachLeaf (RadixElement e, Callable &&func) const |
Private Member Functions inherited from PassthroughAdapter< T > | |
auto && | getId (const T &e) const |
Private Attributes | |
std::atomic< RadixElement > | root |
Static Private Attributes | |
static const int | BITS = 4 |
static const int | MASK = (1 << BITS) - 1 |
static const size_t | CHILD_PER_LEVEL = 1 << BITS |
static const size_t | KEY_BITS = 8 * sizeof(KeyType) |
static const uint32_t | TOP_LEVEL = (KEY_BITS - 1) / BITS |
This is a radix tree storing values identified by a unique key.
The tree is composed of nodes (RadixNode) containing an array of RadixElement. The key is split into chunks of a few bits that serve as an index into that array. RadixElement is a discriminated union of either a RadixNode* representing the next level in the tree, or a T* representing a leaf. New RadixNode are added lazily when two leaves would go in the same slot.
Reads walk the tree using sequential atomic loads, and insertions are done using CAS, which ensures both can be executed lock free. Removing any elements from the tree can also be done using CAS, but requires waiting for other readers before being destroyed. The tree uses RCU to track which thread is reading the tree, which allows deletion to wait for other readers to be up to speed before destroying anything. It is therefore crucial that the lock be taken before reading anything in the tree.
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
|
staticprivate |
|
private |