17#ifndef LLVM_ADT_MAPVECTOR_H
18#define LLVM_ADT_MAPVECTOR_H
33template <
typename KeyT,
typename ValueT,
42 using iterator =
typename VectorType::iterator;
50 return std::move(Vector);
61 Map.reserve(NumEntries);
62 Vector.reserve(NumEntries);
72 return Vector.rbegin();
77 [[nodiscard]]
bool empty()
const {
return Vector.empty(); }
79 [[nodiscard]] std::pair<KeyT, ValueT> &
front() {
return Vector.front(); }
80 [[nodiscard]]
const std::pair<KeyT, ValueT> &
front()
const {
81 return Vector.front();
83 [[nodiscard]] std::pair<KeyT, ValueT> &
back() {
return Vector.back(); }
84 [[nodiscard]]
const std::pair<KeyT, ValueT> &
back()
const {
99 return try_emplace_impl(
Key).first->second;
109 static_assert(std::is_copy_constructible_v<ValueT>,
110 "Cannot call lookup() if ValueT is not copyable.");
111 typename MapType::const_iterator Pos = Map.find(
Key);
112 return Pos == Map.end()? ValueT() : Vector[Pos->second].second;
115 template <
typename... Ts>
117 return try_emplace_impl(
Key, std::forward<Ts>(Args)...);
119 template <
typename... Ts>
121 return try_emplace_impl(std::move(
Key), std::forward<Ts>(Args)...);
124 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
125 return try_emplace_impl(KV.first, KV.second);
127 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
128 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
131 template <
typename V>
135 Ret.first->second = std::forward<V>(Val);
138 template <
typename V>
142 Ret.first->second = std::forward<V>(Val);
147 return Map.find(
Key) != Map.end();
155 typename MapType::const_iterator Pos = Map.find(
Key);
156 return Pos == Map.end() ? Vector.end() : (Vector.begin() + Pos->second);
160 typename MapType::const_iterator Pos = Map.find(
Key);
161 return Pos == Map.end() ? Vector.end() : (Vector.begin() + Pos->second);
167 auto Pos = Map.find(
Key);
168 assert(Pos != Map.end() &&
"MapVector::at failed due to a missing key");
169 return Vector[Pos->second].second;
175 auto Pos = Map.find(
Key);
176 assert(Pos != Map.end() &&
"MapVector::at failed due to a missing key");
177 return Vector[Pos->second].second;
182 typename MapType::iterator Pos = Map.find(Vector.back().first);
194 typename VectorType::iterator
erase(
typename VectorType::iterator Iterator) {
195 Map.erase(Iterator->first);
196 auto Next = Vector.erase(Iterator);
197 if (
Next == Vector.end())
201 size_t Index =
Next - Vector.begin();
202 for (
auto &
I : Map) {
203 assert(
I.second != Index &&
"Index was already erased!");
204 if (
I.second > Index)
215 if (Iterator ==
end())
232 std::is_integral_v<typename MapType::mapped_type>,
233 "The mapped_type of the specified Map must be an integral type");
235 template <
typename KeyArgT,
typename... Ts>
236 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
237 auto [It, Inserted] = Map.try_emplace(
Key);
239 It->second = Vector.size();
240 Vector.emplace_back(std::piecewise_construct,
241 std::forward_as_tuple(std::forward<KeyArgT>(
Key)),
242 std::forward_as_tuple(std::forward<Ts>(Args)...));
243 return {std::prev(
end()),
true};
245 return {
begin() + It->second,
false};
249template <
typename KeyT,
typename ValueT,
typename MapType,
typename VectorType>
250template <
class Function>
252 auto O = Vector.begin();
253 for (
auto I = O,
E = Vector.end();
I !=
E; ++
I) {
263 Map[O->first] = O - Vector.begin();
268 Vector.erase(O, Vector.end());
273template <
typename KeyT,
typename ValueT,
unsigned N>
275 :
MapVector<KeyT, ValueT, SmallDenseMap<KeyT, unsigned, N>,
276 SmallVector<std::pair<KeyT, ValueT>, N>> {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class implements a map that also provides access to all stored values in a deterministic order.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
size_type count(const KeyT &Key) const
typename VectorType::iterator iterator
void pop_back()
Remove the last element from the vector.
const_reverse_iterator rbegin() const
void swap(MapVector &RHS)
ValueT & operator[](const KeyT &Key)
const_iterator end() const
const ValueT & at(const KeyT &Key) const
at - Return the entry for the specified key, or abort if no such entry exists.
VectorType::iterator erase(typename VectorType::iterator Iterator)
Remove the element given by Iterator.
std::pair< iterator, bool > insert_or_assign(KeyT &&Key, V &&Val)
VectorType takeVector()
Clear the MapVector and return the underlying vector.
typename VectorType::size_type size_type
const std::pair< KeyT, ValueT > & back() const
const std::pair< KeyT, ValueT > & front() const
typename VectorType::const_reverse_iterator const_reverse_iterator
typename VectorType::value_type value_type
iterator find(const KeyT &Key)
void remove_if(Predicate Pred)
Remove the elements that match the predicate.
bool contains(const KeyT &Key) const
const_iterator begin() const
ValueT & at(const KeyT &Key)
at - Return the entry for the specified key, or abort if no such entry exists.
std::pair< iterator, bool > insert_or_assign(const KeyT &Key, V &&Val)
const_iterator find(const KeyT &Key) const
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ArrayRef< value_type > getArrayRef() const
Returns an array reference of the underlying vector.
ValueT lookup(const KeyT &Key) const
void reserve(size_type NumEntries)
Grow the MapVector so that it can contain at least NumEntries items before resizing again.
typename VectorType::reverse_iterator reverse_iterator
size_type erase(const KeyT &Key)
Remove all elements with the key value Key.
typename VectorType::const_iterator const_iterator
std::pair< KeyT, ValueT > & front()
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
const_reverse_iterator rend() const
reverse_iterator rbegin()
std::pair< KeyT, ValueT > & back()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Base class of all SIMD vector types.
This is an optimization pass for GlobalISel generic memory operations.
auto make_first_range(ContainerTy &&c)
Given a container of pairs, return a range over the first elements.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionAddr VTableAddr Next
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
A MapVector that performs no allocations if smaller than a certain size.