17#ifndef LLVM_ADT_MAPVECTOR_H
18#define LLVM_ADT_MAPVECTOR_H
34 typename MapType = DenseMap<KeyT, unsigned>,
35 typename VectorType = SmallVector<std::pair<KeyT, ValueT>, 0>>
41 std::is_integral_v<typename MapType::mapped_type>,
42 "The mapped_type of the specified Map must be an integral type");
49 using iterator =
typename VectorType::iterator;
65 Map.reserve(NumEntries);
66 Vector.reserve(NumEntries);
84 const std::pair<KeyT, ValueT> &
front()
const {
return Vector.front(); }
85 std::pair<KeyT, ValueT> &
back() {
return Vector.back(); }
86 const std::pair<KeyT, ValueT> &
back()
const {
return Vector.back(); }
99 std::pair<KeyT, typename MapType::mapped_type> Pair = std::make_pair(Key, 0);
100 std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
101 auto &
I = Result.first->second;
111 static_assert(std::is_copy_constructible_v<ValueT>,
112 "Cannot call lookup() if ValueT is not copyable.");
113 typename MapType::const_iterator Pos = Map.find(Key);
114 return Pos == Map.end()?
ValueT() :
Vector[Pos->second].second;
117 template <
typename... Ts>
119 auto [It, Inserted] = Map.insert(std::make_pair(Key, 0));
121 It->second =
Vector.size();
122 Vector.emplace_back(std::piecewise_construct, std::forward_as_tuple(Key),
123 std::forward_as_tuple(std::forward<Ts>(Args)...));
124 return std::make_pair(std::prev(
end()),
true);
126 return std::make_pair(
begin() + It->second,
false);
128 template <
typename... Ts>
130 auto [It, Inserted] = Map.insert(std::make_pair(Key, 0));
132 It->second =
Vector.size();
133 Vector.emplace_back(std::piecewise_construct,
134 std::forward_as_tuple(std::move(Key)),
135 std::forward_as_tuple(std::forward<Ts>(Args)...));
136 return std::make_pair(std::prev(
end()),
true);
138 return std::make_pair(
begin() + It->second,
false);
141 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
144 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
145 return try_emplace(std::move(KV.first), std::move(KV.second));
148 template <
typename V>
152 Ret.first->second = std::forward<V>(Val);
155 template <
typename V>
157 auto Ret =
try_emplace(std::move(Key), std::forward<V>(Val));
159 Ret.first->second = std::forward<V>(Val);
163 bool contains(
const KeyT &Key)
const {
return Map.find(Key) != Map.end(); }
168 typename MapType::const_iterator Pos = Map.find(Key);
169 return Pos == Map.end()?
Vector.end() :
170 (
Vector.begin() + Pos->second);
174 typename MapType::const_iterator Pos = Map.find(Key);
175 return Pos == Map.end()?
Vector.end() :
176 (
Vector.begin() + Pos->second);
181 typename MapType::iterator Pos = Map.find(
Vector.back().first);
193 typename VectorType::iterator
erase(
typename VectorType::iterator Iterator) {
194 Map.erase(Iterator->first);
195 auto Next =
Vector.erase(Iterator);
201 for (
auto &
I : Map) {
202 assert(
I.second !=
Index &&
"Index was already erased!");
213 auto Iterator =
find(Key);
214 if (Iterator ==
end())
224 template <
class Predicate>
void remove_if(Predicate Pred);
227template <
typename KeyT,
typename ValueT,
typename MapType,
typename VectorType>
228template <
class Function>
241 Map[O->first] = O -
Vector.begin();
251template <
typename KeyT,
typename ValueT,
unsigned N>
253 :
MapVector<KeyT, ValueT, SmallDenseMap<KeyT, unsigned, N>,
254 SmallVector<std::pair<KeyT, ValueT>, N>> {
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
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)
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()
Base class of all SIMD vector types.
This is an optimization pass for GlobalISel generic memory operations.
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.