24#ifndef TSL_HOPSCOTCH_SET_H
25#define TSL_HOPSCOTCH_SET_H
31#include <initializer_list>
36#include "hopscotch_hash.h"
72 class Hash = std::hash<Key>,
73 class KeyEqual = std::equal_to<Key>,
74 class Allocator = std::allocator<Key>,
75 unsigned int NeighborhoodSize = 62,
76 bool StoreHash =
false,
87 const key_type& operator()(
const Key& key)
const {
91 key_type& operator()(Key& key) {
97 using overflow_container_type = std::list<Key, Allocator>;
100 Allocator, NeighborhoodSize,
101 StoreHash, GrowthPolicy,
102 overflow_container_type>;
105 using key_type =
typename ht::key_type;
106 using value_type =
typename ht::value_type;
107 using size_type =
typename ht::size_type;
108 using difference_type =
typename ht::difference_type;
109 using hasher =
typename ht::hasher;
110 using key_equal =
typename ht::key_equal;
111 using allocator_type =
typename ht::allocator_type;
112 using reference =
typename ht::reference;
113 using const_reference =
typename ht::const_reference;
114 using pointer =
typename ht::pointer;
115 using const_pointer =
typename ht::const_pointer;
127 const Hash& hash = Hash(),
128 const KeyEqual& equal = KeyEqual(),
129 const Allocator& alloc = Allocator()) :
130 m_ht(bucket_count, hash, equal, alloc, ht::DEFAULT_MAX_LOAD_FACTOR)
134 hopscotch_set(size_type bucket_count,
135 const Allocator& alloc) : hopscotch_set(bucket_count, Hash(), KeyEqual(), alloc)
139 hopscotch_set(size_type bucket_count,
141 const Allocator& alloc) : hopscotch_set(bucket_count, hash, KeyEqual(), alloc)
145 explicit hopscotch_set(
const Allocator& alloc) : hopscotch_set(ht::DEFAULT_INIT_BUCKETS_SIZE, alloc) {
148 template<
class InputIt>
149 hopscotch_set(InputIt first, InputIt last,
150 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
151 const Hash& hash = Hash(),
152 const KeyEqual& equal = KeyEqual(),
153 const Allocator& alloc = Allocator()) : hopscotch_set(bucket_count, hash, equal, alloc)
158 template<
class InputIt>
159 hopscotch_set(InputIt first, InputIt last,
160 size_type bucket_count,
161 const Allocator& alloc) : hopscotch_set(first, last, bucket_count, Hash(), KeyEqual(), alloc)
165 template<
class InputIt>
166 hopscotch_set(InputIt first, InputIt last,
167 size_type bucket_count,
169 const Allocator& alloc) : hopscotch_set(first, last, bucket_count, hash, KeyEqual(), alloc)
173 hopscotch_set(std::initializer_list<value_type> init,
174 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
175 const Hash& hash = Hash(),
176 const KeyEqual& equal = KeyEqual(),
177 const Allocator& alloc = Allocator()) :
178 hopscotch_set(
init.begin(),
init.end(), bucket_count, hash, equal, alloc)
182 hopscotch_set(std::initializer_list<value_type> init,
183 size_type bucket_count,
184 const Allocator& alloc) :
185 hopscotch_set(
init.begin(),
init.end(), bucket_count, Hash(), KeyEqual(), alloc)
189 hopscotch_set(std::initializer_list<value_type> init,
190 size_type bucket_count,
192 const Allocator& alloc) :
193 hopscotch_set(
init.begin(),
init.end(), bucket_count, hash, KeyEqual(), alloc)
198 hopscotch_set& operator=(std::initializer_list<value_type> ilist) {
201 m_ht.reserve(ilist.size());
202 m_ht.insert(ilist.begin(), ilist.end());
207 allocator_type get_allocator()
const {
return m_ht.get_allocator(); }
213 iterator begin() noexcept {
return m_ht.begin(); }
214 const_iterator begin() const noexcept {
return m_ht.begin(); }
215 const_iterator cbegin() const noexcept {
return m_ht.cbegin(); }
217 iterator end() noexcept {
return m_ht.end(); }
218 const_iterator end() const noexcept {
return m_ht.end(); }
219 const_iterator cend() const noexcept {
return m_ht.cend(); }
225 bool empty() const noexcept {
return m_ht.empty(); }
226 size_type size() const noexcept {
return m_ht.size(); }
227 size_type max_size() const noexcept {
return m_ht.max_size(); }
232 void clear() noexcept { m_ht.clear(); }
237 std::pair<iterator, bool> insert(
const value_type& value) {
return m_ht.insert(value); }
238 std::pair<iterator, bool> insert(value_type&& value) {
return m_ht.insert(std::move(value)); }
240 iterator insert(const_iterator hint,
const value_type& value) {
return m_ht.insert(hint, value); }
241 iterator insert(const_iterator hint, value_type&& value) {
return m_ht.insert(hint, std::move(value)); }
243 template<
class InputIt>
244 void insert(InputIt first, InputIt last) { m_ht.insert(first, last); }
245 void insert(std::initializer_list<value_type> ilist) { m_ht.insert(ilist.begin(), ilist.end()); }
256 template<
class... Args>
257 std::pair<iterator, bool>
emplace(Args&&... args) {
return m_ht.emplace(std::forward<Args>(args)...); }
268 template<
class... Args>
270 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
276 iterator erase(iterator pos) {
return m_ht.erase(pos); }
277 iterator erase(const_iterator pos) {
return m_ht.erase(pos); }
278 iterator erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
279 size_type erase(
const key_type& key) {
return m_ht.erase(key); }
285 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
286 return m_ht.erase(key, precalculated_hash);
293 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
294 size_type
erase(
const K& key) {
return m_ht.erase(key); }
302 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
303 size_type
erase(
const K& key, std::size_t precalculated_hash) {
304 return m_ht.erase(key, precalculated_hash);
316 size_type count(
const Key& key)
const {
return m_ht.count(key); }
322 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
328 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
329 size_type
count(
const K& key)
const {
return m_ht.count(key); }
337 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
338 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
343 iterator find(
const Key& key) {
return m_ht.find(key); }
349 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
351 const_iterator find(
const Key& key)
const {
return m_ht.find(key); }
356 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
362 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
363 iterator
find(
const K& key) {
return m_ht.find(key); }
371 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
372 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
377 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
378 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
386 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
387 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.find(key, precalculated_hash); }
392 std::pair<iterator, iterator> equal_range(
const Key& key) {
return m_ht.equal_range(key); }
398 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
399 return m_ht.equal_range(key, precalculated_hash);
402 std::pair<const_iterator, const_iterator> equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
407 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
408 return m_ht.equal_range(key, precalculated_hash);
415 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
416 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
424 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::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, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
433 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
438 template<class K, class KE = KeyEqual, typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
439 std::pair<const_iterator, const_iterator>
equal_range(
const K& key, std::size_t precalculated_hash)
const {
440 return m_ht.equal_range(key, precalculated_hash);
449 size_type bucket_count()
const {
return m_ht.bucket_count(); }
450 size_type max_bucket_count()
const {
return m_ht.max_bucket_count(); }
456 float load_factor()
const {
return m_ht.load_factor(); }
457 float max_load_factor()
const {
return m_ht.max_load_factor(); }
458 void max_load_factor(
float ml) { m_ht.max_load_factor(ml); }
460 void rehash(size_type count) { m_ht.rehash(count); }
461 void reserve(size_type count) { m_ht.reserve(count); }
467 hasher hash_function()
const {
return m_ht.hash_function(); }
468 key_equal key_eq()
const {
return m_ht.key_eq(); }
479 return m_ht.mutable_iterator(pos);
482 size_type overflow_size() const noexcept {
return m_ht.overflow_size(); }
484 friend bool operator==(
const hopscotch_set& lhs,
const hopscotch_set& rhs) {
485 if(lhs.size() != rhs.size()) {
489 for(
const auto& element_lhs : lhs) {
490 const auto it_element_rhs = rhs.find(element_lhs);
491 if(it_element_rhs == rhs.cend()) {
499 friend bool operator!=(
const hopscotch_set& lhs,
const hopscotch_set& rhs) {
500 return !operator==(lhs, rhs);
503 friend void swap(hopscotch_set& lhs, hopscotch_set& rhs) {
iterator find(const K &key, std::size_t precalculated_hash)
std::pair< iterator, bool > emplace(Args &&... args)
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
iterator mutable_iterator(const_iterator pos)
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
iterator find(const K &key)
iterator find(const Key &key, std::size_t precalculated_hash)
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
const_iterator find(const K &key) const
std::pair< iterator, iterator > equal_range(const K &key)
const_iterator find(const Key &key, std::size_t precalculated_hash) const
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
size_type count(const K &key, std::size_t precalculated_hash) const
size_type erase(const K &key, std::size_t precalculated_hash)
size_type count(const K &key) const
const_iterator find(const K &key, std::size_t precalculated_hash) const
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
size_type erase(const key_type &key, std::size_t precalculated_hash)
size_type erase(const K &key)
iterator emplace_hint(const_iterator hint, Args &&... args)
OutputIteratorT OffsetT ReductionOpT OuputT init
< [in] The initial value of the reduction
Structure required for the Sph Harmonic amplitude dictionary arguments.