4#ifndef GREM_CORE_DATA_HASH_MAP_HPP
5#define GREM_CORE_DATA_HASH_MAP_HPP
18#include <initializer_list>
22#include <memory_resource>
29template <
typename Key,
typename T,
typename Hash = std::hash<Key>,
typename KeyEqual = std::equal_to<Key>,
typename Allocator = std::allocator<Pair<const Key, T>>>
32 static constexpr bool IS_TRANSPARENT =
requires {
33 typename Hash::is_transparent;
34 typename KeyEqual::is_transparent;
49 using Map = std::conditional_t<Const, const HashMap, HashMap>;
55 using iterator_category = std::bidirectional_iterator_tag;
60 [[nodiscard]]
constexpr reference*
operator->() noexcept {
65 Iterator() noexcept = default;
67 constexpr Iterator(Map* map,
size_type index) noexcept
71 constexpr operator Iterator<true>() const noexcept requires(!Const) {
72 return Iterator<true>{map, index};
75 [[nodiscard]]
constexpr reference operator*()
const {
78 return reference{map->keys[index], map->values[index]};
81 [[nodiscard]]
constexpr pointer operator->()
const {
85 constexpr Iterator& operator++() {
89 index = map->findActiveIndexUnbounded(index + 1);
93 constexpr Iterator operator++(
int) {
99 constexpr Iterator& operator--() {
103 index = map->findActiveIndexReverseUnbounded(index - 1);
107 constexpr Iterator operator--(
int) {
108 Iterator old = *
this;
113 [[nodiscard]]
constexpr bool operator==(
const Iterator& other)
const {
115 return index == other.index;
118 [[nodiscard]]
constexpr size_type getIndex() const noexcept {
141 constexpr explicit
HashMap(
size_type bucket_count, const Hash& hash = Hash(), const KeyEqual& equal = KeyEqual(), const Allocator& allocator = Allocator())
142 :
HashMap(hash, equal, allocator) {
147 :
HashMap(bucket_count, Hash(), KeyEqual(), allocator) {}
150 :
HashMap(bucket_count, hash, KeyEqual(), allocator) {}
152 constexpr explicit HashMap(
const Allocator& allocator)
153 :
HashMap(Hash(), KeyEqual(), allocator) {}
155 template <std::input_iterator InputIterator, std::sentinel_for<InputIterator> Sentinel>
156 constexpr HashMap(InputIterator first, Sentinel last,
size_type bucket_count = 0,
const Hash& hash = Hash(),
const KeyEqual& equal = KeyEqual(),
157 const Allocator& allocator = Allocator())
158 :
HashMap(bucket_count, hash, equal, allocator) {
162 template <std::input_iterator InputIterator, std::sentinel_for<InputIterator> Sentinel>
163 constexpr HashMap(InputIterator first, Sentinel last,
size_type bucket_count,
const Allocator& allocator)
164 :
HashMap(first, last, bucket_count, Hash(), KeyEqual(), allocator) {}
166 template <std::input_iterator InputIterator, std::sentinel_for<InputIterator> Sentinel>
167 constexpr HashMap(InputIterator first, Sentinel last,
size_type bucket_count,
const Hash& hash,
const Allocator& allocator)
168 :
HashMap(first, last, bucket_count, hash, KeyEqual(), allocator) {}
170 constexpr HashMap(std::initializer_list<value_type> ilist,
size_type bucket_count = 0,
const Hash& hash = Hash(),
const KeyEqual& equal = KeyEqual(),
171 const Allocator& allocator = Allocator())
172 :
HashMap(ilist.
begin(), ilist.
end(), bucket_count, hash, equal, allocator) {}
174 constexpr HashMap(std::initializer_list<value_type> ilist,
size_type bucket_count,
const Allocator& allocator = Allocator())
175 :
HashMap(ilist, bucket_count, Hash(), KeyEqual(), allocator) {}
177 constexpr HashMap(std::initializer_list<value_type> ilist,
size_type bucket_count,
const Hash& hash = Hash(),
const Allocator& allocator = Allocator())
178 :
HashMap(ilist, bucket_count, hash, KeyEqual(), allocator) {}
181 :
HashMap(other, std::allocator_traits<Allocator>::select_on_container_copy_construction(other.
get_allocator())) {}
189 : activeBits(std::exchange(other.activeBits,
nullptr))
190 , bucketExtents(std::exchange(other.bucketExtents,
nullptr))
191 , keys(std::exchange(other.keys,
nullptr))
192 , values(std::exchange(other.values,
nullptr))
193 , elementCount(std::exchange(other.elementCount,
size_type{0}))
194 , elementCapacity(std::exchange(other.elementCapacity,
size_type{0}))
195 , hash(std::move(other.hash))
196 , equal(std::move(other.equal))
197 , allocator(other.get_allocator()) {}
201 if constexpr (!std::allocator_traits<Allocator>::is_always_equal::value) {
202 if (allocator != other.get_allocator()) {
205 if constexpr (std::is_nothrow_move_constructible_v<Key> && std::is_nothrow_move_constructible_v<T>) {
206 emplace(std::move(
const_cast<Key&
>(element.first)), std::move(element.second));
208 emplace(element.first, element.second);
215 activeBits = std::exchange(other.activeBits,
nullptr);
216 bucketExtents = std::exchange(other.bucketExtents,
nullptr);
217 keys = std::exchange(other.keys,
nullptr);
218 values = std::exchange(other.values,
nullptr);
219 elementCount = std::exchange(other.elementCount,
size_type{0});
220 elementCapacity = std::exchange(other.elementCapacity,
size_type{0});
221 hash = std::move(other.hash);
222 equal = std::move(other.equal);
230 if (
this == &other) {
233 if constexpr (std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value) {
234 if constexpr (!std::allocator_traits<Allocator>::is_always_equal::value) {
242 if (elementCapacity == other.elementCapacity) {
243 if (other.elementCount > 0) {
246 KeyAllocator keyAllocator = allocator;
247 ValueAllocator valueAllocator = allocator;
249 for (
size_type index =
begin; index < elementCapacity; index = other.findActiveIndexUnbounded(index + 1)) {
251 std::allocator_traits<KeyAllocator>::construct(keyAllocator, std::to_address(keys) + index, other.keys[index]);
253 std::allocator_traits<ValueAllocator>::construct(valueAllocator, std::to_address(values) + index, other.values[index]);
255 std::allocator_traits<KeyAllocator>::destroy(keyAllocator, std::to_address(keys) + index);
259 while (index !=
begin) {
260 index = other.findActiveIndexReverseUnbounded(index - 1);
261 std::allocator_traits<ValueAllocator>::destroy(valueAllocator, std::to_address(values) + index);
262 std::allocator_traits<KeyAllocator>::destroy(keyAllocator, std::to_address(keys) + index);
267 std::memcpy(std::to_address(activeBits), std::to_address(other.activeBits), (elementCapacity / 64) *
sizeof(std::uint64_t));
268 std::memcpy(std::to_address(bucketExtents), std::to_address(other.bucketExtents), elementCapacity *
sizeof(std::uint32_t));
269 elementCount = other.elementCount;
280 if (
this == &other) {
283 if constexpr (!std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {
284 if constexpr (!std::allocator_traits<Allocator>::is_always_equal::value) {
285 if (allocator != other.get_allocator()) {
289 if constexpr (std::is_nothrow_move_constructible_v<Key> && std::is_nothrow_move_constructible_v<T>) {
290 emplace(std::move(
const_cast<Key&
>(element.first)), std::move(element.second));
292 emplace(element.first, element.second);
301 activeBits = std::exchange(other.activeBits,
nullptr);
302 bucketExtents = std::exchange(other.bucketExtents,
nullptr);
303 keys = std::exchange(other.keys,
nullptr);
304 values = std::exchange(other.values,
nullptr);
305 elementCount = std::exchange(other.elementCount,
size_type{0});
306 elementCapacity = std::exchange(other.elementCapacity,
size_type{0});
307 hash = std::move(other.hash);
308 equal = std::move(other.equal);
309 if constexpr (std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {
310 allocator = other.get_allocator();
321 constexpr void swap(
HashMap& other)
noexcept(std::allocator_traits<Allocator>::is_always_equal::value) {
322 if (
this == &other) {
326 swap(activeBits, other.activeBits);
327 swap(bucketExtents, other.bucketExtents);
328 swap(keys, other.keys);
329 swap(values, other.values);
330 swap(elementCount, other.elementCount);
331 swap(elementCapacity, other.elementCapacity);
332 swap(hash, other.hash);
333 swap(equal, other.equal);
334 if constexpr (std::allocator_traits<Allocator>::propagate_on_container_swap::value) {
335 swap(allocator, other.allocator);
336 }
else if constexpr (!std::allocator_traits<Allocator>::is_always_equal::value) {
346 if (elementCount > 0) {
349 KeyAllocator keyAllocator = allocator;
350 ValueAllocator valueAllocator = allocator;
351 for (
size_type index = findActiveIndexUnbounded(0); index < elementCapacity; index = findActiveIndexUnbounded(index + 1)) {
352 std::allocator_traits<ValueAllocator>::destroy(valueAllocator, std::to_address(values) + index);
353 std::allocator_traits<KeyAllocator>::destroy(keyAllocator, std::to_address(keys) + index);
355 std::memset(std::to_address(activeBits), 0, (elementCapacity / 64) *
sizeof(std::uint64_t));
356 std::memset(std::to_address(bucketExtents), 0, elementCapacity *
sizeof(std::uint32_t));
363 while (
static_cast<float>(capacity) >
static_cast<float>(newCapacity) * MAX_SIZE_PER_CAPACITY) {
364 if (newCapacity >= std::numeric_limits<size_type>::max() / 2) {
365 throw std::length_error{
"Maximum capacity exceeded."};
369 if (newCapacity <= elementCapacity) {
374 GREM_ASSERT((newCapacity & (newCapacity - 1)) == 0);
376 HashMap newMap{hash, equal, allocator};
377 UInt64Allocator uInt64Allocator = allocator;
378 UInt32Allocator uInt32Allocator = allocator;
379 KeyAllocator keyAllocator = allocator;
380 ValueAllocator valueAllocator = allocator;
381 newMap.activeBits = std::allocator_traits<UInt64Allocator>::allocate(uInt64Allocator, newCapacity / 64 + 1);
383 newMap.bucketExtents = std::allocator_traits<UInt32Allocator>::allocate(uInt32Allocator, newCapacity);
385 newMap.keys = std::allocator_traits<KeyAllocator>::allocate(keyAllocator, newCapacity);
387 newMap.values = std::allocator_traits<ValueAllocator>::allocate(valueAllocator, newCapacity);
389 std::allocator_traits<KeyAllocator>::deallocate(keyAllocator, newMap.keys, newCapacity);
393 std::allocator_traits<UInt32Allocator>::deallocate(uInt32Allocator, newMap.bucketExtents, newCapacity);
397 std::allocator_traits<UInt64Allocator>::deallocate(uInt64Allocator, newMap.activeBits, newCapacity / 64 + 1);
400 std::memset(std::to_address(newMap.activeBits), 0, (newCapacity / 64) *
sizeof(std::uint64_t));
401 newMap.activeBits[newCapacity / 64] = 1;
402 std::memset(std::to_address(newMap.bucketExtents), 0, newCapacity *
sizeof(std::uint32_t));
403 newMap.elementCapacity = newCapacity;
406 if constexpr (std::is_nothrow_move_constructible_v<Key> && std::is_nothrow_move_constructible_v<T>) {
407 newMap.
emplace(std::move(
const_cast<Key&
>(element.first)), std::move(element.second));
409 newMap.
emplace(element.first, element.second);
413 *
this = std::move(newMap);
421 return try_emplace(std::move(value.first), std::move(value.second));
424 template <
typename P>
426 return emplace(std::forward<P>(value));
429 template <std::input_iterator InputIterator, std::sentinel_for<InputIterator> Sentinel>
430 constexpr void insert(InputIterator first, Sentinel last) {
431 if constexpr (std::is_convertible_v<typename std::iterator_traits<InputIterator>::iterator_category, std::random_access_iterator_tag>) {
434 while (first != last) {
439 constexpr void insert(std::initializer_list<value_type> ilist) {
440 insert(ilist.begin(), ilist.end());
443 template <
typename R>
445 insert(std::begin(r), std::end(r));
448 template <
typename... Args>
453 template <
typename... Args>
455 return try_emplace(Key(k), std::forward<Args>(args)...);
458 template <
typename... Args>
460 return insertAndConstruct(std::move(k), std::forward<Args>(args)...);
463 template <
typename K,
typename... Args>
465 requires(!std::is_convertible_v<K &&, const_iterator> && !std::is_convertible_v<K &&, iterator> && IS_TRANSPARENT) {
466 return insertAndConstruct(std::forward<K>(k), std::forward<Args>(args)...);
469 template <
typename M>
472 if (!result.second) {
473 result.first->second = std::forward<M>(
obj);
478 template <
typename M>
480 const auto result =
try_emplace(std::move(k), std::forward<M>(
obj));
481 if (!result.second) {
482 result.first->second = std::forward<M>(
obj);
487 template <
typename K,
typename M>
489 const auto result =
try_emplace(std::forward<K>(k), std::forward<M>(
obj));
490 if (!result.second) {
491 result.first->second = std::forward<M>(
obj);
497 return iterator{
this, eraseAtIndex(pos.index)};
501 while (first != last) {
502 first =
erase(first);
508 return eraseKey(key);
511 template <
typename K>
512 constexpr size_type erase(K&& x)
requires(IS_TRANSPARENT && !std::is_convertible_v<K, iterator> && !std::is_convertible_v<K, const_iterator>) {
513 return eraseKey(std::forward<K>(x));
516 template <
typename Predicate>
520 while (it != c.
end()) {
521 if (predicate(*it)) {
527 return oldSize - c.
size();
542 [[nodiscard]]
constexpr bool empty() const noexcept {
543 return elementCount == 0;
551 static_assert(MAX_SIZE_PER_CAPACITY <= 1.0f);
553 static_cast<float>(std::min({
554 static_cast<size_type>(std::numeric_limits<difference_type>::max()),
555 static_cast<size_type>(std::numeric_limits<size_type>::max() /
sizeof(std::uint32_t)),
556 static_cast<size_type>(std::numeric_limits<size_type>::max() /
sizeof(Key)),
557 static_cast<size_type>(std::numeric_limits<size_type>::max() /
sizeof(T)),
558 static_cast<size_type>(std::allocator_traits<UInt32Allocator>::max_size(allocator)),
559 static_cast<size_type>(std::allocator_traits<KeyAllocator>::max_size(allocator)),
560 static_cast<size_type>(std::allocator_traits<ValueAllocator>::max_size(allocator)),
562 MAX_SIZE_PER_CAPACITY);
565 [[nodiscard]]
constexpr T&
at(
const Key& key) {
569 throw std::out_of_range{
"!contains(key)"};
572 [[nodiscard]]
constexpr const T&
at(
const Key& key)
const {
576 throw std::out_of_range{
"!contains(key)"};
579 template <
typename K>
580 [[nodiscard]]
constexpr T&
at(
const K& key)
requires(IS_TRANSPARENT) {
584 throw std::out_of_range{
"!contains(key)"};
587 template <
typename K>
588 [[nodiscard]]
constexpr const T&
at(
const K& key)
const requires(IS_TRANSPARENT) {
592 throw std::out_of_range{
"!contains(key)"};
603 template <
typename K>
604 [[nodiscard]]
constexpr T&
operator[](K&& x)
requires(IS_TRANSPARENT) {
605 return try_emplace(std::forward<K>(x)).first->second;
608 [[nodiscard]]
constexpr bool contains(
const Key& key)
const {
612 template <
typename K>
613 [[nodiscard]]
constexpr bool contains(
const K& x)
const requires(IS_TRANSPARENT) {
621 template <
typename K>
622 [[nodiscard]]
constexpr size_type count(
const K& x)
const requires(IS_TRANSPARENT) {
627 return iterator{
this, findIndex(key)};
634 template <
typename K>
635 [[nodiscard]]
constexpr iterator find(
const K& x)
requires(IS_TRANSPARENT) {
636 return iterator{
this, findIndex(x)};
639 template <
typename K>
669 return {it, std::next(it)};
677 return {it, std::next(it)};
682 template <
typename K>
686 return {it, std::next(it)};
691 template <
typename K>
695 return {it, std::next(it)};
701 return iterator{
this, (elementCount > 0) ? findActiveIndexUnbounded(0) : elementCapacity};
705 return const_iterator{
this, (elementCount > 0) ? findActiveIndexUnbounded(0) : elementCapacity};
713 return iterator{
this, elementCapacity};
729 return std::lexicographical_compare(
begin(),
end(), other.
begin(), other.
end());
733 return !(other < *
this);
737 return other < *
this;
741 return !(*
this < other);
745 static constexpr float MAX_SIZE_PER_CAPACITY = 0.7f;
747 using UInt64Allocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<std::uint64_t>;
748 using UInt32Allocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<std::uint32_t>;
749 using KeyAllocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<Key>;
750 using ValueAllocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<T>;
752 constexpr HashMap(
const Hash& hash,
const KeyEqual&
equal,
const Allocator& allocator)
755 , allocator(allocator) {}
757 [[nodiscard]]
constexpr size_type getBucketIndexOfHash(std::size_t hashCode)
const noexcept {
758 GREM_ASSERT((elementCapacity & (elementCapacity - 1)) == 0);
759 return static_cast<size_type>(hashCode) &
static_cast<size_type>(elementCapacity - 1);
764 GREM_ASSERT((elementCapacity & (elementCapacity - 1)) == 0);
765 return index &
static_cast<size_type>(elementCapacity - 1);
768 [[nodiscard]]
constexpr bool isActive(
size_type index)
const {
769 return (activeBits[index / 64] & (std::uint64_t{1} << (index % 64))) != 0;
772 constexpr void setActive(
size_type index) {
773 activeBits[index / 64] |= std::uint64_t{1} << (index % 64);
776 constexpr void clearActive(
size_type index) {
777 activeBits[index / 64] &= ~(std::uint64_t{1} << (index % 64));
782 const std::uint64_t bitsIndex = index / 64;
783 const std::uint64_t bitOffset = index % 64;
784 const std::uint64_t bits = activeBits[bitsIndex] >> bitOffset;
786 index +=
static_cast<size_type>(std::countr_zero(bits));
789 index += 64 - bitOffset;
794 [[nodiscard]]
constexpr size_type findActiveIndexReverseUnbounded(
size_type index)
const {
796 const std::uint64_t bitsIndex = index / 64;
797 const std::uint64_t bitOffset = index % 64;
798 const std::uint64_t bits = activeBits[bitsIndex] << (63 - bitOffset);
800 index -=
static_cast<size_type>(std::countl_zero(bits));
803 index -= bitOffset + 1;
808 constexpr void reset() noexcept {
810 if (elementCapacity > 0) {
812 UInt64Allocator uInt64Allocator = allocator;
813 UInt32Allocator uInt32Allocator = allocator;
814 KeyAllocator keyAllocator = allocator;
815 ValueAllocator valueAllocator = allocator;
816 std::allocator_traits<UInt64Allocator>::deallocate(uInt64Allocator, activeBits, elementCapacity / 64 + 1);
817 std::allocator_traits<UInt32Allocator>::deallocate(uInt32Allocator, bucketExtents, elementCapacity);
818 std::allocator_traits<KeyAllocator>::deallocate(keyAllocator, keys, elementCapacity);
819 std::allocator_traits<ValueAllocator>::deallocate(valueAllocator, values, elementCapacity);
820 activeBits =
nullptr;
821 bucketExtents =
nullptr;
828 template <
typename K,
typename... Args>
831 throw std::length_error{
"size() >= max_size()"};
836 const size_type bucketBegin = getBucketIndexOfHash(hash(k));
837 const size_type bucketExtent = bucketExtents[bucketBegin];
838 const size_type bucketEnd = getWrappedIndex(bucketBegin + bucketExtent);
839 for (
size_type index = bucketBegin; index != bucketEnd; index = getWrappedIndex(index + 1)) {
840 if (isActive(index) && equal(keys[index], k)) {
841 return {
iterator{
this, index},
false};
846 while (isActive(index)) {
847 index = getWrappedIndex(index + 1);
848 if (newBucketExtent >=
size_type{std::numeric_limits<std::uint32_t>::max()}) {
849 throw std::length_error{
"Maximum bucket size exceeded."};
854 KeyAllocator keyAllocator = allocator;
855 ValueAllocator valueAllocator = allocator;
856 std::allocator_traits<KeyAllocator>::construct(keyAllocator, std::to_address(keys) + index, std::forward<K>(k));
858 std::allocator_traits<ValueAllocator>::construct(valueAllocator, std::to_address(values) + index, std::forward<Args>(args)...);
860 std::allocator_traits<KeyAllocator>::destroy(keyAllocator, std::to_address(keys) + index);
864 if (newBucketExtent > bucketExtent) {
865 bucketExtents[bucketBegin] =
static_cast<std::uint32_t
>(newBucketExtent);
870 return {
iterator{
this, index},
true};
877 const size_type bucketBegin = getBucketIndexOfHash(hash(keys[index]));
878 size_type bucketExtent = bucketExtents[bucketBegin];
879 size_type bucketEnd = getWrappedIndex(bucketBegin + bucketExtent);
884 KeyAllocator keyAllocator = allocator;
885 ValueAllocator valueAllocator = allocator;
886 std::allocator_traits<ValueAllocator>::destroy(valueAllocator, std::to_address(values) + index);
887 std::allocator_traits<KeyAllocator>::destroy(keyAllocator, std::to_address(keys) + index);
891 if (getWrappedIndex(index + 1) == bucketEnd) {
894 while (bucketExtent > 0) {
895 const size_type previousIndex = getWrappedIndex(bucketEnd - 1);
896 if (isActive(previousIndex)) {
900 bucketEnd = previousIndex;
902 bucketExtents[bucketBegin] =
static_cast<std::uint32_t
>(bucketExtent);
905 return findActiveIndexUnbounded(index + 1);
908 template <
typename K>
909 [[nodiscard]]
size_type eraseKey(
const K& k) {
914 const size_type bucketBegin = getBucketIndexOfHash(hash(k));
915 size_type bucketExtent = bucketExtents[bucketBegin];
916 size_type bucketEnd = getWrappedIndex(bucketBegin + bucketExtent);
918 while (index != bucketEnd && (!isActive(index) || !equal(keys[index], k))) {
919 index = getWrappedIndex(index + 1);
921 if (index == bucketEnd) {
928 KeyAllocator keyAllocator = allocator;
929 ValueAllocator valueAllocator = allocator;
930 std::allocator_traits<ValueAllocator>::destroy(valueAllocator, std::to_address(values) + index);
931 std::allocator_traits<KeyAllocator>::destroy(keyAllocator, std::to_address(keys) + index);
935 if (getWrappedIndex(index + 1) == bucketEnd) {
938 while (bucketExtent > 0) {
939 const size_type previousIndex = getWrappedIndex(bucketEnd - 1);
940 if (isActive(previousIndex)) {
944 bucketEnd = previousIndex;
946 bucketExtents[bucketBegin] =
static_cast<std::uint32_t
>(bucketExtent);
952 template <
typename K>
953 [[nodiscard]]
size_type findIndex(
const K& k)
const {
955 const size_type bucketBegin = getBucketIndexOfHash(hash(k));
956 const size_type bucketExtent = bucketExtents[bucketBegin];
957 const size_type bucketEnd = getWrappedIndex(bucketBegin + bucketExtent);
959 while (index != bucketEnd && (!isActive(index) || !equal(keys[index], k))) {
960 index = getWrappedIndex(index + 1);
962 if (index != bucketEnd) {
966 return elementCapacity;
969 typename std::allocator_traits<UInt64Allocator>::pointer activeBits{};
970 typename std::allocator_traits<UInt32Allocator>::pointer bucketExtents{};
971 typename std::allocator_traits<KeyAllocator>::pointer keys{};
972 typename std::allocator_traits<ValueAllocator>::pointer values{};
975 [[no_unique_address]]
hasher hash;
977 [[no_unique_address]] Allocator allocator;
984template <
typename Key,
typename T,
typename Hash = std::hash<Key>,
typename KeyEqual = std::equal_to<Key>>
#define GREM_ASSERT(expression)
Definition assertions.hpp:77
Definition HashMap.hpp:30
KeyEqual key_equal
Definition HashMap.hpp:42
std::size_t size_type
Definition HashMap.hpp:40
constexpr hasher hash_function() const
Definition HashMap.hpp:530
constexpr HashMap(std::initializer_list< value_type > ilist, size_type bucket_count, const Hash &hash=Hash(), const Allocator &allocator=Allocator())
Definition HashMap.hpp:177
constexpr size_type count(const K &x) const
Definition HashMap.hpp:622
constexpr HashMap & operator=(HashMap &&other) noexcept
Definition HashMap.hpp:279
friend constexpr void swap(HashMap &a, HashMap &b) noexcept(noexcept(a.swap(b)))
Definition HashMap.hpp:341
constexpr bool operator==(const HashMap &other) const
Definition HashMap.hpp:724
constexpr Pair< iterator, bool > insert(P &&value)
Definition HashMap.hpp:425
constexpr HashMap(std::initializer_list< value_type > ilist, size_type bucket_count=0, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &allocator=Allocator())
Definition HashMap.hpp:170
constexpr const_iterator begin() const noexcept
Definition HashMap.hpp:704
constexpr size_type erase(K &&x)
Definition HashMap.hpp:512
constexpr HashMap(InputIterator first, Sentinel last, size_type bucket_count=0, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &allocator=Allocator())
Definition HashMap.hpp:156
constexpr const_iterator find(const K &x) const
Definition HashMap.hpp:640
constexpr ~HashMap()
Definition HashMap.hpp:225
constexpr void insert(InputIterator first, Sentinel last)
Definition HashMap.hpp:430
constexpr Pair< iterator, iterator > equal_range(const Key &key)
Definition HashMap.hpp:666
constexpr HashMap & operator=(const HashMap &other)
Definition HashMap.hpp:229
constexpr bool operator>=(const HashMap &other) const
Definition HashMap.hpp:740
Allocator allocator_type
Definition HashMap.hpp:43
constexpr HashMap(InputIterator first, Sentinel last, size_type bucket_count, const Hash &hash, const Allocator &allocator)
Definition HashMap.hpp:167
constexpr T & operator[](K &&x)
Definition HashMap.hpp:604
T mapped_type
Definition HashMap.hpp:39
constexpr size_type max_size() const noexcept
Definition HashMap.hpp:550
constexpr Pair< iterator, bool > insert_or_assign(const Key &k, M &&obj)
Definition HashMap.hpp:470
constexpr HashMap(std::initializer_list< value_type > ilist, size_type bucket_count, const Allocator &allocator=Allocator())
Definition HashMap.hpp:174
constexpr Pair< iterator, bool > insert_or_assign(K &&k, M &&obj)
Definition HashMap.hpp:488
constexpr HashMap(size_type bucket_count, const Allocator &allocator)
Definition HashMap.hpp:146
typename const_iterator::pointer const_pointer
Definition HashMap.hpp:136
constexpr const T & at(const Key &key) const
Definition HashMap.hpp:572
constexpr bool contains(const K &x) const
Definition HashMap.hpp:613
constexpr const_iterator cend() const noexcept
Definition HashMap.hpp:720
constexpr size_type erase(const Key &key)
Definition HashMap.hpp:507
constexpr void insert_range(R &&r)
Definition HashMap.hpp:444
constexpr void insert(std::initializer_list< value_type > ilist)
Definition HashMap.hpp:439
constexpr key_equal key_eq() const
Definition HashMap.hpp:534
constexpr bool operator<=(const HashMap &other) const
Definition HashMap.hpp:732
constexpr const T & at(const K &key) const
Definition HashMap.hpp:588
constexpr size_type size() const noexcept
Definition HashMap.hpp:546
constexpr Pair< iterator, bool > try_emplace(const Key &k, Args &&... args)
Definition HashMap.hpp:454
constexpr iterator end() noexcept
Definition HashMap.hpp:712
constexpr T & operator[](Key &&key)
Definition HashMap.hpp:599
constexpr HashMap(const HashMap &other, const Allocator &allocator)
Definition HashMap.hpp:183
constexpr const_iterator end() const noexcept
Definition HashMap.hpp:716
constexpr HashMap(HashMap &&other, const Allocator &allocator) noexcept
Definition HashMap.hpp:199
constexpr const_reference getAtIndex(size_type index) const
Definition HashMap.hpp:660
constexpr HashMap(const HashMap &other)
Definition HashMap.hpp:180
Hash hasher
Definition HashMap.hpp:41
constexpr void swap(HashMap &other) noexcept(std::allocator_traits< Allocator >::is_always_equal::value)
Definition HashMap.hpp:321
constexpr bool empty() const noexcept
Definition HashMap.hpp:542
typename iterator::difference_type difference_type
Definition HashMap.hpp:137
constexpr Pair< iterator, iterator > equal_range(const K &x)
Definition HashMap.hpp:683
friend constexpr size_type erase_if(HashMap &c, Predicate predicate)
Definition HashMap.hpp:517
constexpr T & operator[](const Key &key)
Definition HashMap.hpp:595
constexpr void clear() noexcept
Definition HashMap.hpp:345
constexpr bool operator<(const HashMap &other) const
Definition HashMap.hpp:728
constexpr bool contains(const Key &key) const
Definition HashMap.hpp:608
constexpr Pair< const_iterator, const_iterator > equal_range(const K &x) const
Definition HashMap.hpp:692
constexpr HashMap() noexcept=default
constexpr allocator_type get_allocator() const noexcept
Definition HashMap.hpp:538
constexpr void reserve(size_type capacity)
Definition HashMap.hpp:361
constexpr iterator erase(const_iterator pos)
Definition HashMap.hpp:496
constexpr HashMap(const Allocator &allocator)
Definition HashMap.hpp:152
constexpr const_iterator find(const Key &key) const
Definition HashMap.hpp:630
constexpr Pair< iterator, bool > try_emplace(K &&k, Args &&... args)
Definition HashMap.hpp:464
constexpr T & at(const K &key)
Definition HashMap.hpp:580
constexpr HashMap(InputIterator first, Sentinel last, size_type bucket_count, const Allocator &allocator)
Definition HashMap.hpp:163
constexpr Pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition HashMap.hpp:674
constexpr Pair< iterator, bool > emplace(Args &&... args)
Definition HashMap.hpp:449
constexpr bool operator>(const HashMap &other) const
Definition HashMap.hpp:736
constexpr iterator find(const Key &key)
Definition HashMap.hpp:626
constexpr HashMap(HashMap &&other) noexcept
Definition HashMap.hpp:188
constexpr Pair< iterator, bool > try_emplace(Key &&k, Args &&... args)
Definition HashMap.hpp:459
constexpr HashMap(size_type bucket_count, const Hash &hash, const Allocator &allocator)
Definition HashMap.hpp:149
Iterator< true > const_iterator
Definition HashMap.hpp:131
constexpr T & at(const Key &key)
Definition HashMap.hpp:565
constexpr size_type count(const Key &key) const
Definition HashMap.hpp:617
constexpr iterator getIteratorAtIndex(size_type index)
Definition HashMap.hpp:644
constexpr iterator find(const K &x)
Definition HashMap.hpp:635
Iterator< false > iterator
Definition HashMap.hpp:130
constexpr const_iterator cbegin() const noexcept
Definition HashMap.hpp:708
constexpr iterator begin() noexcept
Definition HashMap.hpp:700
constexpr const_iterator getIteratorAtIndex(size_type index) const
Definition HashMap.hpp:649
Key key_type
Definition HashMap.hpp:38
constexpr Pair< iterator, bool > insert(value_type &&value)
Definition HashMap.hpp:420
typename iterator::value_type value_type
Definition HashMap.hpp:132
constexpr reference getAtIndex(size_type index)
Definition HashMap.hpp:654
constexpr Pair< iterator, bool > insert_or_assign(Key &&k, M &&obj)
Definition HashMap.hpp:479
typename iterator::reference reference
Definition HashMap.hpp:133
constexpr Pair< iterator, bool > insert(const value_type &value)
Definition HashMap.hpp:416
typename const_iterator::reference const_reference
Definition HashMap.hpp:134
constexpr HashMap & operator=(std::initializer_list< value_type > ilist)
Definition HashMap.hpp:315
constexpr iterator erase(const_iterator first, const_iterator last)
Definition HashMap.hpp:500
Definition concepts.hpp:106
@ K
'k'
Definition keyboard.hpp:81
Definition aliases.hpp:18
Definition Allocation.hpp:554
grem::HashMap< Key, T, Hash, KeyEqual, std::pmr::polymorphic_allocator< Pair< const Key, T > > > HashMap
Definition HashMap.hpp:985
constexpr bool equal(input_range auto &&rangeA, input_range auto &&rangeB)
Definition algorithms.hpp:358
Pair(T1, T2) -> Pair< T1, T2 >
Definition HashMap.hpp:57
reference ref
Definition HashMap.hpp:58
constexpr reference * operator->() noexcept
Definition HashMap.hpp:60