12#ifndef LLVM_ADT_RADIXTREE_H
13#define LLVM_ADT_RADIXTREE_H
71template <
typename KeyType,
typename T>
class RadixTree {
75 using value_type = std::pair<const KeyType, mapped_type>;
78 using KeyConstIteratorType =
79 decltype(
adl_begin(std::declval<const key_type &>()));
83 using ContainerType = std::list<value_type>;
87 KeyConstIteratorRangeType
Key{KeyConstIteratorType{},
88 KeyConstIteratorType{}};
89 std::vector<Node> Children;
96 typename ContainerType::iterator
Value;
99 KeyValueType KeyFront;
102 Node(
const KeyConstIteratorRangeType &
Key)
107 Node(Node &&) =
default;
110 Node(
const Node &) =
delete;
113 const Node *findChild(
const KeyConstIteratorRangeType &
Key)
const {
116 for (
const Node &Child : Children) {
117 assert(!Child.Key.empty());
118 if (Child.KeyFront == *
Key.begin())
124 Node *findChild(
const KeyConstIteratorRangeType &Query) {
125 const Node *This =
this;
126 return const_cast<Node *
>(This->findChild(Query));
131 for (
const Node &
C : Children)
146 void split(KeyConstIteratorType SplitPoint) {
150 Children.swap(Child.Children);
153 Children.emplace_back(std::move(Child));
160 ContainerType KeyValuePairs;
163 Node &findOrCreate(KeyConstIteratorRangeType
Key) {
172 if (I2 != Curr->Key.end()) {
182 Node *Child = Curr->findChild(
Key);
198 return Curr->Children.emplace_back(
Key);
210 template <
typename MappedType>
212 :
public iterator_facade_base<IteratorImpl<MappedType>,
213 std::forward_iterator_tag, MappedType> {
214 const Node *Curr =
nullptr;
215 KeyConstIteratorRangeType Query{KeyConstIteratorType{},
216 KeyConstIteratorType{}};
218 void findNextValid() {
219 while (Curr && Curr->Value ==
typename ContainerType::iterator())
230 Curr = Curr->findChild(Query);
237 if (I2 != Curr->Key.end()) {
244 friend class RadixTree;
245 IteratorImpl(
const Node *
C,
const KeyConstIteratorRangeType &Q)
246 : Curr(
C), Query(Q) {
251 IteratorImpl() =
default;
253 MappedType &operator*()
const {
return *Curr->Value; }
262 return Curr ==
Other.Curr;
278 bool empty()
const {
return KeyValuePairs.empty(); }
281 size_t size()
const {
return KeyValuePairs.size(); }
310 template <
typename... Ts>
316 const value_type &NewValue = KeyValuePairs.emplace_front(
317 std::move(
Key),
T(std::forward<Ts>(Args)...));
318 Node &Node = findOrCreate(NewValue.first);
319 bool HasValue = Node.Value !=
typename ContainerType::iterator();
321 Node.Value = KeyValuePairs.begin();
323 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.