[llvm] r175449 - Add front/back/erase to MapVector.

Douglas Gregor dgregor at apple.com
Tue Feb 19 10:46:03 PST 2013


On Feb 18, 2013, at 9:45 PM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Douglas Gregor wrote:
>> Author: dgregor
>> Date: Mon Feb 18 10:03:04 2013
>> New Revision: 175449
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=175449&view=rev
>> Log:
>> Add front/back/erase to MapVector.
>> 
>> Modified:
>>     llvm/trunk/include/llvm/ADT/MapVector.h
>> 
>> Modified: llvm/trunk/include/llvm/ADT/MapVector.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/MapVector.h?rev=175449&r1=175448&r2=175449&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ADT/MapVector.h (original)
>> +++ llvm/trunk/include/llvm/ADT/MapVector.h Mon Feb 18 10:03:04 2013
>> @@ -64,6 +64,11 @@ public:
>>      return Vector.empty();
>>    }
>> 
>> +  std::pair<KeyT, ValueT>        &front()       { return Vector.front(); }
>> +  const std::pair<KeyT, ValueT>  &front() const { return Vector.front(); }
>> +  std::pair<KeyT, ValueT>        &back()        { return Vector.back(); }
>> +  const std::pair<KeyT, ValueT>  &back()  const { return Vector.back(); }
>> +
>>    void clear() {
>>      Map.clear();
>>      Vector.clear();
>> @@ -113,6 +118,16 @@ public:
>>      return Pos == Map.end()? Vector.end() :
>>                              (Vector.begin() + Pos->second);
>>    }
>> +
>> +  /// \brief Erase entry with the given key.
>> +  void erase(const KeyT&key) {
>> +    typename MapType::iterator Pos = Map.find(key);
>> +    if (Pos == Map.end())
>> +      return;
>> +
>> +    Vector.erase(Vector.begin() + Pos->second);
> 
> Since the map's values are indices into the vector by element number (ie., "the 12th element in the vector"), if you delete from the middle of the vector all the map entries which point past it are now wrong.
> 
> Please revert this part of the change, or fix it either by leaving behind a tombstone in the vector or by doing a scan through the entire map to update any out of date entries (and probably rename it the same name with a different memory/performance guarantee will be deceptive).

This should simply be pop_back(); implemented and unit tested in LLVM r175538..

	- Doug



More information about the llvm-commits mailing list