17#ifndef TRINITYCORE_FLAT_SET_H
18#define TRINITYCORE_FLAT_SET_H
26template <
class Key,
class Compare = std::less<Key>,
class KeyContainer = std::vector<Key>>
30 using iterator =
typename KeyContainer::iterator;
44 return std::binary_search(this->
begin(), this->
end(), value, Compare());
47 auto find(Key
const& value)
const
49 auto compare = Compare();
51 auto itr = std::lower_bound(this->
begin(),
end, value, compare);
52 if (itr !=
end && compare(value, *itr))
58 auto find(Key
const& value)
60 auto compare = Compare();
62 auto itr = std::lower_bound(this->
begin(),
end, value, compare);
63 if (itr !=
end && compare(value, *itr))
69 template <
class... Args>
70 std::pair<iterator, bool>
emplace(Args&&... args)
72 Key newElement(std::forward<Args>(args)...);
73 auto compare = Compare();
75 auto itr = std::lower_bound(this->
begin(),
end, newElement, compare);
76 if (itr !=
end && !compare(newElement, *itr))
77 return { itr,
false };
79 return {
_storage.emplace(itr, std::move(newElement)),
true };
82 std::pair<iterator, bool>
insert(Key
const& key) {
return this->
emplace(key); }
84 std::size_t
erase(Key
const& key)
86 auto itr = this->
find(key);
87 if (itr == this->
end())
auto erase(const_iterator itr)
friend std::strong_ordering operator<=>(FlatSet const &left, FlatSet const &right)=default
bool contains(Key const &value) const
auto find(Key const &value) const
auto find(Key const &value)
std::pair< iterator, bool > emplace(Args &&... args)
typename KeyContainer::iterator iterator
std::pair< iterator, bool > insert(Key const &key)
friend bool operator==(FlatSet const &left, FlatSet const &right)=default
std::size_t erase(Key const &key)
typename KeyContainer::const_iterator const_iterator