|
LLVM 22.0.0git
|
A Radix Tree implementation. More...
#include "llvm/ADT/RadixTree.h"
Public Types | |
| using | key_type = KeyType |
| using | mapped_type = T |
| using | value_type = std::pair<const KeyType, mapped_type> |
| using | prefix_iterator = IteratorImpl<value_type> |
| using | const_prefix_iterator = IteratorImpl<const value_type> |
| using | iterator = typename ContainerType::iterator |
| using | const_iterator = typename ContainerType::const_iterator |
Public Member Functions | |
| RadixTree ()=default | |
| RadixTree (RadixTree &&)=default | |
| RadixTree & | operator= (RadixTree &&)=default |
| bool | empty () const |
| Returns true if the tree is empty. | |
| size_t | size () const |
| Returns the number of elements in the tree. | |
| size_t | countNodes () const |
| Returns the number of nodes in the tree. | |
| iterator | begin () |
| Returns an iterator to the first element. | |
| const_iterator | begin () const |
| iterator | end () |
| Returns an iterator to the end of the tree. | |
| const_iterator | end () const |
| template<typename... Ts> | |
| std::pair< iterator, bool > | emplace (key_type &&Key, Ts &&...Args) |
| Constructs and inserts a new element into the tree. | |
| iterator_range< const_prefix_iterator > | find_prefixes (const key_type &Key) const |
| Finds all elements whose keys are prefixes of the given Key. | |
A Radix Tree implementation.
A Radix Tree (also known as a compact prefix tree or radix trie) is a data structure that stores a dynamic set or associative array where keys are strings and values are associated with these keys. Unlike a regular trie, the edges of a radix tree can be labeled with sequences of characters as well as single characters. This makes radix trees more efficient for storing sparse data sets, where many nodes in a regular trie would have only one child.
This implementation supports arbitrary key types that can be iterated over (e.g., std::string, std::vector<char>, ArrayRef<char>). The key type must provide begin() and end() for iteration.
The tree stores std::pair<const KeyType, T> as its value type.
Example usage:
Definition at line 71 of file RadixTree.h.
| using llvm::RadixTree< KeyType, T >::const_iterator = typename ContainerType::const_iterator |
Definition at line 275 of file RadixTree.h.
| using llvm::RadixTree< KeyType, T >::const_prefix_iterator = IteratorImpl<const value_type> |
Definition at line 272 of file RadixTree.h.
| using llvm::RadixTree< KeyType, T >::iterator = typename ContainerType::iterator |
Definition at line 274 of file RadixTree.h.
| using llvm::RadixTree< KeyType, T >::key_type = KeyType |
Definition at line 73 of file RadixTree.h.
| using llvm::RadixTree< KeyType, T >::mapped_type = T |
Definition at line 74 of file RadixTree.h.
| using llvm::RadixTree< KeyType, T >::prefix_iterator = IteratorImpl<value_type> |
Definition at line 271 of file RadixTree.h.
| using llvm::RadixTree< KeyType, T >::value_type = std::pair<const KeyType, mapped_type> |
Definition at line 75 of file RadixTree.h.
|
default |
Referenced by operator=(), and RadixTree().
|
default |
References RadixTree().
|
inline |
Returns an iterator to the first element.
Definition at line 290 of file RadixTree.h.
|
inline |
Definition at line 291 of file RadixTree.h.
|
inline |
Returns the number of nodes in the tree.
This function counts all internal nodes in the tree. It can be useful for understanding the memory footprint or complexity of the tree structure.
Definition at line 287 of file RadixTree.h.
|
inline |
Constructs and inserts a new element into the tree.
This function constructs an element in place within the tree. If an element with the same key already exists, the insertion fails and the function returns an iterator to the existing element along with false. Otherwise, the new element is inserted and the function returns an iterator to the new element along with true.
| Key | The key of the element to construct. |
| Args | Arguments to forward to the constructor of the mapped_type. |
Definition at line 311 of file RadixTree.h.
References llvm::HasValue(), llvm::InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key, and T.
|
inline |
Returns true if the tree is empty.
Definition at line 278 of file RadixTree.h.
|
inline |
Returns an iterator to the end of the tree.
Definition at line 294 of file RadixTree.h.
|
inline |
Definition at line 295 of file RadixTree.h.
|
inline |
Finds all elements whose keys are prefixes of the given Key.
This function returns an iterator range over all elements in the tree whose keys are prefixes of the provided Key. For example, if the tree contains "abcde", "abc", "abcdefgh", and Key is "abcde", this function would return iterators to "abcde" and "abc".
| Key | The key to search for prefixes of. |
Definition at line 342 of file RadixTree.h.
References llvm::InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key.
|
default |
References RadixTree().
|
inline |
Returns the number of elements in the tree.
Definition at line 281 of file RadixTree.h.