1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[llvm] Add contains(KeyType) -> bool methods to SparseSet

Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
This commit is contained in:
David Blaikie 2020-07-17 10:43:01 -07:00
parent 294e3ec1ba
commit 479337797c
2 changed files with 13 additions and 8 deletions

View File

@ -229,12 +229,15 @@ public:
return const_cast<SparseSet*>(this)->findIndex(KeyIndexOf(Key));
}
/// Check if the set contains the given \c Key.
///
/// @param Key A valid key to find.
bool contains(const KeyT &Key) const { return find(Key) == end() ? 0 : 1; }
/// count - Returns 1 if this set contains an element identified by Key,
/// 0 otherwise.
///
size_type count(const KeyT &Key) const {
return find(Key) == end() ? 0 : 1;
}
size_type count(const KeyT &Key) const { return contains(Key) ? 1 : 0; }
/// insert - Attempts to insert a new element.
///

View File

@ -25,15 +25,15 @@ TEST(SparseSetTest, EmptySet) {
Set.setUniverse(10);
// Lookups on empty set.
EXPECT_TRUE(Set.find(0) == Set.end());
EXPECT_TRUE(Set.find(9) == Set.end());
EXPECT_FALSE(Set.contains(0));
EXPECT_FALSE(Set.contains(9));
// Same thing on a const reference.
const USet &CSet = Set;
EXPECT_TRUE(CSet.empty());
EXPECT_TRUE(CSet.begin() == CSet.end());
EXPECT_EQ(0u, CSet.size());
EXPECT_TRUE(CSet.find(0) == CSet.end());
EXPECT_FALSE(CSet.contains(0));
USet::const_iterator I = CSet.find(5);
EXPECT_TRUE(I == CSet.end());
}
@ -51,8 +51,9 @@ TEST(SparseSetTest, SingleEntrySet) {
EXPECT_TRUE(Set.begin() + 1 == Set.end());
EXPECT_EQ(1u, Set.size());
EXPECT_TRUE(Set.find(0) == Set.end());
EXPECT_TRUE(Set.find(9) == Set.end());
EXPECT_FALSE(Set.contains(0));
EXPECT_FALSE(Set.contains(9));
EXPECT_TRUE(Set.contains(5));
EXPECT_FALSE(Set.count(0));
EXPECT_TRUE(Set.count(5));
@ -71,6 +72,7 @@ TEST(SparseSetTest, SingleEntrySet) {
USet::iterator I = Set.find(5);
EXPECT_TRUE(I == Set.begin());
I = Set.erase(I);
EXPECT_FALSE(Set.contains(5));
EXPECT_TRUE(I == Set.end());
EXPECT_TRUE(Set.empty());
}