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);
76 return Vector.empty();
79 std::pair<KeyT, ValueT> &
front() {
return Vector.front(); }
80 const std::pair<KeyT, ValueT> &
front()
const {
return Vector.front(); }
81 std::pair<KeyT, ValueT> &
back() {
return Vector.back(); }
82 const std::pair<KeyT, ValueT> &
back()
const {
return Vector.back(); }
95 return try_emplace_impl(
Key).first->second;
100 static_assert(std::is_copy_constructible_v<ValueT>,
101 "Cannot call lookup() if ValueT is not copyable.");
102 typename MapType::const_iterator Pos = Map.find(
Key);
103 return Pos == Map.end()?
ValueT() : Vector[Pos->second].second;
106 template <
typename... Ts>
108 return try_emplace_impl(
Key, std::forward<Ts>(Args)...);
110 template <
typename... Ts>
112 return try_emplace_impl(std::move(
Key), std::forward<Ts>(Args)...);
115 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
116 return try_emplace_impl(KV.first, KV.second);
118 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
119 return try_emplace_impl(std::move(KV.first), std::move(KV.second));
122 template <
typename V>
126 Ret.first->second = std::forward<V>(Val);
129 template <
typename V>
133 Ret.first->second = std::forward<V>(Val);
142 typename MapType::const_iterator Pos = Map.find(
Key);
143 return Pos == Map.end()? Vector.end() :
144 (Vector.begin() + Pos->second);
148 typename MapType::const_iterator Pos = Map.find(
Key);
149 return Pos == Map.end()? Vector.end() :
150 (Vector.begin() + Pos->second);
155 typename MapType::iterator Pos = Map.find(Vector.back().first);
167 typename VectorType::iterator
erase(
typename VectorType::iterator Iterator) {
168 Map.erase(Iterator->first);
169 auto Next = Vector.erase(Iterator);
170 if (
Next == Vector.end())
174 size_t Index =
Next - Vector.begin();
175 for (
auto &
I : Map) {
176 assert(
I.second != Index &&
"Index was already erased!");
177 if (
I.second > Index)
188 if (Iterator ==
end())
205 std::is_integral_v<typename MapType::mapped_type>,
206 "The mapped_type of the specified Map must be an integral type");
208 template <
typename KeyArgT,
typename... Ts>
209 std::pair<iterator, bool> try_emplace_impl(KeyArgT &&
Key, Ts &&...Args) {
210 auto [It, Inserted] = Map.try_emplace(
Key);
212 It->second = Vector.size();
213 Vector.emplace_back(std::piecewise_construct,
214 std::forward_as_tuple(std::forward<KeyArgT>(
Key)),
215 std::forward_as_tuple(std::forward<Ts>(Args)...));
216 return {std::prev(
end()),
true};
218 return {
begin() + It->second,
false};
222template <
typename KeyT,
typename ValueT,
typename MapType,
typename VectorType>
223template <
class Function>
225 auto O = Vector.begin();
226 for (
auto I = O,
E = Vector.end();
I !=
E; ++
I) {
236 Map[O->first] = O - Vector.begin();
241 Vector.erase(O, Vector.end());
246template <
typename KeyT,
typename ValueT,
unsigned N>
248 :
MapVector<KeyT, ValueT, SmallDenseMap<KeyT, unsigned, N>,
249 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
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
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.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionAddr VTableAddr Next
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.