12#ifndef LLVM_ADT_RADIXTREE_H
13#define LLVM_ADT_RADIXTREE_H
70template <
typename KeyType,
typename T>
class RadixTree {
74 using value_type = std::pair<const KeyType, mapped_type>;
77 using KeyConstIteratorType =
78 decltype(
adl_begin(std::declval<const key_type &>()));
82 using ContainerType = std::list<value_type>;
86 KeyConstIteratorRangeType
Key{KeyConstIteratorType{},
87 KeyConstIteratorType{}};
88 std::vector<Node> Children;
95 typename ContainerType::iterator
Value;
98 KeyValueType KeyFront;
101 Node(
const KeyConstIteratorRangeType &
Key)
106 Node(Node &&) =
default;
109 Node(
const Node &) =
delete;
112 const Node *findChild(
const KeyConstIteratorRangeType &
Key)
const {
115 for (
const Node &Child : Children) {
116 assert(!Child.Key.empty());
117 if (Child.KeyFront == *
Key.begin())
123 Node *findChild(
const KeyConstIteratorRangeType &Query) {
124 const Node *This =
this;
125 return const_cast<Node *
>(This->findChild(Query));
130 for (
const Node &
C : Children)
145 void split(KeyConstIteratorType SplitPoint) {
149 Children.swap(Child.Children);
152 Children.emplace_back(std::move(Child));
159 ContainerType KeyValuePairs;
162 Node &findOrCreate(KeyConstIteratorRangeType
Key) {
171 if (I2 != Curr->Key.end()) {
181 Node *Child = Curr->findChild(
Key);
197 return Curr->Children.emplace_back(
Key);
209 template <
typename MappedType>
211 :
public iterator_facade_base<IteratorImpl<MappedType>,
212 std::forward_iterator_tag, MappedType> {
213 const Node *Curr =
nullptr;
214 KeyConstIteratorRangeType Query{KeyConstIteratorType{},
215 KeyConstIteratorType{}};
217 void findNextValid() {
218 while (Curr && Curr->Value ==
typename ContainerType::iterator())
229 Curr = Curr->findChild(Query);
236 if (I2 != Curr->Key.end()) {
243 friend class RadixTree;
244 IteratorImpl(
const Node *
C,
const KeyConstIteratorRangeType &Q)
245 : Curr(
C), Query(Q) {
250 IteratorImpl() =
default;
252 MappedType &operator*()
const {
return *Curr->Value; }
261 return Curr ==
Other.Curr;
277 bool empty()
const {
return KeyValuePairs.empty(); }
280 size_t size()
const {
return KeyValuePairs.size(); }
309 template <
typename... Ts>
315 const value_type &NewValue = KeyValuePairs.emplace_front(
316 std::move(
Key),
T(std::forward<Ts>(Args)...));
317 Node &Node = findOrCreate(NewValue.first);
318 bool HasValue = Node.Value !=
typename ContainerType::iterator();
320 Node.Value = KeyValuePairs.begin();
322 KeyValuePairs.pop_front();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
iterator end()
Returns an iterator to the end of 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.
const_iterator end() const
typename ContainerType::const_iterator const_iterator
RadixTree(RadixTree &&)=default
std::pair< iterator, bool > emplace(key_type &&Key, Ts &&...Args)
Constructs and inserts a new element into the tree.
RadixTree & operator=(RadixTree &&)=default
std::pair< const KeyType, mapped_type > value_type
const_iterator begin() const
typename ContainerType::iterator iterator
bool empty() const
Returns true if the tree is empty.
IteratorImpl< const value_type > const_prefix_iterator
iterator begin()
Returns an iterator to the first element.
IteratorImpl< value_type > prefix_iterator
size_t countNodes() const
Returns the number of nodes in the tree.
size_t size() const
Returns the number of elements in the tree.
LLVM Value Representation.
IteratorImpl< MappedType > & operator++()
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
NodeAddr< NodeBase * > Node
This is an optimization pass for GlobalISel generic memory operations.
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto mismatch(R1 &&Range1, R2 &&Range2)
Provide wrappers to std::mismatch which take ranges instead of having to pass begin/end explicitly.
detail::ValueMatchesPoly< M > HasValue(M Matcher)
iterator_range< SplittingIterator > split(StringRef Str, StringRef Separator)
Split the specified string over a separator and return a range-compatible iterable over its partition...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.