EnTT: src/entt/container/dense_set.hpp Source File

EnTT 3.15.0

Loading...
Searching...
No Matches
dense_set.hpp
1#ifndef ENTT_CONTAINER_DENSE_SET_HPP
2#define ENTT_CONTAINER_DENSE_SET_HPP
3
4#include <cmath>
5#include <cstddef>
6#include <functional>
7#include <iterator>
8#include <limits>
9#include <memory>
10#include <tuple>
11#include <type_traits>
12#include <utility>
13#include <vector>
14#include "../config/config.h"
15#include "../core/bit.hpp"
16#include "../core/compressed_pair.hpp"
17#include "../core/type_traits.hpp"
18#include "fwd.hpp"
19
20namespace entt {
21
23namespace internal {
24
25template<typename It>
26class dense_set_iterator final {
27 template<typename>
28 friend class dense_set_iterator;
29
30public:
31 using value_type = typename It::value_type::second_type;
32 using pointer = const value_type *;
33 using reference = const value_type &;
34 using difference_type = std::ptrdiff_t;
35 using iterator_category = std::random_access_iterator_tag;
36
37 constexpr dense_set_iterator() noexcept
38 : it{} {}
39
40 constexpr dense_set_iterator(const It iter) noexcept
41 : it{iter} {}
42
43 template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
44 constexpr dense_set_iterator(const dense_set_iterator<Other> &other) noexcept
45 : it{other.it} {}
46
47 constexpr dense_set_iterator &operator++() noexcept {
48 return ++it, *this;
49 }
50
51 constexpr dense_set_iterator operator++(int) noexcept {
52 const dense_set_iterator orig = *this;
53 return ++(*this), orig;
54 }
55
56 constexpr dense_set_iterator &operator--() noexcept {
57 return --it, *this;
58 }
59
60 constexpr dense_set_iterator operator--(int) noexcept {
61 const dense_set_iterator orig = *this;
62 return operator--(), orig;
63 }
64
65 constexpr dense_set_iterator &operator+=(const difference_type value) noexcept {
66 it += value;
67 return *this;
68 }
69
70 constexpr dense_set_iterator operator+(const difference_type value) const noexcept {
71 dense_set_iterator copy = *this;
72 return (copy += value);
73 }
74
75 constexpr dense_set_iterator &operator-=(const difference_type value) noexcept {
76 return (*this += -value);
77 }
78
79 constexpr dense_set_iterator operator-(const difference_type value) const noexcept {
80 return (*this + -value);
81 }
82
83 [[nodiscard]] constexpr reference operator[](const difference_type value) const noexcept {
84 return it[value].second;
85 }
86
87 [[nodiscard]] constexpr pointer operator->() const noexcept {
88 return std::addressof(operator[](0));
89 }
90
91 [[nodiscard]] constexpr reference operator*() const noexcept {
92 return operator[](0);
93 }
94
95 template<typename Lhs, typename Rhs>
96 friend constexpr std::ptrdiff_t operator-(const dense_set_iterator<Lhs> &, const dense_set_iterator<Rhs> &) noexcept;
97
98 template<typename Lhs, typename Rhs>
99 friend constexpr bool operator==(const dense_set_iterator<Lhs> &, const dense_set_iterator<Rhs> &) noexcept;
100
101 template<typename Lhs, typename Rhs>
102 friend constexpr bool operator<(const dense_set_iterator<Lhs> &, const dense_set_iterator<Rhs> &) noexcept;
103
104private:
105 It it;
106};
107
108template<typename Lhs, typename Rhs>
109[[nodiscard]] constexpr std::ptrdiff_t operator-(const dense_set_iterator<Lhs> &lhs, const dense_set_iterator<Rhs> &rhs) noexcept {
110 return lhs.it - rhs.it;
111}
112
113template<typename Lhs, typename Rhs>
114[[nodiscard]] constexpr bool operator==(const dense_set_iterator<Lhs> &lhs, const dense_set_iterator<Rhs> &rhs) noexcept {
115 return lhs.it == rhs.it;
116}
117
118template<typename Lhs, typename Rhs>
119[[nodiscard]] constexpr bool operator!=(const dense_set_iterator<Lhs> &lhs, const dense_set_iterator<Rhs> &rhs) noexcept {
120 return !(lhs == rhs);
121}
122
123template<typename Lhs, typename Rhs>
124[[nodiscard]] constexpr bool operator<(const dense_set_iterator<Lhs> &lhs, const dense_set_iterator<Rhs> &rhs) noexcept {
125 return lhs.it < rhs.it;
126}
127
128template<typename Lhs, typename Rhs>
129[[nodiscard]] constexpr bool operator>(const dense_set_iterator<Lhs> &lhs, const dense_set_iterator<Rhs> &rhs) noexcept {
130 return rhs < lhs;
131}
132
133template<typename Lhs, typename Rhs>
134[[nodiscard]] constexpr bool operator<=(const dense_set_iterator<Lhs> &lhs, const dense_set_iterator<Rhs> &rhs) noexcept {
135 return !(lhs > rhs);
136}
137
138template<typename Lhs, typename Rhs>
139[[nodiscard]] constexpr bool operator>=(const dense_set_iterator<Lhs> &lhs, const dense_set_iterator<Rhs> &rhs) noexcept {
140 return !(lhs < rhs);
141}
142
143template<typename It>
144class dense_set_local_iterator final {
145 template<typename>
146 friend class dense_set_local_iterator;
147
148public:
149 using value_type = typename It::value_type::second_type;
150 using pointer = const value_type *;
151 using reference = const value_type &;
152 using difference_type = std::ptrdiff_t;
153 using iterator_category = std::forward_iterator_tag;
154
155 constexpr dense_set_local_iterator() noexcept
156 : it{},
157 offset{} {}
158
159 constexpr dense_set_local_iterator(It iter, const std::size_t pos) noexcept
160 : it{iter},
161 offset{pos} {}
162
163 template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
164 constexpr dense_set_local_iterator(const dense_set_local_iterator<Other> &other) noexcept
165 : it{other.it},
166 offset{other.offset} {}
167
168 constexpr dense_set_local_iterator &operator++() noexcept {
169 return offset = it[static_cast<typename It::difference_type>(offset)].first, *this;
170 }
171
172 constexpr dense_set_local_iterator operator++(int) noexcept {
173 const dense_set_local_iterator orig = *this;
174 return ++(*this), orig;
175 }
176
177 [[nodiscard]] constexpr pointer operator->() const noexcept {
178 return std::addressof(it[static_cast<typename It::difference_type>(offset)].second);
179 }
180
181 [[nodiscard]] constexpr reference operator*() const noexcept {
182 return *operator->();
183 }
184
185 [[nodiscard]] constexpr std::size_t index() const noexcept {
186 return offset;
187 }
188
189private:
190 It it;
191 std::size_t offset;
192};
193
194template<typename Lhs, typename Rhs>
195[[nodiscard]] constexpr bool operator==(const dense_set_local_iterator<Lhs> &lhs, const dense_set_local_iterator<Rhs> &rhs) noexcept {
196 return lhs.index() == rhs.index();
197}
198
199template<typename Lhs, typename Rhs>
200[[nodiscard]] constexpr bool operator!=(const dense_set_local_iterator<Lhs> &lhs, const dense_set_local_iterator<Rhs> &rhs) noexcept {
201 return !(lhs == rhs);
202}
203
204} // namespace internal
206
219template<typename Type, typename Hash, typename KeyEqual, typename Allocator>
220 class dense_set {
221 static constexpr float default_threshold = 0.875f;
222 static constexpr std::size_t minimum_capacity = 8u;
223
224 using node_type = std::pair<std::size_t, Type>;
225 using alloc_traits = std::allocator_traits<Allocator>;
226 static_assert(std::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
227 using sparse_container_type = std::vector<std::size_t, typename alloc_traits::template rebind_alloc<std::size_t>>;
228 using packed_container_type = std::vector<node_type, typename alloc_traits::template rebind_alloc<node_type>>;
229
230 template<typename Other>
231 [[nodiscard]] std::size_t value_to_bucket(const Other &value) const noexcept {
232 return fast_mod(static_cast<size_type>(sparse.second()(value)), bucket_count());
233 }
234
235 template<typename Other>
236 [[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) {
237 for(auto it = begin(bucket), last = end(bucket); it != last; ++it) {
238 if(packed.second()(*it, value)) {
239 return begin() + static_cast<difference_type>(it.index());
240 }
241 }
242
243 return end();
244 }
245
246 template<typename Other>
247 [[nodiscard]] auto constrained_find(const Other &value, std::size_t bucket) const {
248 for(auto it = cbegin(bucket), last = cend(bucket); it != last; ++it) {
249 if(packed.second()(*it, value)) {
250 return cbegin() + static_cast<difference_type>(it.index());
251 }
252 }
253
254 return cend();
255 }
256
257 template<typename Other>
258 [[nodiscard]] auto insert_or_do_nothing(Other &&value) {
259 const auto index = value_to_bucket(value);
260
261 if(auto it = constrained_find(value, index); it != end()) {
262 return std::make_pair(it, false);
263 }
264
265 packed.first().emplace_back(sparse.first()[index], std::forward<Other>(value));
266 sparse.first()[index] = packed.first().size() - 1u;
267 rehash_if_required();
268
269 return std::make_pair(--end(), true);
270 }
271
272 void move_and_pop(const std::size_t pos) {
273 if(const auto last = size() - 1u; pos != last) {
274 size_type *curr = &sparse.first()[value_to_bucket(packed.first().back().second)];
275 packed.first()[pos] = std::move(packed.first().back());
276 for(; *curr != last; curr = &packed.first()[*curr].first) {}
277 *curr = pos;
278 }
279
280 packed.first().pop_back();
281 }
282
283 void rehash_if_required() {
284 if(const auto bc = bucket_count(); size() > static_cast<size_type>(static_cast<float>(bc) * max_load_factor())) {
285 rehash(bc * 2u);
286 }
287 }
288
289public:
291 using allocator_type = Allocator;
293 using key_type = Type;
295 using value_type = Type;
297 using size_type = std::size_t;
299 using difference_type = std::ptrdiff_t;
301 using hasher = Hash;
303 using key_equal = KeyEqual;
305 using iterator = internal::dense_set_iterator<typename packed_container_type::iterator>;
307 using const_iterator = internal::dense_set_iterator<typename packed_container_type::const_iterator>;
309 using reverse_iterator = std::reverse_iterator<iterator>;
311 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
313 using local_iterator = internal::dense_set_local_iterator<typename packed_container_type::iterator>;
315 using const_local_iterator = internal::dense_set_local_iterator<typename packed_container_type::const_iterator>;
316
318 dense_set()
319 : dense_set{minimum_capacity} {}
320
325 explicit dense_set(const allocator_type &allocator)
326 : dense_set{minimum_capacity, hasher{}, key_equal{}, allocator} {}
327
334 dense_set(const size_type cnt, const allocator_type &allocator)
335 : dense_set{cnt, hasher{}, key_equal{}, allocator} {}
336
344 dense_set(const size_type cnt, const hasher &hash, const allocator_type &allocator)
345 : dense_set{cnt, hash, key_equal{}, allocator} {}
346
355 explicit dense_set(const size_type cnt, const hasher &hash = hasher{}, const key_equal &equal = key_equal{}, const allocator_type &allocator = allocator_type{})
356 : sparse{allocator, hash},
357 packed{allocator, equal} {
358 rehash(cnt);
359 }
360
362 dense_set(const dense_set &) = default;
363
369 dense_set(const dense_set &other, const allocator_type &allocator)
370 : sparse{std::piecewise_construct, std::forward_as_tuple(other.sparse.first(), allocator), std::forward_as_tuple(other.sparse.second())},
371 packed{std::piecewise_construct, std::forward_as_tuple(other.packed.first(), allocator), std::forward_as_tuple(other.packed.second())},
372 threshold{other.threshold} {}
373
375 dense_set(dense_set &&) noexcept = default;
376
382 dense_set(dense_set &&other, const allocator_type &allocator)
383 : sparse{std::piecewise_construct, std::forward_as_tuple(std::move(other.sparse.first()), allocator), std::forward_as_tuple(std::move(other.sparse.second()))},
384 packed{std::piecewise_construct, std::forward_as_tuple(std::move(other.packed.first()), allocator), std::forward_as_tuple(std::move(other.packed.second()))},
385 threshold{other.threshold} {}
386
388 ~dense_set() = default;
389
394 dense_set &operator=(const dense_set &) = default;
395
400 dense_set &operator=(dense_set &&) noexcept = default;
401
406 void swap(dense_set &other) noexcept {
407 using std::swap;
408 swap(sparse, other.sparse);
409 swap(packed, other.packed);
410 swap(threshold, other.threshold);
411 }
412
417 [[nodiscard]] constexpr allocator_type get_allocator() const noexcept {
418 return sparse.first().get_allocator();
419 }
420
428 [[nodiscard]] const_iterator cbegin() const noexcept {
429 return packed.first().begin();
430 }
431
433 [[nodiscard]] const_iterator begin() const noexcept {
434 return cbegin();
435 }
436
438 [[nodiscard]] iterator begin() noexcept {
439 return packed.first().begin();
440 }
441
447 [[nodiscard]] const_iterator cend() const noexcept {
448 return packed.first().end();
449 }
450
452 [[nodiscard]] const_iterator end() const noexcept {
453 return cend();
454 }
455
457 [[nodiscard]] iterator end() noexcept {
458 return packed.first().end();
459 }
460
468 [[nodiscard]] const_reverse_iterator crbegin() const noexcept {
469 return std::make_reverse_iterator(cend());
470 }
471
473 [[nodiscard]] const_reverse_iterator rbegin() const noexcept {
474 return crbegin();
475 }
476
478 [[nodiscard]] reverse_iterator rbegin() noexcept {
479 return std::make_reverse_iterator(end());
480 }
481
487 [[nodiscard]] const_reverse_iterator crend() const noexcept {
488 return std::make_reverse_iterator(cbegin());
489 }
490
492 [[nodiscard]] const_reverse_iterator rend() const noexcept {
493 return crend();
494 }
495
497 [[nodiscard]] reverse_iterator rend() noexcept {
498 return std::make_reverse_iterator(begin());
499 }
500
505 [[nodiscard]] bool empty() const noexcept {
506 return packed.first().empty();
507 }
508
513 [[nodiscard]] size_type size() const noexcept {
514 return packed.first().size();
515 }
516
521 [[nodiscard]] size_type max_size() const noexcept {
522 return packed.first().max_size();
523 }
524
526 void clear() noexcept {
527 sparse.first().clear();
528 packed.first().clear();
529 rehash(0u);
530 }
531
539 std::pair<iterator, bool> insert(const value_type &value) {
540 return insert_or_do_nothing(value);
541 }
542
544 std::pair<iterator, bool> insert(value_type &&value) {
545 return insert_or_do_nothing(std::move(value));
546 }
547
554 template<typename It>
555 void insert(It first, It last) {
556 for(; first != last; ++first) {
557 insert(*first);
558 }
559 }
560
574 template<typename... Args>
575 std::pair<iterator, bool> emplace(Args &&...args) {
576 if constexpr(((sizeof...(Args) == 1u) && ... && std::is_same_v<std::decay_t<Args>, value_type>)) {
577 return insert_or_do_nothing(std::forward<Args>(args)...);
578 } else {
579 auto &node = packed.first().emplace_back(std::piecewise_construct, std::make_tuple(packed.first().size()), std::forward_as_tuple(std::forward<Args>(args)...));
580 const auto index = value_to_bucket(node.second);
581
582 if(auto it = constrained_find(node.second, index); it != end()) {
583 packed.first().pop_back();
584 return std::make_pair(it, false);
585 }
586
587 std::swap(node.first, sparse.first()[index]);
588 rehash_if_required();
589
590 return std::make_pair(--end(), true);
591 }
592 }
593
599 iterator erase(const_iterator pos) {
600 const auto diff = pos - cbegin();
601 erase(*pos);
602 return begin() + diff;
603 }
604
611 iterator erase(const_iterator first, const_iterator last) {
612 const auto dist = first - cbegin();
613
614 for(auto from = last - cbegin(); from != dist; --from) {
615 erase(packed.first()[static_cast<size_type>(from) - 1u].second);
616 }
617
618 return (begin() + dist);
619 }
620
626 size_type erase(const value_type &value) {
627 for(size_type *curr = &sparse.first()[value_to_bucket(value)]; *curr != (std::numeric_limits<size_type>::max)(); curr = &packed.first()[*curr].first) {
628 if(packed.second()(packed.first()[*curr].second, value)) {
629 const auto index = *curr;
630 *curr = packed.first()[*curr].first;
631 move_and_pop(index);
632 return 1u;
633 }
634 }
635
636 return 0u;
637 }
638
644 [[nodiscard]] size_type count(const value_type &key) const {
645 return find(key) != end();
646 }
647
654 template<typename Other>
655 [[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, size_type>>
656 count(const Other &key) const {
657 return find(key) != end();
658 }
659
666 [[nodiscard]] iterator find(const value_type &value) {
667 return constrained_find(value, value_to_bucket(value));
668 }
669
671 [[nodiscard]] const_iterator find(const value_type &value) const {
672 return constrained_find(value, value_to_bucket(value));
673 }
674
682 template<typename Other>
683 [[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, iterator>>
684 find(const Other &value) {
685 return constrained_find(value, value_to_bucket(value));
686 }
687
689 template<typename Other>
690 [[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, const_iterator>>
691 find(const Other &value) const {
692 return constrained_find(value, value_to_bucket(value));
693 }
694
701 [[nodiscard]] std::pair<iterator, iterator> equal_range(const value_type &value) {
702 const auto it = find(value);
703 return {it, it + !(it == end())};
704 }
705
707 [[nodiscard]] std::pair<const_iterator, const_iterator> equal_range(const value_type &value) const {
708 const auto it = find(value);
709 return {it, it + !(it == cend())};
710 }
711
720 template<typename Other>
721 [[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, std::pair<iterator, iterator>>>
722 equal_range(const Other &value) {
723 const auto it = find(value);
724 return {it, it + !(it == end())};
725 }
726
728 template<typename Other>
729 [[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, std::pair<const_iterator, const_iterator>>>
730 equal_range(const Other &value) const {
731 const auto it = find(value);
732 return {it, it + !(it == cend())};
733 }
734
740 [[nodiscard]] bool contains(const value_type &value) const {
741 return (find(value) != cend());
742 }
743
751 template<typename Other>
752 [[nodiscard]] std::enable_if_t<is_transparent_v<hasher> && is_transparent_v<key_equal>, std::conditional_t<false, Other, bool>>
753 contains(const Other &value) const {
754 return (find(value) != cend());
755 }
756
762 [[nodiscard]] const_local_iterator cbegin(const size_type index) const {
763 return {packed.first().begin(), sparse.first()[index]};
764 }
765
771 [[nodiscard]] const_local_iterator begin(const size_type index) const {
772 return cbegin(index);
773 }
774
780 [[nodiscard]] local_iterator begin(const size_type index) {
781 return {packed.first().begin(), sparse.first()[index]};
782 }
783
789 [[nodiscard]] const_local_iterator cend([[maybe_unused]] const size_type index) const {
790 return {packed.first().begin(), (std::numeric_limits<size_type>::max)()};
791 }
792
798 [[nodiscard]] const_local_iterator end(const size_type index) const {
799 return cend(index);
800 }
801
807 [[nodiscard]] local_iterator end([[maybe_unused]] const size_type index) {
808 return {packed.first().begin(), (std::numeric_limits<size_type>::max)()};
809 }
810
815 [[nodiscard]] size_type bucket_count() const {
816 return sparse.first().size();
817 }
818
823 [[nodiscard]] size_type max_bucket_count() const {
824 return sparse.first().max_size();
825 }
826
832 [[nodiscard]] size_type bucket_size(const size_type index) const {
833 return static_cast<size_type>(std::distance(begin(index), end(index)));
834 }
835
841 [[nodiscard]] size_type bucket(const value_type &value) const {
842 return value_to_bucket(value);
843 }
844
849 [[nodiscard]] float load_factor() const {
850 return static_cast<float>(size()) / static_cast<float>(bucket_count());
851 }
852
857 [[nodiscard]] float max_load_factor() const {
858 return threshold;
859 }
860
865 void max_load_factor(const float value) {
866 ENTT_ASSERT(value > 0.f, "Invalid load factor");
867 threshold = value;
868 rehash(0u);
869 }
870
876 void rehash(const size_type cnt) {
877 auto value = cnt > minimum_capacity ? cnt : minimum_capacity;
878 const auto cap = static_cast<size_type>(static_cast<float>(size()) / max_load_factor());
879 value = value > cap ? value : cap;
880
881 if(const auto sz = next_power_of_two(value); sz != bucket_count()) {
882 sparse.first().resize(sz);
883
884 for(auto &&elem: sparse.first()) {
885 elem = (std::numeric_limits<size_type>::max)();
886 }
887
888 for(size_type pos{}, last = size(); pos < last; ++pos) {
889 const auto index = value_to_bucket(packed.first()[pos].second);
890 packed.first()[pos].first = std::exchange(sparse.first()[index], pos);
891 }
892 }
893 }
894
900 void reserve(const size_type cnt) {
901 packed.first().reserve(cnt);
902 rehash(static_cast<size_type>(std::ceil(static_cast<float>(cnt) / max_load_factor())));
903 }
904
909 [[nodiscard]] hasher hash_function() const {
910 return sparse.second();
911 }
912
917 [[nodiscard]] key_equal key_eq() const {
918 return packed.second();
919 }
920
921private:
922 compressed_pair<sparse_container_type, hasher> sparse;
923 compressed_pair<packed_container_type, key_equal> packed;
924 float threshold{default_threshold};
925};
926
927} // namespace entt
928
929#endif
entt::compressed_pair
A compressed pair.
Definition compressed_pair.hpp:87
entt::dense_set::bucket_size
size_type bucket_size(const size_type index) const
Returns the number of elements in a given bucket.
Definition dense_set.hpp:832
entt::dense_set::clear
void clear() noexcept
Clears the container.
Definition dense_set.hpp:526
entt::dense_set::const_local_iterator
internal::dense_set_local_iterator< typename packed_container_type::const_iterator > const_local_iterator
Constant forward iterator type.
Definition dense_set.hpp:315
entt::dense_set::crbegin
const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the beginning.
Definition dense_set.hpp:468
entt::dense_set::difference_type
std::ptrdiff_t difference_type
Signed integer type.
Definition dense_set.hpp:299
entt::dense_set::begin
const_iterator begin() const noexcept
Returns an iterator to the beginning.
Definition dense_set.hpp:433
entt::dense_set::key_eq
key_equal key_eq() const
Returns the function used to compare elements for equality.
Definition dense_set.hpp:917
entt::dense_set::key_equal
KeyEqual key_equal
Type of function to use to compare the elements for equality.
Definition dense_set.hpp:303
entt::dense_set::const_iterator
internal::dense_set_iterator< typename packed_container_type::const_iterator > const_iterator
Constant random access iterator type.
Definition dense_set.hpp:307
entt::dense_set::cend
const_iterator cend() const noexcept
Returns an iterator to the end.
Definition dense_set.hpp:447
entt::dense_set::erase
iterator erase(const_iterator first, const_iterator last)
Removes the given elements from a container.
Definition dense_set.hpp:611
entt::dense_set::contains
std::enable_if_t< is_transparent_v< hasher > &&is_transparent_v< key_equal >, std::conditional_t< false, Other, bool > > contains(const Other &value) const
Checks if the container contains an element that compares equivalent to a given value.
Definition dense_set.hpp:753
entt::dense_set::hasher
Hash hasher
Type of function to use to hash the elements.
Definition dense_set.hpp:301
entt::dense_set::size_type
std::size_t size_type
Unsigned integer type.
Definition dense_set.hpp:297
entt::dense_set::bucket
size_type bucket(const value_type &value) const
Returns the bucket for a given element.
Definition dense_set.hpp:841
entt::dense_set::rbegin
reverse_iterator rbegin() noexcept
Returns a reverse iterator to the beginning.
Definition dense_set.hpp:478
entt::dense_set::find
iterator find(const value_type &value)
Finds an element with a given value.
Definition dense_set.hpp:666
entt::dense_set::key_type
Type key_type
Key type of the container.
Definition dense_set.hpp:293
entt::dense_set::value_type
Type value_type
Value type of the container.
Definition dense_set.hpp:295
entt::dense_set::iterator
internal::dense_set_iterator< typename packed_container_type::iterator > iterator
Random access iterator type.
Definition dense_set.hpp:305
entt::dense_set::emplace
std::pair< iterator, bool > emplace(Args &&...args)
Constructs an element in-place, if it does not exist.
Definition dense_set.hpp:575
entt::dense_set::operator=
dense_set & operator=(dense_set &&) noexcept=default
Default move assignment operator.
entt::dense_set::bucket_count
size_type bucket_count() const
Returns the number of buckets.
Definition dense_set.hpp:815
entt::dense_set::max_size
size_type max_size() const noexcept
Returns the maximum possible number of elements.
Definition dense_set.hpp:521
entt::dense_set::size
size_type size() const noexcept
Returns the number of elements in a container.
Definition dense_set.hpp:513
entt::dense_set::equal_range
std::pair< iterator, iterator > equal_range(const value_type &value)
Returns a range containing all elements with a given value.
Definition dense_set.hpp:701
entt::dense_set::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Constant reverse iterator type.
Definition dense_set.hpp:311
entt::dense_set::equal_range
std::enable_if_t< is_transparent_v< hasher > &&is_transparent_v< key_equal >, std::conditional_t< false, Other, std::pair< iterator, iterator > > > equal_range(const Other &value)
Returns a range containing all elements that compare equivalent to a given value.
Definition dense_set.hpp:722
entt::dense_set::end
local_iterator end(const size_type index)
Returns an iterator to the end of a given bucket.
Definition dense_set.hpp:807
entt::dense_set::dense_set
dense_set(const dense_set &other, const allocator_type &allocator)
Allocator-extended copy constructor.
Definition dense_set.hpp:369
entt::dense_set::empty
bool empty() const noexcept
Checks whether a container is empty.
Definition dense_set.hpp:505
entt::dense_set::dense_set
dense_set(const size_type cnt, const hasher &hash, const allocator_type &allocator)
Constructs an empty container with a given allocator, hash function and user supplied minimal number ...
Definition dense_set.hpp:344
entt::dense_set::find
const_iterator find(const value_type &value) const
Finds an element with a given value.
Definition dense_set.hpp:671
entt::dense_set::cbegin
const_iterator cbegin() const noexcept
Returns an iterator to the beginning.
Definition dense_set.hpp:428
entt::dense_set::rend
const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the end.
Definition dense_set.hpp:492
entt::dense_set::dense_set
dense_set(const size_type cnt, const allocator_type &allocator)
Constructs an empty container with a given allocator and user supplied minimal number of buckets.
Definition dense_set.hpp:334
entt::dense_set::hash_function
hasher hash_function() const
Returns the function used to hash the elements.
Definition dense_set.hpp:909
entt::dense_set::insert
std::pair< iterator, bool > insert(const value_type &value)
Inserts an element into the container, if it does not exist.
Definition dense_set.hpp:539
entt::dense_set::local_iterator
internal::dense_set_local_iterator< typename packed_container_type::iterator > local_iterator
Forward iterator type.
Definition dense_set.hpp:313
entt::dense_set::~dense_set
~dense_set()=default
Default destructor.
entt::dense_set::reserve
void reserve(const size_type cnt)
Reserves space for at least the specified number of elements and regenerates the hash table.
Definition dense_set.hpp:900
entt::dense_set::cend
const_local_iterator cend(const size_type index) const
Returns an iterator to the end of a given bucket.
Definition dense_set.hpp:789
entt::dense_set::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator type.
Definition dense_set.hpp:309
entt::dense_set::allocator_type
Allocator allocator_type
Allocator type.
Definition dense_set.hpp:291
entt::dense_set::count
size_type count(const value_type &key) const
Returns the number of elements matching a value (either 1 or 0).
Definition dense_set.hpp:644
entt::dense_set::end
iterator end() noexcept
Returns an iterator to the end.
Definition dense_set.hpp:457
entt::dense_set::find
std::enable_if_t< is_transparent_v< hasher > &&is_transparent_v< key_equal >, std::conditional_t< false, Other, const_iterator > > find(const Other &value) const
Finds an element with a given value.
Definition dense_set.hpp:691
entt::dense_set::dense_set
dense_set(const dense_set &)=default
Default copy constructor.
entt::dense_set< id_type, identity, std::equal_to<>, typename alloc_traits::template rebind_alloc< id_type > >::swap
void swap(dense_set &other) noexcept
Definition dense_set.hpp:406
entt::dense_set::dense_set
dense_set(dense_set &&) noexcept=default
Default move constructor.
entt::dense_set::end
const_local_iterator end(const size_type index) const
Returns an iterator to the end of a given bucket.
Definition dense_set.hpp:798
entt::dense_set::max_load_factor
void max_load_factor(const float value)
Sets the desired maximum average number of elements per bucket.
Definition dense_set.hpp:865
entt::dense_set::load_factor
float load_factor() const
Returns the average number of elements per bucket.
Definition dense_set.hpp:849
entt::dense_set::erase
size_type erase(const value_type &value)
Removes the element associated with a given value.
Definition dense_set.hpp:626
entt::dense_set::insert
std::pair< iterator, bool > insert(value_type &&value)
Inserts an element into the container, if it does not exist.
Definition dense_set.hpp:544
entt::dense_set::max_bucket_count
size_type max_bucket_count() const
Returns the maximum number of buckets.
Definition dense_set.hpp:823
entt::dense_set::dense_set
dense_set(const allocator_type &allocator)
Constructs an empty container with a given allocator.
Definition dense_set.hpp:325
entt::dense_set::rbegin
const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the beginning.
Definition dense_set.hpp:473
entt::dense_set::dense_set
dense_set()
Default constructor.
Definition dense_set.hpp:318
entt::dense_set::end
const_iterator end() const noexcept
Returns an iterator to the end.
Definition dense_set.hpp:452
entt::dense_set::operator=
dense_set & operator=(const dense_set &)=default
Default copy assignment operator.
entt::dense_set::dense_set
dense_set(const size_type cnt, const hasher &hash=hasher{}, const key_equal &equal=key_equal{}, const allocator_type &allocator=allocator_type{})
Constructs an empty container with a given allocator, hash function, compare function and user suppli...
Definition dense_set.hpp:355
entt::dense_set::erase
iterator erase(const_iterator pos)
Removes an element from a given position.
Definition dense_set.hpp:599
entt::dense_set::find
std::enable_if_t< is_transparent_v< hasher > &&is_transparent_v< key_equal >, std::conditional_t< false, Other, iterator > > find(const Other &value)
Finds an element that compares equivalent to a given value.
Definition dense_set.hpp:684
entt::dense_set::rehash
void rehash(const size_type cnt)
Reserves at least the specified number of buckets and regenerates the hash table.
Definition dense_set.hpp:876
entt::dense_set::crend
const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the end.
Definition dense_set.hpp:487
entt::dense_set::count
std::enable_if_t< is_transparent_v< hasher > &&is_transparent_v< key_equal >, std::conditional_t< false, Other, size_type > > count(const Other &key) const
Returns the number of elements matching a key (either 1 or 0).
Definition dense_set.hpp:656
entt::dense_set::get_allocator
constexpr allocator_type get_allocator() const noexcept
Returns the associated allocator.
Definition dense_set.hpp:417
entt::dense_set::insert
void insert(It first, It last)
Inserts elements into the container, if they do not exist.
Definition dense_set.hpp:555
entt::dense_set::rend
reverse_iterator rend() noexcept
Returns a reverse iterator to the end.
Definition dense_set.hpp:497
entt::dense_set::max_load_factor
float max_load_factor() const
Returns the maximum average number of elements per bucket.
Definition dense_set.hpp:857
entt::dense_set::equal_range
std::enable_if_t< is_transparent_v< hasher > &&is_transparent_v< key_equal >, std::conditional_t< false, Other, std::pair< const_iterator, const_iterator > > > equal_range(const Other &value) const
Returns a range containing all elements with a given value.
Definition dense_set.hpp:730
entt::dense_set::equal_range
std::pair< const_iterator, const_iterator > equal_range(const value_type &value) const
Returns a range containing all elements with a given value.
Definition dense_set.hpp:707
entt::dense_set::begin
const_local_iterator begin(const size_type index) const
Returns an iterator to the beginning of a given bucket.
Definition dense_set.hpp:771
entt::dense_set::begin
local_iterator begin(const size_type index)
Returns an iterator to the beginning of a given bucket.
Definition dense_set.hpp:780
entt::dense_set::cbegin
const_local_iterator cbegin(const size_type index) const
Returns an iterator to the beginning of a given bucket.
Definition dense_set.hpp:762
entt::dense_set::contains
bool contains(const value_type &value) const
Checks if the container contains an element with a given value.
Definition dense_set.hpp:740
entt::dense_set::begin
iterator begin() noexcept
Returns an iterator to the beginning.
Definition dense_set.hpp:438
entt
EnTT default namespace.
Definition dense_map.hpp:22
entt::fast_mod
constexpr std::enable_if_t< std::is_unsigned_v< Type >, Type > fast_mod(const Type value, const std::size_t mod) noexcept
Fast module utility function (powers of two only).
Definition bit.hpp:63
entt::is_transparent_v
constexpr bool is_transparent_v
Helper variable template.
Definition type_traits.hpp:737
entt::operator<=
constexpr bool operator<=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:257
entt::next_power_of_two
constexpr std::enable_if_t< std::is_unsigned_v< Type >, Type > next_power_of_two(const Type value) noexcept
Computes the smallest power of two greater than or equal to a value (waiting for C++20 and std::bit_c...
Definition bit.hpp:43
entt::operator<
constexpr bool operator<(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:244
entt::operator+
constexpr type_list< Type..., Other... > operator+(type_list< Type... >, type_list< Other... >)
Concatenates multiple type lists.
Definition type_traits.hpp:210
entt::operator!=
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:232
entt::operator>=
constexpr bool operator>=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:283
entt::operator>
constexpr bool operator>(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:270
entt::operator==
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:220