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:
parent
294e3ec1ba
commit
479337797c
@ -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.
|
||||
///
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user