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

Nick Lewycky nicholas at mxc.ca
Mon Feb 18 21:45:13 PST 2013


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).

Nick

PS. unit tests :)

> +    Map.erase(Pos);
> +  }
>   };
>
>   }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list