@@ -51,6 +51,9 @@ class BlotMapVector {
51
51
iterator_range<iterator> getItems () {
52
52
return swift::make_range (begin (), end ());
53
53
}
54
+ iterator_range<const_iterator> getItems () const {
55
+ return swift::make_range (begin (), end ());
56
+ }
54
57
55
58
ValueT &operator [](const KeyT &Arg) {
56
59
auto Pair = Map.insert (std::make_pair (Arg, size_t (0 )));
@@ -85,27 +88,34 @@ class BlotMapVector {
85
88
}
86
89
87
90
const_iterator find (const KeyT &Key) const {
88
- return const_cast <BlotMapVector &>(*this )-> find (Key);
91
+ return const_cast <BlotMapVector &>(*this ). find (Key);
89
92
}
90
93
91
- // / This is similar to erase, but instead of removing the element from the
92
- // / vector, it just zeros out the key in the vector. This leaves iterators
93
- // / intact, but clients must be prepared for zeroed-out keys when iterating.
94
- void erase (const KeyT &Key) { blot (Key); }
95
-
96
- // / This is similar to erase, but instead of removing the element from the
97
- // / vector, it just zeros out the key in the vector. This leaves iterators
94
+ // / Eliminate the element at `Key`. Instead of removing the element from the
95
+ // / vector, just zero out the key in the vector. This leaves iterators
98
96
// / intact, but clients must be prepared for zeroed-out keys when iterating.
97
+ // /
98
+ // / Return true if the element was erased.
99
+ bool erase (const KeyT &Key) { return blot (Key); }
100
+
101
+ // / Eliminate the element at the given iterator. Instead of removing the
102
+ // / element from the vector, just zero out the key in the vector. This
103
+ // / leaves iterators intact, but clients must be prepared for zeroed-out
104
+ // / keys when iterating.
99
105
void erase (iterator I) { erase ((*I)->first ); }
100
106
101
- // / This is similar to erase, but instead of removing the element from the
107
+ // / Eliminate the element at `Key`. Instead of removing the element from the
102
108
// / vector, it just zeros out the key in the vector. This leaves iterators
103
109
// / intact, but clients must be prepared for zeroed-out keys when iterating.
104
- void blot (const KeyT &Key) {
110
+ // /
111
+ // / Return true if the element was found and erased.
112
+ bool blot (const KeyT &Key) {
105
113
typename MapT::iterator It = Map.find (Key);
106
- if (It == Map.end ()) return ;
114
+ if (It == Map.end ())
115
+ return false ;
107
116
Vector[It->second ] = None;
108
117
Map.erase (It);
118
+ return true ;
109
119
}
110
120
111
121
void clear () {
0 commit comments