Skip to content

Commit 814f051

Browse files
author
git apple-llvm automerger
committed
Merge commit 'de442d10ac33' from apple/master into swift/master-next
2 parents ee06218 + de442d1 commit 814f051

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

llvm/include/llvm/ADT/SparseSet.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,15 @@ class SparseSet {
229229
return const_cast<SparseSet*>(this)->findIndex(KeyIndexOf(Key));
230230
}
231231

232+
/// Check if the set contains the given \c Key.
233+
///
234+
/// @param Key A valid key to find.
235+
bool contains(const KeyT &Key) const { return find(Key) == end() ? 0 : 1; }
236+
232237
/// count - Returns 1 if this set contains an element identified by Key,
233238
/// 0 otherwise.
234239
///
235-
size_type count(const KeyT &Key) const {
236-
return find(Key) == end() ? 0 : 1;
237-
}
240+
size_type count(const KeyT &Key) const { return contains(Key) ? 1 : 0; }
238241

239242
/// insert - Attempts to insert a new element.
240243
///

llvm/unittests/ADT/SparseSetTest.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ TEST(SparseSetTest, EmptySet) {
2525
Set.setUniverse(10);
2626

2727
// Lookups on empty set.
28-
EXPECT_TRUE(Set.find(0) == Set.end());
29-
EXPECT_TRUE(Set.find(9) == Set.end());
28+
EXPECT_FALSE(Set.contains(0));
29+
EXPECT_FALSE(Set.contains(9));
3030

3131
// Same thing on a const reference.
3232
const USet &CSet = Set;
3333
EXPECT_TRUE(CSet.empty());
3434
EXPECT_TRUE(CSet.begin() == CSet.end());
3535
EXPECT_EQ(0u, CSet.size());
36-
EXPECT_TRUE(CSet.find(0) == CSet.end());
36+
EXPECT_FALSE(CSet.contains(0));
3737
USet::const_iterator I = CSet.find(5);
3838
EXPECT_TRUE(I == CSet.end());
3939
}
@@ -51,8 +51,9 @@ TEST(SparseSetTest, SingleEntrySet) {
5151
EXPECT_TRUE(Set.begin() + 1 == Set.end());
5252
EXPECT_EQ(1u, Set.size());
5353

54-
EXPECT_TRUE(Set.find(0) == Set.end());
55-
EXPECT_TRUE(Set.find(9) == Set.end());
54+
EXPECT_FALSE(Set.contains(0));
55+
EXPECT_FALSE(Set.contains(9));
56+
EXPECT_TRUE(Set.contains(5));
5657

5758
EXPECT_FALSE(Set.count(0));
5859
EXPECT_TRUE(Set.count(5));
@@ -71,6 +72,7 @@ TEST(SparseSetTest, SingleEntrySet) {
7172
USet::iterator I = Set.find(5);
7273
EXPECT_TRUE(I == Set.begin());
7374
I = Set.erase(I);
75+
EXPECT_FALSE(Set.contains(5));
7476
EXPECT_TRUE(I == Set.end());
7577
EXPECT_TRUE(Set.empty());
7678
}

0 commit comments

Comments
 (0)