24 #ifndef PXR_TSL_ROBIN_MAP_H
25 #define PXR_TSL_ROBIN_MAP_H
29 #include <initializer_list>
31 #include <type_traits>
91 template <
class Key,
class T,
class Hash = std::hash<Key>,
92 class KeyEqual = std::equal_to<Key>,
93 class Allocator = std::allocator<std::pair<Key, T>>,
94 bool StoreHash = false,
95 class GrowthPolicy = pxr_tsl::rh::power_of_two_growth_policy<2>>
105 const key_type& operator()(
const std::pair<Key, T>& key_value)
const
107 return key_value.first;
110 key_type& operator()(std::pair<Key, T>& key_value) noexcept {
111 return key_value.first;
119 const value_type& operator()(
const std::pair<Key, T>& key_value)
const
121 return key_value.second;
124 value_type& operator()(std::pair<Key, T>& key_value) noexcept {
125 return key_value.second;
130 ValueSelect,
Hash, KeyEqual,
131 Allocator, StoreHash, GrowthPolicy>;
156 const KeyEqual&
equal = KeyEqual(),
157 const Allocator& alloc = Allocator())
158 : m_ht(bucket_count, hash,
equal, alloc) {}
164 :
robin_map(bucket_count, hash, KeyEqual(), alloc) {}
167 :
robin_map(
ht::DEFAULT_INIT_BUCKETS_SIZE, alloc) {}
169 template <
class InputIt>
172 const Hash& hash =
Hash(),
const KeyEqual&
equal = KeyEqual(),
173 const Allocator& alloc = Allocator())
178 template <
class InputIt>
180 const Allocator& alloc)
181 :
robin_map(first, last, bucket_count,
Hash(), KeyEqual(), alloc) {}
183 template <
class InputIt>
185 const Hash& hash,
const Allocator& alloc)
186 :
robin_map(first, last, bucket_count, hash, KeyEqual(), alloc) {}
190 const Hash& hash =
Hash(),
const KeyEqual&
equal = KeyEqual(),
191 const Allocator& alloc = Allocator())
195 const Allocator& alloc)
200 const Hash& hash,
const Allocator& alloc)
208 m_ht.
insert(ilist.begin(), ilist.end());
239 return m_ht.
insert(value);
242 template <
class P,
typename std::enable_if<std::is_constructible<
256 template <
class P,
typename std::enable_if<std::is_constructible<
266 template <
class InputIt>
267 void insert(InputIt first, InputIt last) {
271 void insert(std::initializer_list<value_type> ilist) {
272 m_ht.
insert(ilist.begin(), ilist.end());
302 template <
class... Args>
314 template <
class... Args>
319 template <
class... Args>
324 template <
class... Args>
329 template <
class... Args>
334 template <
class... Args>
337 std::forward<Args>(
args)...);
343 return m_ht.
erase(first, last);
353 return m_ht.
erase(key, precalculated_hash);
362 class K,
class KE = KeyEqual,
365 return m_ht.
erase(key);
376 class K,
class KE = KeyEqual,
379 return m_ht.
erase(key, precalculated_hash);
387 T&
at(
const Key& key) {
return m_ht.
at(key); }
394 T&
at(
const Key& key, std::size_t precalculated_hash) {
395 return m_ht.
at(key, precalculated_hash);
398 const T&
at(
const Key& key)
const {
return m_ht.
at(key); }
403 const T&
at(
const Key& key, std::size_t precalculated_hash)
const {
404 return m_ht.
at(key, precalculated_hash);
413 class K,
class KE = KeyEqual,
427 class K,
class KE = KeyEqual,
429 T&
at(
const K& key, std::size_t precalculated_hash) {
430 return m_ht.
at(key, precalculated_hash);
437 class K,
class KE = KeyEqual,
439 const T&
at(
const K& key)
const {
447 class K,
class KE = KeyEqual,
449 const T&
at(
const K& key, std::size_t precalculated_hash)
const {
450 return m_ht.
at(key, precalculated_hash);
464 return m_ht.
count(key, precalculated_hash);
473 class K,
class KE = KeyEqual,
476 return m_ht.
count(key);
487 class K,
class KE = KeyEqual,
490 return m_ht.
count(key, precalculated_hash);
501 return m_ht.
find(key, precalculated_hash);
510 return m_ht.
find(key, precalculated_hash);
519 class K,
class KE = KeyEqual,
522 return m_ht.
find(key);
533 class K,
class KE = KeyEqual,
536 return m_ht.
find(key, precalculated_hash);
543 class K,
class KE = KeyEqual,
546 return m_ht.
find(key);
557 class K,
class KE = KeyEqual,
560 return m_ht.
find(key, precalculated_hash);
570 bool contains(
const Key& key, std::size_t precalculated_hash)
const {
571 return m_ht.
contains(key, precalculated_hash);
580 class K,
class KE = KeyEqual,
594 class K,
class KE = KeyEqual,
596 bool contains(
const K& key, std::size_t precalculated_hash)
const {
597 return m_ht.
contains(key, precalculated_hash);
610 std::size_t precalculated_hash) {
614 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
622 const Key& key, std::size_t precalculated_hash)
const {
632 class K,
class KE = KeyEqual,
646 class K,
class KE = KeyEqual,
649 std::size_t precalculated_hash) {
657 class K,
class KE = KeyEqual,
659 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
667 class K,
class KE = KeyEqual,
670 const K& key, std::size_t precalculated_hash)
const {
733 template <
class Serializer>
764 template <
class Deserializer>
766 bool hash_compatible =
false) {
768 map.m_ht.
deserialize(deserializer, hash_compatible);
778 for (
const auto& element_lhs : lhs) {
779 const auto it_element_rhs = rhs.
find(element_lhs.first);
780 if (it_element_rhs == rhs.
cend() ||
781 element_lhs.second != it_element_rhs->second) {
803 template <
class Key,
class T,
class Hash = std::hash<Key>,
804 class KeyEqual = std::equal_to<Key>,
805 class Allocator = std::allocator<std::pair<Key, T>>,
806 bool StoreHash = false>
iterator insert(const_iterator hint, P &&value)
bool contains(const Key &key) const
iterator emplace_hint(const_iterator hint, Args &&...args)
float load_factor() const
T & at(const K &key, std::size_t precalculated_hash)
typename KeySelect::key_type key_type
size_type max_bucket_count() const
iterator try_emplace_hint(const_iterator hint, K &&key, Args &&...args)
size_type erase(const key_type &key, std::size_t precalculated_hash)
robin_map(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
void deserialize(Deserializer &deserializer, bool hash_compatible)
std::pair< iterator, bool > insert(P &&value)
size_type erase(const K &key, std::size_t precalculated_hash)
iterator find(const Key &key, std::size_t precalculated_hash)
iterator emplace_hint(const_iterator hint, Args &&...args)
const T & at(const K &key, std::size_t precalculated_hash) const
iterator erase(const_iterator pos)
STATIC_INLINE size_t Hash(const char *s, size_t len)
std::pair< iterator, bool > insert_or_assign(K &&key, M &&obj)
std::pair< iterator, bool > emplace(Args &&...args)
std::pair< iterator, iterator > equal_range(const K &key)
bool contains(const K &key, std::size_t precalculated_hash) const
hasher hash_function() const
bool contains(const K &key) const
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
GLsizei const GLfloat * value
const_iterator find(const Key &key, std::size_t precalculated_hash) const
iterator mutable_iterator(const_iterator pos)
float max_load_factor() const
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
T & operator[](const Key &key)
size_type count(const Key &key) const
void swap(robin_hash &other)
robin_map(std::initializer_list< value_type > init, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
size_type erase(const key_type &key)
void serialize(Serializer &serializer) const
const_iterator find(const K &key, std::size_t precalculated_hash) const
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
std::pair< iterator, iterator > equal_range(const K &key)
bool contains(const K &key) const
iterator find(const K &key, std::size_t precalculated_hash)
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
void rehash(size_type count_)
size_type count(const Key &key, std::size_t precalculated_hash) const
size_type erase(const K &key)
std::pair< iterator, bool > emplace(Args &&...args)
size_type bucket_count() const
iterator insert_hint(const_iterator hint, P &&value)
allocator_type get_allocator() const
float max_load_factor() const
iterator find(const Key &key)
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
size_type count(const K &key) const
friend bool operator==(const robin_map &lhs, const robin_map &rhs)
const T & at(const K &key) const
const_iterator cend() const noexcept
void serialize(Serializer &serializer) const
robin_map(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
typename ht::key_type key_type
typename ht::const_reference const_reference
robin_map(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
std::ptrdiff_t difference_type
iterator try_emplace(const_iterator hint, const key_type &k, Args &&...args)
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
typename ht::value_type value_type
robin_map(size_type bucket_count, const Allocator &alloc)
void reserve(size_type count_)
void max_load_factor(float ml)
robin_map(InputIt first, InputIt last, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
robin_iterator< true > const_iterator
const_iterator find(const Key &key) const
typename ht::key_equal key_equal
const_iterator cend() const noexcept
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
const_iterator find(const K &key) const
typename ht::iterator iterator
bool empty() const noexcept
iterator insert(const_iterator hint, value_type &&value)
std::pair< iterator, bool > insert(P &&value)
typename ht::hasher hasher
size_type max_size() const noexcept
void swap(robin_map &other)
size_type max_size() const noexcept
std::pair< Key, T > value_type
std::pair< iterator, bool > try_emplace(K &&key, Args &&...args)
void rehash(size_type count_)
typename ht::reference reference
friend bool operator!=(const robin_map &lhs, const robin_map &rhs)
bool empty() const noexcept
size_type size() const noexcept
const value_type & const_reference
const_iterator cbegin() const noexcept
void insert(std::initializer_list< value_type > ilist)
size_type count(const K &key) const
robin_map(const Allocator &alloc)
const value_type * const_pointer
iterator find(const K &key)
typename ht::difference_type difference_type
static robin_map deserialize(Deserializer &deserializer, bool hash_compatible=false)
robin_map(size_type bucket_count, const Hash &hash, const Allocator &alloc)
typename ht::const_pointer const_pointer
std::pair< iterator, bool > insert(value_type &&value)
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&...args)
float min_load_factor() const
iterator begin() noexcept
bool contains(const Key &key, std::size_t precalculated_hash) const
__hostdev__ uint64_t last(uint32_t i) const
const_iterator begin() const noexcept
iterator mutable_iterator(const_iterator pos)
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&...args)
iterator erase(iterator pos)
typename ht::pointer pointer
float min_load_factor() const
hasher hash_function() const
T & at(const Key &key, std::size_t precalculated_hash)
robin_iterator< false > iterator
std::pair< iterator, iterator > equal_range(const Key &key)
const T & at(const Key &key) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
friend void swap(robin_map &lhs, robin_map &rhs)
std::pair< iterator, bool > insert(const value_type &value)
T & operator[](Key &&key)
const_iterator end() const noexcept
#define PXR_NAMESPACE_CLOSE_SCOPE
iterator erase(const_iterator first, const_iterator last)
void insert(InputIt first, InputIt last)
void min_load_factor(float ml)
**If you just want to fire and args
size_type size() const noexcept
const_iterator cbegin() const noexcept
robin_map & operator=(std::initializer_list< value_type > ilist)
iterator find(const K &key)
typename ht::size_type size_type
U::value_type & at(const K &key)
const T & at(const Key &key, std::size_t precalculated_hash) const
size_type count(const K &key, std::size_t precalculated_hash) const
robin_map(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
float load_factor() const
allocator_type get_allocator() const
robin_map(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
iterator try_emplace(const_iterator hint, key_type &&k, Args &&...args)
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
typename ht::const_iterator const_iterator
std::vector< _OverloadBinderBasePtr > mapped_type
size_type max_bucket_count() const
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
iterator begin() noexcept
static const size_type DEFAULT_INIT_BUCKETS_SIZE
iterator insert(const_iterator hint, const value_type &value)
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
robin_map< Key, T, Hash, KeyEqual, Allocator, StoreHash, pxr_tsl::rh::prime_growth_policy > robin_pg_map
iterator erase(iterator pos)
size_type bucket_count() const
void reserve(size_type count_)
typename ht::allocator_type allocator_type