llvm.org GIT mirror llvm / a17e361
[ADT] Enable set_difference() to be used on StringSet Summary: Re-land r362766 after it was reverted in r362823. Reviewers: jhenderson, dsanders, aaron.ballman, MatzeB, lhames, dblaikie Reviewed By: dblaikie Subscribers: smeenai, mgrang, mgorny, dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62369 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362835 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Pozulp a month ago
5 changed file(s) with 56 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
358358 return find(Key) == end() ? 0 : 1;
359359 }
360360
361 template
362 size_type count(const StringMapEntry &MapEntry) const {
363 return count(MapEntry.getKey());
364 }
365
361366 /// insert - Insert the specified key/value pair into the map. If the key
362367 /// already exists in the map, return false and ignore the request, otherwise
363368 /// insert it and return true.
4444 for (auto It = Begin; It != End; ++It)
4545 base::insert(std::make_pair(*It, '\0'));
4646 }
47
48 template
49 std::pair
50 insert(const StringMapEntry &MapEntry) {
51 return insert(MapEntry.getKey());
52 }
4753 };
4854
4955 } // end namespace llvm
6464 StringExtrasTest.cpp
6565 StringMapTest.cpp
6666 StringRefTest.cpp
67 StringSetTest.cpp
6768 StringSwitchTest.cpp
6869 TinyPtrVectorTest.cpp
6970 TripleTest.cpp
66 //===----------------------------------------------------------------------===//
77
88 #include "llvm/ADT/StringMap.h"
9 #include "llvm/ADT/StringSet.h"
109 #include "llvm/ADT/Twine.h"
1110 #include "llvm/Support/DataTypes.h"
1211 #include "gtest/gtest.h"
277276 Map["D"] = 3;
278277
279278 auto Keys = to_vector<4>(Map.keys());
280 llvm::sort(Keys);
281
282 SmallVector Expected = {"A", "B", "C", "D"};
283 EXPECT_EQ(Expected, Keys);
284 }
285
286 TEST_F(StringMapTest, IterSetKeys) {
287 StringSet<> Set;
288 Set.insert("A");
289 Set.insert("B");
290 Set.insert("C");
291 Set.insert("D");
292
293 auto Keys = to_vector<4>(Set.keys());
294279 llvm::sort(Keys);
295280
296281 SmallVector Expected = {"A", "B", "C", "D"};
0 //===- llvm/unittest/ADT/StringSetTest.cpp - StringSet unit tests ----------===//
1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/ADT/StringSet.h"
9 #include "gtest/gtest.h"
10 using namespace llvm;
11
12 namespace {
13
14 // Test fixture
15 class StringSetTest : public testing::Test {};
16
17 TEST_F(StringSetTest, IterSetKeys) {
18 StringSet<> Set;
19 Set.insert("A");
20 Set.insert("B");
21 Set.insert("C");
22 Set.insert("D");
23
24 auto Keys = to_vector<4>(Set.keys());
25 llvm::sort(Keys);
26
27 SmallVector Expected = {"A", "B", "C", "D"};
28 EXPECT_EQ(Expected, Keys);
29 }
30
31 TEST_F(StringSetTest, InsertAndCountStringMapEntry) {
32 // Test insert(StringMapEntry) and count(StringMapEntry)
33 // which are required for set_difference(StringSet, StringSet).
34 StringSet<> Set;
35 StringMapEntry *Element = StringMapEntry::Create("A");
36 Set.insert(*Element);
37 size_t Count = Set.count(*Element);
38 size_t Expected = 1;
39 EXPECT_EQ(Expected, Count);
40 Element->Destroy();
41 }
42
43 } // end anonymous namespace