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