17 #ifndef LLVM_ADT_MAPVECTOR_H
18 #define LLVM_ADT_MAPVECTOR_H
30 template<
typename KeyT,
typename ValueT,
32 typename VectorType = std::vector<std::pair<KeyT, ValueT> > >
34 typedef typename VectorType::size_type SizeType;
40 typedef typename VectorType::iterator
iterator;
48 return Vector.begin();
52 return Vector.begin();
64 return Vector.empty();
67 std::pair<KeyT, ValueT> &
front() {
return Vector.front(); }
68 const std::pair<KeyT, ValueT> &
front()
const {
return Vector.front(); }
69 std::pair<KeyT, ValueT> &
back() {
return Vector.back(); }
70 const std::pair<KeyT, ValueT> &
back()
const {
return Vector.back(); }
78 std::pair<KeyT, unsigned> Pair = std::make_pair(Key, 0);
79 std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
80 unsigned &
I = Result.first->second;
82 Vector.push_back(std::make_pair(Key, ValueT()));
83 I = Vector.size() - 1;
85 return Vector[
I].second;
89 typename MapType::const_iterator Pos = Map.find(Key);
90 return Pos == Map.end()? ValueT() : Vector[Pos->second].second;
93 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
94 std::pair<KeyT, unsigned> Pair = std::make_pair(KV.first, 0);
95 std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
96 unsigned &
I = Result.first->second;
98 Vector.push_back(std::make_pair(KV.first, KV.second));
99 I = Vector.size() - 1;
102 return std::make_pair(
begin() + I,
false);
106 typename MapType::const_iterator Pos = Map.find(Key);
107 return Pos == Map.end()? 0 : 1;
111 typename MapType::const_iterator Pos = Map.find(Key);
112 return Pos == Map.end()? Vector.end() :
113 (Vector.begin() + Pos->second);
117 typename MapType::const_iterator Pos = Map.find(Key);
118 return Pos == Map.end()? Vector.end() :
119 (Vector.begin() + Pos->second);
124 typename MapType::iterator Pos = Map.find(Vector.back().first);
const_iterator begin() const
VectorType::iterator iterator
const std::pair< KeyT, ValueT > & back() const
void pop_back()
Remove the last element from the vector.
const_iterator end() const
std::pair< KeyT, ValueT > & back()
ValueT & operator[](const KeyT &Key)
const_iterator find(const KeyT &Key) const
iterator find(const KeyT &Key)
ValueT lookup(const KeyT &Key) const
const std::pair< KeyT, ValueT > & front() const
unsigned count(const KeyT &Key) const
VectorType::const_iterator const_iterator
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
std::pair< KeyT, ValueT > & front()
ItTy prior(ItTy it, Dist n)