aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-08-15 12:37:47 +0200
committerShauren <shauren.trinity@gmail.com>2025-08-15 12:37:47 +0200
commita27e3a52a0cdfae8cf5cbb787e944f4f76319f26 (patch)
tree9284de765247ccb1a08315a64c9dc5724059bf75 /src/common
parent764b6a5a9336f77f43810022ce449524f6225b53 (diff)
Core/Utils: Added .contains member function to FlatSet
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Containers/FlatSet.h31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/common/Containers/FlatSet.h b/src/common/Containers/FlatSet.h
index 694c994b520..809aa2ad7dc 100644
--- a/src/common/Containers/FlatSet.h
+++ b/src/common/Containers/FlatSet.h
@@ -39,11 +39,17 @@ public:
auto end() { return _storage.end(); }
auto end() const { return _storage.end(); }
+ bool contains(Key const& value) const
+ {
+ return std::binary_search(this->begin(), this->end(), value, Compare());
+ }
+
auto find(Key const& value) const
{
+ auto compare = Compare();
auto end = this->end();
- auto itr = std::lower_bound(this->begin(), end, value, Compare());
- if (itr != end && Compare()(value, *itr))
+ auto itr = std::lower_bound(this->begin(), end, value, compare);
+ if (itr != end && compare(value, *itr))
itr = end;
return itr;
@@ -51,9 +57,10 @@ public:
auto find(Key const& value)
{
+ auto compare = Compare();
auto end = this->end();
- auto itr = std::lower_bound(this->begin(), end, value, Compare());
- if (itr != end && Compare()(value, *itr))
+ auto itr = std::lower_bound(this->begin(), end, value, compare);
+ if (itr != end && compare(value, *itr))
itr = end;
return itr;
@@ -63,9 +70,10 @@ public:
std::pair<iterator, bool> emplace(Args&&... args)
{
Key newElement(std::forward<Args>(args)...);
+ auto compare = Compare();
auto end = this->end();
- auto itr = std::lower_bound(this->begin(), end, newElement, Compare());
- if (itr != end && !Compare()(newElement, *itr))
+ auto itr = std::lower_bound(this->begin(), end, newElement, compare);
+ if (itr != end && !compare(newElement, *itr))
return { itr, false };
return { _storage.emplace(itr, std::move(newElement)), true };
@@ -88,15 +96,8 @@ public:
void shrink_to_fit() { _storage.shrink_to_fit(); }
- friend bool operator==(FlatSet const& left, FlatSet const& right)
- {
- return left._storage == right._storage;
- }
-
- friend bool operator!=(FlatSet const& left, FlatSet const& right)
- {
- return !(left == right);
- }
+ friend std::strong_ordering operator<=>(FlatSet const& left, FlatSet const& right) = default;
+ friend bool operator==(FlatSet const& left, FlatSet const& right) = default;
private:
KeyContainer _storage;