[llvm] r219240 - Add size_t MapVector::erase(KeyT) similar to the one in std::map.

David Blaikie dblaikie at gmail.com
Tue Oct 7 15:48:58 PDT 2014


On Tue, Oct 7, 2014 at 3:44 PM, Kaelyn Takata <rikka at google.com> wrote:

>
>
> On Tue, Oct 7, 2014 at 2:37 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>>
>>
>> On Tue, Oct 7, 2014 at 2:15 PM, Kaelyn Takata <rikka at google.com> wrote:
>>
>>> Author: rikka
>>> Date: Tue Oct  7 16:15:51 2014
>>> New Revision: 219240
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=219240&view=rev
>>> Log:
>>> Add size_t MapVector::erase(KeyT) similar to the one in std::map.
>>>
>>> Modified:
>>>     llvm/trunk/include/llvm/ADT/MapVector.h
>>>     llvm/trunk/unittests/ADT/MapVectorTest.cpp
>>>
>>> Modified: llvm/trunk/include/llvm/ADT/MapVector.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/MapVector.h?rev=219240&r1=219239&r2=219240&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/ADT/MapVector.h (original)
>>> +++ llvm/trunk/include/llvm/ADT/MapVector.h Tue Oct  7 16:15:51 2014
>>> @@ -147,6 +147,17 @@ public:
>>>      return Next;
>>>    }
>>>
>>> +  /// \brief Remove all elements with the key value Key.
>>> +  ///
>>> +  /// Returns the number of elements removed.
>>> +  size_type erase(const KeyT &Key) {
>>> +    auto Iterator = find(Key);
>>> +    if (Iterator == end())
>>> +      return 0;
>>> +    erase(Iterator);
>>> +    return 1;
>>> +  }
>>> +
>>>    /// \brief Remove the elements that match the predicate.
>>>    ///
>>>    /// Erase all elements that match \c Pred in a single pass.  Takes
>>> linear
>>>
>>> Modified: llvm/trunk/unittests/ADT/MapVectorTest.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/MapVectorTest.cpp?rev=219240&r1=219239&r2=219240&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/unittests/ADT/MapVectorTest.cpp (original)
>>> +++ llvm/trunk/unittests/ADT/MapVectorTest.cpp Tue Oct  7 16:15:51 2014
>>> @@ -67,6 +67,11 @@ TEST(MapVectorTest, erase) {
>>>    ASSERT_EQ(MV.find(1), MV.end());
>>>    ASSERT_EQ(MV[3], 4);
>>>    ASSERT_EQ(MV[5], 6);
>>> +
>>> +  MV.erase(3);
>>> +  ASSERT_EQ(MV.size(), 1u);
>>> +  ASSERT_EQ(MV.find(3), MV.end());
>>> +  ASSERT_EQ(MV[5], 6);
>>>
>>
>> Maybe a test for the return value? And a negative test (when the element
>> isn't in the container)
>>
>
> Good point. How about:
>
> --- a/unittests/ADT/MapVectorTest.cpp
> +++ b/unittests/ADT/MapVectorTest.cpp
> @@ -68,10 +68,13 @@ TEST(MapVectorTest, erase) {
>    ASSERT_EQ(MV[3], 4);
>    ASSERT_EQ(MV[5], 6);
>
> -  MV.erase(3);
> +  ASSERT_EQ(MV.erase(3), 1u);
>    ASSERT_EQ(MV.size(), 1u);
>    ASSERT_EQ(MV.find(3), MV.end());
>    ASSERT_EQ(MV[5], 6);
> +
> +  ASSERT_EQ(MV.erase(79), 0u);
> +  ASSERT_EQ(MV.size(), 1u);
>

Looks good to me - thanks!


>  }
>
>  TEST(MapVectorTest, remove_if) {
>
>
>>
>>>  }
>>>
>>>  TEST(MapVectorTest, remove_if) {
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141007/57cdd9e6/attachment.html>


More information about the llvm-commits mailing list