1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-21 18:22:53 +01:00

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

Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
This commit is contained in:
David Blaikie 2020-07-17 10:42:23 -07:00
parent fe6846924a
commit 294e3ec1ba
2 changed files with 32 additions and 0 deletions

View File

@ -232,6 +232,13 @@ public:
return {Set.end()};
}
/// Check if the SmallSet contains the given element.
bool contains(const T &V) const {
if (isSmall())
return vfind(V) != Vector.end();
return Set.find(V) != Set.end();
}
private:
bool isSmall() const { return Set.empty(); }

View File

@ -167,3 +167,28 @@ TEST(SmallSetTest, EqualityComparisonTest) {
EXPECT_NE(s1small, s4large);
EXPECT_NE(s4large, s3large);
}
TEST(SmallSetTest, Contains) {
SmallSet<int, 2> Set;
EXPECT_FALSE(Set.contains(0));
EXPECT_FALSE(Set.contains(1));
Set.insert(0);
Set.insert(1);
EXPECT_TRUE(Set.contains(0));
EXPECT_TRUE(Set.contains(1));
Set.insert(1);
EXPECT_TRUE(Set.contains(0));
EXPECT_TRUE(Set.contains(1));
Set.erase(1);
EXPECT_TRUE(Set.contains(0));
EXPECT_FALSE(Set.contains(1));
Set.insert(1);
Set.insert(2);
EXPECT_TRUE(Set.contains(0));
EXPECT_TRUE(Set.contains(1));
EXPECT_TRUE(Set.contains(2));
}