24#ifndef TSL_HOPSCOTCH_SC_SET_H
25#define TSL_HOPSCOTCH_SC_SET_H
31#include <initializer_list>
36#include "hopscotch_hash.h"
57 class Hash = std::hash<Key>,
58 class KeyEqual = std::equal_to<Key>,
59 class Compare = std::less<Key>,
60 class Allocator = std::allocator<Key>,
61 unsigned int NeighborhoodSize = 62,
62 bool StoreHash =
false,
73 const key_type& operator()(
const Key& key)
const {
77 key_type& operator()(Key& key) {
83 using overflow_container_type = std::set<Key, Compare, Allocator>;
86 Allocator, NeighborhoodSize,
87 StoreHash, GrowthPolicy,
88 overflow_container_type>;
91 using key_type =
typename ht::key_type;
92 using value_type =
typename ht::value_type;
93 using size_type =
typename ht::size_type;
94 using difference_type =
typename ht::difference_type;
95 using hasher =
typename ht::hasher;
97 using key_compare = Compare;
98 using allocator_type =
typename ht::allocator_type;
99 using reference =
typename ht::reference;
100 using const_reference =
typename ht::const_reference;
101 using pointer =
typename ht::pointer;
102 using const_pointer =
typename ht::const_pointer;
114 const Hash& hash = Hash(),
115 const KeyEqual& equal = KeyEqual(),
116 const Allocator& alloc = Allocator(),
117 const Compare& comp = Compare()) :
118 m_ht(bucket_count, hash, equal, alloc, ht::DEFAULT_MAX_LOAD_FACTOR, comp)
122 hopscotch_sc_set(size_type bucket_count,
123 const Allocator& alloc) : hopscotch_sc_set(bucket_count, Hash(), KeyEqual(), alloc)
127 hopscotch_sc_set(size_type bucket_count,
129 const Allocator& alloc) : hopscotch_sc_set(bucket_count, hash, KeyEqual(), alloc)
133 explicit hopscotch_sc_set(
const Allocator& alloc) : hopscotch_sc_set(ht::DEFAULT_INIT_BUCKETS_SIZE, alloc) {
136 template<
class InputIt>
137 hopscotch_sc_set(InputIt first, InputIt last,
138 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
139 const Hash& hash = Hash(),
140 const KeyEqual& equal = KeyEqual(),
141 const Allocator& alloc = Allocator()) : hopscotch_sc_set(bucket_count, hash, equal, alloc)
146 template<
class InputIt>
147 hopscotch_sc_set(InputIt first, InputIt last,
148 size_type bucket_count,
149 const Allocator& alloc) : hopscotch_sc_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
153 template<
class InputIt>
154 hopscotch_sc_set(InputIt first, InputIt last,
155 size_type bucket_count,
157 const Allocator& alloc) : hopscotch_sc_set(first, last, bucket_count, hash, KeyEqual(), alloc)
161 hopscotch_sc_set(std::initializer_list<value_type> init,
162 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
163 const Hash& hash = Hash(),
164 const KeyEqual& equal = KeyEqual(),
165 const Allocator& alloc = Allocator()) :
166 hopscotch_sc_set(
init.begin(),
init.end(), bucket_count, hash, equal, alloc)
170 hopscotch_sc_set(std::initializer_list<value_type> init,
171 size_type bucket_count,
172 const Allocator& alloc) :
173 hopscotch_sc_set(
init.begin(),
init.end(), bucket_count, Hash(), KeyEqual(), alloc)
177 hopscotch_sc_set(std::initializer_list<value_type> init,
178 size_type bucket_count,
180 const Allocator& alloc) :
181 hopscotch_sc_set(
init.begin(),
init.end(), bucket_count, hash, KeyEqual(), alloc)
186 hopscotch_sc_set& operator=(std::initializer_list<value_type> ilist) {
189 m_ht.reserve(ilist.size());
190 m_ht.insert(ilist.begin(), ilist.end());
195 allocator_type get_allocator()
const {
return m_ht.get_allocator(); }
201 iterator begin() noexcept {
return m_ht.begin(); }
202 const_iterator begin() const noexcept {
return m_ht.begin(); }
203 const_iterator cbegin() const noexcept {
return m_ht.cbegin(); }
205 iterator end() noexcept {
return m_ht.end(); }
206 const_iterator end() const noexcept {
return m_ht.end(); }
207 const_iterator cend() const noexcept {
return m_ht.cend(); }
213 bool empty() const noexcept {
return m_ht.empty(); }
214 size_type size() const noexcept {
return m_ht.size(); }
215 size_type max_size() const noexcept {
return m_ht.max_size(); }
220 void clear() noexcept { m_ht.clear(); }
225 std::pair<iterator, bool> insert(
const value_type& value) {
return m_ht.insert(value); }
226 std::pair<iterator, bool> insert(value_type&& value) {
return m_ht.insert(std::move(value)); }
228 iterator insert(const_iterator hint,
const value_type& value) {
return m_ht.insert(hint, value); }
229 iterator insert(const_iterator hint, value_type&& value) {
return m_ht.insert(hint, std::move(value)); }
231 template<
class InputIt>
232 void insert(InputIt first, InputIt last) { m_ht.insert(first, last); }
233 void insert(std::initializer_list<value_type> ilist) { m_ht.insert(ilist.begin(), ilist.end()); }
244 template<
class... Args>
245 std::pair<iterator, bool>
emplace(Args&&... args) {
return m_ht.emplace(std::forward<Args>(args)...); }
256 template<
class... Args>
258 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
264 iterator erase(iterator pos) {
return m_ht.erase(pos); }
265 iterator erase(const_iterator pos) {
return m_ht.erase(pos); }
266 iterator erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
267 size_type erase(
const key_type& key) {
return m_ht.erase(key); }
273 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
274 return m_ht.erase(key, precalculated_hash);
282 template<
class K,
class KE = KeyEqual,
class CP = Compare,
283 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
284 size_type
erase(
const K& key) {
return m_ht.erase(key); }
292 template<
class K,
class KE = KeyEqual,
class CP = Compare,
293 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
294 size_type
erase(
const K& key, std::size_t precalculated_hash) {
return m_ht.erase(key, precalculated_hash); }
305 size_type count(
const Key& key)
const {
return m_ht.count(key); }
311 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
318 template<
class K,
class KE = KeyEqual,
class CP = Compare,
319 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
320 size_type
count(
const K& key)
const {
return m_ht.count(key); }
328 template<
class K,
class KE = KeyEqual,
class CP = Compare,
329 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
330 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
335 iterator find(
const Key& key) {
return m_ht.find(key); }
341 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
343 const_iterator find(
const Key& key)
const {
return m_ht.find(key); }
348 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
355 template<
class K,
class KE = KeyEqual,
class CP = Compare,
356 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
357 iterator
find(
const K& key) {
return m_ht.find(key); }
365 template<
class K,
class KE = KeyEqual,
class CP = Compare,
366 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
367 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
372 template<
class K,
class KE = KeyEqual,
class CP = Compare,
373 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
374 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
382 template<
class K,
class KE = KeyEqual,
class CP = Compare,
383 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
384 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
389 std::pair<iterator, iterator> equal_range(
const Key& key) {
return m_ht.equal_range(key); }
395 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
396 return m_ht.equal_range(key, precalculated_hash);
399 std::pair<const_iterator, const_iterator> equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
404 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
405 return m_ht.equal_range(key, precalculated_hash);
413 template<
class K,
class KE = KeyEqual,
class CP = Compare,
414 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
415 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
423 template<
class K,
class KE = KeyEqual,
class CP = Compare,
424 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
425 std::pair<iterator, iterator>
equal_range(
const K& key, std::size_t precalculated_hash) {
426 return m_ht.equal_range(key, precalculated_hash);
432 template<
class K,
class KE = KeyEqual,
class CP = Compare,
433 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
434 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
439 template<
class K,
class KE = KeyEqual,
class CP = Compare,
440 typename std::enable_if<has_is_transparent<KE>::value && has_is_transparent<CP>::value>::type* =
nullptr>
441 std::pair<const_iterator, const_iterator>
equal_range(
const K& key, std::size_t precalculated_hash)
const {
442 return m_ht.equal_range(key, precalculated_hash);
451 size_type bucket_count()
const {
return m_ht.bucket_count(); }
452 size_type max_bucket_count()
const {
return m_ht.max_bucket_count(); }
458 float load_factor()
const {
return m_ht.load_factor(); }
459 float max_load_factor()
const {
return m_ht.max_load_factor(); }
460 void max_load_factor(
float ml) { m_ht.max_load_factor(ml); }
462 void rehash(size_type count) { m_ht.rehash(count); }
463 void reserve(size_type count) { m_ht.reserve(count); }
469 hasher hash_function()
const {
return m_ht.hash_function(); }
470 key_equal key_eq()
const {
return m_ht.key_eq(); }
471 key_compare key_comp()
const {
return m_ht.key_comp(); }
482 return m_ht.mutable_iterator(pos);
485 size_type overflow_size() const noexcept {
return m_ht.overflow_size(); }
487 friend bool operator==(
const hopscotch_sc_set& lhs,
const hopscotch_sc_set& rhs) {
488 if(lhs.size() != rhs.size()) {
492 for(
const auto& element_lhs : lhs) {
493 const auto it_element_rhs = rhs.find(element_lhs);
494 if(it_element_rhs == rhs.cend()) {
502 friend bool operator!=(
const hopscotch_sc_set& lhs,
const hopscotch_sc_set& rhs) {
503 return !operator==(lhs, rhs);
506 friend void swap(hopscotch_sc_set& lhs, hopscotch_sc_set& rhs) {
iterator emplace_hint(const_iterator hint, Args &&... args)
std::pair< iterator, iterator > equal_range(const K &key)
size_type erase(const key_type &key, std::size_t precalculated_hash)
size_type erase(const K &key, std::size_t precalculated_hash)
iterator find(const Key &key, std::size_t precalculated_hash)
size_type count(const K &key) const
std::pair< iterator, bool > emplace(Args &&... args)
size_type count(const K &key, std::size_t precalculated_hash) const
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
const_iterator find(const K &key, std::size_t precalculated_hash) const
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
iterator find(const K &key)
const_iterator find(const Key &key, std::size_t precalculated_hash) const
const_iterator find(const K &key) const
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
size_type count(const Key &key, std::size_t precalculated_hash) const
iterator mutable_iterator(const_iterator pos)
size_type erase(const K &key)
iterator find(const K &key, std::size_t precalculated_hash)
OutputIteratorT OffsetT ReductionOpT OuputT init
< [in] The initial value of the reduction
Structure required for the Sph Harmonic amplitude dictionary arguments.