24 #ifndef PXR_TSL_ROBIN_HASH_H
25 #define PXR_TSL_ROBIN_HASH_H
38 #include <type_traits>
51 namespace detail_robin_hash {
58 template <
typename T,
typename =
void>
69 template <std::
size_t GrowthFactor>
75 const T&
clamp(
const T&
v,
const T& lo,
const T& hi) {
79 template <
typename T,
typename U>
80 static T numeric_cast(U
value,
81 const char* error_message =
"numeric_cast() failed.") {
83 if (static_cast<U>(ret) !=
value) {
87 const bool is_same_signedness =
90 if (!is_same_signedness && (ret < T{}) != (value < U{})) {
97 template <
class T,
class Deserializer>
98 static T deserialize_value(Deserializer& deserializer) {
101 #if defined(_MSC_VER) && _MSC_VER < 1910
102 return deserializer.Deserializer::operator()<
T>();
104 return deserializer.Deserializer::template operator()<
T>();
116 "slz_size_type must be >= std::size_t");
124 template <
bool StoreHash>
171 template <
typename ValueType,
bool StoreHash>
182 m_last_bucket(false) {
197 m_last_bucket(other.m_last_bucket) {
198 if (!other.empty()) {
199 ::new (static_cast<void*>(std::addressof(m_value)))
201 m_dist_from_ideal_bucket = other.m_dist_from_ideal_bucket;
211 std::is_nothrow_move_constructible<
value_type>::value)
214 m_last_bucket(other.m_last_bucket) {
215 if (!other.empty()) {
216 ::new (static_cast<void*>(std::addressof(m_value)))
218 m_dist_from_ideal_bucket = other.m_dist_from_ideal_bucket;
224 if (
this != &other) {
228 if (!other.empty()) {
229 ::new (static_cast<void*>(std::addressof(m_value)))
233 m_dist_from_ideal_bucket = other.m_dist_from_ideal_bucket;
234 m_last_bucket = other.m_last_bucket;
257 return *
reinterpret_cast<value_type*
>(std::addressof(m_value));
262 return *
reinterpret_cast<const value_type*
>(std::addressof(m_value));
266 return m_dist_from_ideal_bucket;
273 template <
typename... Args>
276 Args&&... value_type_args) {
280 ::new (static_cast<void*>(std::addressof(m_value)))
281 value_type(std::forward<Args>(value_type_args)...);
294 swap(dist_from_ideal_bucket, m_dist_from_ideal_bucket);
311 void destroy_value() noexcept {
313 value().~value_type();
321 "DIST_FROM_IDEAL_BUCKET_LIMIT must be <= "
322 "std::numeric_limits<distance_type>::max() - 1.");
325 using storage =
typename std::aligned_storage<
sizeof(
value_type),
352 template <
class ValueType,
class KeySelect,
class ValueSelect,
class Hash,
353 class KeyEqual,
class Allocator,
bool StoreHash,
class GrowthPolicy>
356 template <
typename U>
357 using has_mapped_type =
361 noexcept(std::declval<GrowthPolicy>().bucket_for_hash(std::size_t(0))),
362 "GrowthPolicy::bucket_for_hash must be noexcept.");
363 static_assert(noexcept(std::declval<GrowthPolicy>().
clear()),
364 "GrowthPolicy::clear must be noexcept.");
367 template <
bool IsConst>
390 static constexpr
bool STORE_HASH =
398 !std::is_same<Hash, std::hash<key_type>>
::value));
405 static constexpr
bool USE_STORED_HASH_ON_LOOKUP = StoreHash;
419 return (bucket_count - 1) <=
431 using buckets_allocator =
typename std::allocator_traits<
433 using buckets_container_type = std::vector<bucket_entry, buckets_allocator>;
447 template <
bool IsConst>
448 class robin_iterator {
452 using bucket_entry_ptr =
456 robin_iterator(bucket_entry_ptr bucket) noexcept : m_bucket(bucket) {}
468 template <
bool TIsConst = IsConst,
471 : m_bucket(other.m_bucket) {}
479 return KeySelect()(m_bucket->value());
482 template <
class U = ValueSelect,
484 IsConst>
::type* =
nullptr>
486 return U()(m_bucket->value());
489 template <
class U = ValueSelect,
491 !IsConst>
::type* =
nullptr>
493 return U()(m_bucket->value());
502 if (m_bucket->last_bucket()) {
508 if (!m_bucket->empty()) {
523 return lhs.m_bucket == rhs.m_bucket;
528 return !(lhs == rhs);
532 bucket_entry_ptr m_bucket;
536 #if defined(__cplusplus) && __cplusplus >= 201402L
538 const Allocator& alloc,
543 GrowthPolicy(bucket_count),
549 "The map exceeds its maximum bucket count.");
555 m_buckets(m_buckets_data.empty() ? static_empty_bucket_ptr()
556 : m_buckets_data.
data()),
557 m_bucket_count(bucket_count),
559 m_grow_on_next_insert(false),
560 m_try_shrink_on_next_insert(false) {
561 if (m_bucket_count > 0) {
563 m_buckets_data.back().set_as_last_bucket();
581 const Allocator& alloc,
586 GrowthPolicy(bucket_count),
587 m_buckets_data(alloc),
588 m_buckets(static_empty_bucket_ptr()),
589 m_bucket_count(bucket_count),
591 m_grow_on_next_insert(false),
592 m_try_shrink_on_next_insert(false) {
595 "The map exceeds its maximum bucket count.");
598 if (m_bucket_count > 0) {
599 m_buckets_data.resize(m_bucket_count);
600 m_buckets = m_buckets_data.data();
603 m_buckets_data.back().set_as_last_bucket();
615 m_buckets_data(other.m_buckets_data),
616 m_buckets(m_buckets_data.
empty() ? static_empty_bucket_ptr()
617 : m_buckets_data.
data()),
618 m_bucket_count(other.m_bucket_count),
619 m_nb_elements(other.m_nb_elements),
620 m_load_threshold(other.m_load_threshold),
621 m_min_load_factor(other.m_min_load_factor),
622 m_max_load_factor(other.m_max_load_factor),
623 m_grow_on_next_insert(other.m_grow_on_next_insert),
624 m_try_shrink_on_next_insert(other.m_try_shrink_on_next_insert) {}
627 std::is_nothrow_move_constructible<
628 Hash>::value&& std::is_nothrow_move_constructible<KeyEqual>::value&&
629 std::is_nothrow_move_constructible<GrowthPolicy>::value&&
630 std::is_nothrow_move_constructible<buckets_container_type>::value)
631 :
Hash(std::move(static_cast<
Hash&>(other))),
632 KeyEqual(std::move(static_cast<KeyEqual&>(other))),
633 GrowthPolicy(std::move(static_cast<GrowthPolicy&>(other))),
634 m_buckets_data(std::move(other.m_buckets_data)),
635 m_buckets(m_buckets_data.
empty() ? static_empty_bucket_ptr()
636 : m_buckets_data.
data()),
637 m_bucket_count(other.m_bucket_count),
638 m_nb_elements(other.m_nb_elements),
639 m_load_threshold(other.m_load_threshold),
640 m_min_load_factor(other.m_min_load_factor),
641 m_max_load_factor(other.m_max_load_factor),
642 m_grow_on_next_insert(other.m_grow_on_next_insert),
643 m_try_shrink_on_next_insert(other.m_try_shrink_on_next_insert) {
644 other.clear_and_shrink();
648 if (&other !=
this) {
653 m_buckets_data = other.m_buckets_data;
654 m_buckets = m_buckets_data.empty() ? static_empty_bucket_ptr()
655 : m_buckets_data.data();
656 m_bucket_count = other.m_bucket_count;
657 m_nb_elements = other.m_nb_elements;
659 m_load_threshold = other.m_load_threshold;
660 m_min_load_factor = other.m_min_load_factor;
661 m_max_load_factor = other.m_max_load_factor;
663 m_grow_on_next_insert = other.m_grow_on_next_insert;
664 m_try_shrink_on_next_insert = other.m_try_shrink_on_next_insert;
678 return m_buckets_data.get_allocator();
686 while (i < m_bucket_count && m_buckets[i].
empty()) {
697 while (i < m_bucket_count && m_buckets[i].
empty()) {
715 bool empty() const noexcept {
return m_nb_elements == 0; }
725 if (m_min_load_factor > 0.0
f) {
728 for (
auto& bucket : m_buckets_data) {
733 m_grow_on_next_insert =
false;
737 template <
typename P>
739 return insert_impl(KeySelect()(value), std::forward<P>(value));
742 template <
typename P>
744 if (hint !=
cend() &&
745 compare_keys(KeySelect()(*hint), KeySelect()(value))) {
749 return insert(std::forward<P>(value)).first;
752 template <
class InputIt>
755 std::forward_iterator_tag,
756 typename std::iterator_traits<InputIt>::iterator_category>::value) {
761 if (nb_elements_insert > 0 &&
762 nb_free_buckets <
size_type(nb_elements_insert)) {
772 template <
class K,
class M>
774 auto it =
try_emplace(std::forward<K>(key), std::forward<M>(obj));
776 it.first.value() = std::forward<M>(obj);
782 template <
class K,
class M>
784 if (hint !=
cend() && compare_keys(KeySelect()(*hint), key)) {
786 it.value() = std::forward<M>(obj);
794 template <
class... Args>
799 template <
class... Args>
804 template <
class K,
class... Args>
806 return insert_impl(key, std::piecewise_construct,
807 std::forward_as_tuple(std::forward<K>(key)),
808 std::forward_as_tuple(std::forward<Args>(
args)...));
811 template <
class K,
class... Args>
813 if (hint !=
cend() && compare_keys(KeySelect()(*hint), key)) {
817 return try_emplace(std::forward<K>(key), std::forward<Args>(
args)...).first;
825 erase_from_bucket(pos);
832 if (pos.m_bucket->empty()) {
836 m_try_shrink_on_next_insert =
true;
850 for (
auto it = first_mutable.m_bucket; it != last_mutable.m_bucket; ++it) {
857 if (last_mutable ==
end()) {
858 m_try_shrink_on_next_insert =
true;
866 std::size_t icloser_bucket =
867 static_cast<std::size_t
>(first_mutable.m_bucket - m_buckets);
868 std::size_t ito_move_closer_value =
869 static_cast<std::size_t
>(last_mutable.m_bucket - m_buckets);
872 const std::size_t ireturn_bucket =
873 ito_move_closer_value -
875 ito_move_closer_value - icloser_bucket,
877 m_buckets[ito_move_closer_value].dist_from_ideal_bucket()));
879 while (ito_move_closer_value < m_bucket_count &&
880 m_buckets[ito_move_closer_value].dist_from_ideal_bucket() > 0) {
882 ito_move_closer_value -
884 ito_move_closer_value - icloser_bucket,
886 m_buckets[ito_move_closer_value].dist_from_ideal_bucket()));
889 const distance_type new_distance = distance_type(
890 m_buckets[ito_move_closer_value].dist_from_ideal_bucket() -
891 (ito_move_closer_value - icloser_bucket));
893 new_distance, m_buckets[ito_move_closer_value].truncated_hash(),
894 std::move(m_buckets[ito_move_closer_value].
value()));
895 m_buckets[ito_move_closer_value].
clear();
898 ++ito_move_closer_value;
901 m_try_shrink_on_next_insert =
true;
903 return iterator(m_buckets + ireturn_bucket);
908 return erase(key, hash_key(key));
913 auto it =
find(key, hash);
915 erase_from_bucket(it);
916 m_try_shrink_on_next_insert =
true;
927 swap(static_cast<Hash&>(*
this), static_cast<Hash&>(other));
928 swap(static_cast<KeyEqual&>(*
this), static_cast<KeyEqual&>(other));
929 swap(static_cast<GrowthPolicy&>(*
this), static_cast<GrowthPolicy&>(other));
930 swap(m_buckets_data, other.m_buckets_data);
931 swap(m_buckets, other.m_buckets);
932 swap(m_bucket_count, other.m_bucket_count);
933 swap(m_nb_elements, other.m_nb_elements);
934 swap(m_load_threshold, other.m_load_threshold);
935 swap(m_min_load_factor, other.m_min_load_factor);
936 swap(m_max_load_factor, other.m_max_load_factor);
937 swap(m_grow_on_next_insert, other.m_grow_on_next_insert);
938 swap(m_try_shrink_on_next_insert, other.m_try_shrink_on_next_insert);
944 template <
class K,
class U = ValueSelect,
947 return at(key, hash_key(key));
950 template <
class K,
class U = ValueSelect,
957 template <
class K,
class U = ValueSelect,
960 return at(key, hash_key(key));
963 template <
class K,
class U = ValueSelect,
966 auto it =
find(key, hash);
974 template <
class K,
class U = ValueSelect,
977 return try_emplace(std::forward<K>(key)).first.value();
982 return count(key, hash_key(key));
996 return find_impl(key, hash_key(key));
1001 return find_impl(key, hash);
1006 return find_impl(key, hash_key(key));
1011 return find_impl(key, hash);
1016 return contains(key, hash_key(key));
1021 return count(key, hash) != 0;
1030 std::pair<iterator, iterator>
equal_range(
const K& key, std::size_t hash) {
1032 return std::make_pair(it, (it ==
end()) ? it : std::next(it));
1036 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
1042 const K& key, std::size_t hash)
const {
1044 return std::make_pair(it, (it ==
cend()) ? it : std::next(it));
1053 return std::min(GrowthPolicy::max_bucket_count(),
1054 m_buckets_data.max_size());
1086 rehash_impl(count_);
1104 return iterator(const_cast<bucket_entry*>(pos.m_bucket));
1107 template <
class Serializer>
1109 serialize_impl(serializer);
1112 template <
class Deserializer>
1114 deserialize_impl(deserializer, hash_compatible);
1119 std::size_t hash_key(
const K& key)
const {
1120 return Hash::operator()(key);
1123 template <
class K1,
class K2>
1124 bool compare_keys(
const K1& key1,
const K2& key2)
const {
1125 return KeyEqual::operator()(key1, key2);
1128 std::size_t bucket_for_hash(std::size_t hash)
const {
1129 const std::size_t bucket = GrowthPolicy::bucket_for_hash(hash);
1131 (bucket == 0 && m_bucket_count == 0));
1136 template <
class U = GrowthPolicy,
1139 std::size_t next_bucket(std::size_t
index)
const noexcept {
1142 return (
index + 1) & this->m_mask;
1145 template <
class U = GrowthPolicy,
1148 std::size_t next_bucket(std::size_t
index)
const noexcept {
1156 iterator find_impl(
const K& key, std::size_t hash) {
1158 static_cast<const robin_hash*>(
this)->
find(key, hash));
1163 std::size_t ibucket = bucket_for_hash(hash);
1164 distance_type dist_from_ideal_bucket = 0;
1166 while (dist_from_ideal_bucket <=
1167 m_buckets[ibucket].dist_from_ideal_bucket()) {
1169 (!USE_STORED_HASH_ON_LOOKUP ||
1170 m_buckets[ibucket].bucket_hash_equal(hash)) &&
1171 compare_keys(KeySelect()(m_buckets[ibucket].
value()), key))) {
1175 ibucket = next_bucket(ibucket);
1176 dist_from_ideal_bucket++;
1182 void erase_from_bucket(
iterator pos) {
1183 pos.m_bucket->clear();
1193 std::size_t previous_ibucket =
1194 static_cast<std::size_t
>(pos.m_bucket - m_buckets);
1195 std::size_t ibucket = next_bucket(previous_ibucket);
1197 while (m_buckets[ibucket].dist_from_ideal_bucket() > 0) {
1200 const distance_type new_distance =
1201 distance_type(m_buckets[ibucket].dist_from_ideal_bucket() - 1);
1203 new_distance, m_buckets[ibucket].truncated_hash(),
1204 std::move(m_buckets[ibucket].
value()));
1205 m_buckets[ibucket].
clear();
1207 previous_ibucket = ibucket;
1208 ibucket = next_bucket(ibucket);
1212 template <
class K,
class... Args>
1213 std::pair<iterator, bool> insert_impl(
const K& key,
1214 Args&&... value_type_args) {
1215 const std::size_t hash = hash_key(key);
1217 std::size_t ibucket = bucket_for_hash(hash);
1218 distance_type dist_from_ideal_bucket = 0;
1220 while (dist_from_ideal_bucket <=
1221 m_buckets[ibucket].dist_from_ideal_bucket()) {
1222 if ((!USE_STORED_HASH_ON_LOOKUP ||
1223 m_buckets[ibucket].bucket_hash_equal(hash)) &&
1224 compare_keys(KeySelect()(m_buckets[ibucket].
value()), key)) {
1225 return std::make_pair(
iterator(m_buckets + ibucket),
false);
1228 ibucket = next_bucket(ibucket);
1229 dist_from_ideal_bucket++;
1232 if (rehash_on_extreme_load()) {
1233 ibucket = bucket_for_hash(hash);
1234 dist_from_ideal_bucket = 0;
1236 while (dist_from_ideal_bucket <=
1237 m_buckets[ibucket].dist_from_ideal_bucket()) {
1238 ibucket = next_bucket(ibucket);
1239 dist_from_ideal_bucket++;
1243 if (m_buckets[ibucket].
empty()) {
1246 std::forward<Args>(value_type_args)...);
1248 insert_value(ibucket, dist_from_ideal_bucket,
1250 std::forward<Args>(value_type_args)...);
1258 return std::make_pair(
iterator(m_buckets + ibucket),
true);
1261 template <
class... Args>
1262 void insert_value(std::size_t ibucket, distance_type dist_from_ideal_bucket,
1265 insert_value_impl(ibucket, dist_from_ideal_bucket, hash, value);
1268 void insert_value(std::size_t ibucket, distance_type dist_from_ideal_bucket,
1270 insert_value_impl(ibucket, dist_from_ideal_bucket, hash, value);
1281 void insert_value_impl(std::size_t ibucket,
1282 distance_type dist_from_ideal_bucket,
1286 ibucket = next_bucket(ibucket);
1287 dist_from_ideal_bucket++;
1289 while (!m_buckets[ibucket].
empty()) {
1290 if (dist_from_ideal_bucket >
1291 m_buckets[ibucket].dist_from_ideal_bucket()) {
1292 if (dist_from_ideal_bucket >=
1298 m_grow_on_next_insert =
true;
1305 ibucket = next_bucket(ibucket);
1306 dist_from_ideal_bucket++;
1314 robin_hash new_table(count_, static_cast<Hash&>(*
this),
1316 m_min_load_factor, m_max_load_factor);
1318 const bool use_stored_hash =
1319 USE_STORED_HASH_ON_REHASH(new_table.bucket_count());
1320 for (
auto& bucket : m_buckets_data) {
1321 if (bucket.empty()) {
1325 const std::size_t hash =
1326 use_stored_hash ? bucket.truncated_hash()
1327 : new_table.hash_key(KeySelect()(bucket.value()));
1329 new_table.insert_value_on_rehash(new_table.bucket_for_hash(hash), 0,
1331 std::move(bucket.value()));
1334 new_table.m_nb_elements = m_nb_elements;
1335 new_table.swap(*
this);
1338 void clear_and_shrink() noexcept {
1339 GrowthPolicy::clear();
1340 m_buckets_data.clear();
1341 m_buckets = static_empty_bucket_ptr();
1344 m_load_threshold = 0;
1345 m_grow_on_next_insert =
false;
1346 m_try_shrink_on_next_insert =
false;
1349 void insert_value_on_rehash(std::size_t ibucket,
1350 distance_type dist_from_ideal_bucket,
1353 if (dist_from_ideal_bucket >
1354 m_buckets[ibucket].dist_from_ideal_bucket()) {
1355 if (m_buckets[ibucket].
empty()) {
1357 hash, std::move(value));
1365 dist_from_ideal_bucket++;
1366 ibucket = next_bucket(ibucket);
1377 bool rehash_on_extreme_load() {
1378 if (m_grow_on_next_insert ||
size() >= m_load_threshold) {
1379 rehash_impl(GrowthPolicy::next_bucket_count());
1380 m_grow_on_next_insert =
false;
1385 if (m_try_shrink_on_next_insert) {
1386 m_try_shrink_on_next_insert =
false;
1387 if (m_min_load_factor != 0.0
f &&
load_factor() < m_min_load_factor) {
1397 template <
class Serializer>
1398 void serialize_impl(Serializer& serializer)
const {
1400 serializer(version);
1405 const std::int16_t hash_stored_for_bucket =
1406 static_cast<std::int16_t
>(STORE_HASH);
1407 serializer(hash_stored_for_bucket);
1410 serializer(nb_elements);
1413 serializer(bucket_count);
1416 serializer(min_load_factor);
1419 serializer(max_load_factor);
1421 for (
const bucket_entry& bucket : m_buckets_data) {
1422 if (bucket.empty()) {
1423 const std::int16_t empty_bucket =
1425 serializer(empty_bucket);
1427 const std::int16_t dist_from_ideal_bucket =
1428 bucket.dist_from_ideal_bucket();
1429 serializer(dist_from_ideal_bucket);
1431 const std::uint32_t truncated_hash = bucket.truncated_hash();
1432 serializer(truncated_hash);
1434 serializer(bucket.value());
1439 template <
class Deserializer>
1440 void deserialize_impl(Deserializer& deserializer,
bool hash_compatible) {
1444 deserialize_value<slz_size_type>(deserializer);
1447 if (version != SERIALIZATION_PROTOCOL_VERSION) {
1449 "Can't deserialize the ordered_map/set. "
1450 "The protocol version header is invalid.");
1453 const bool hash_stored_for_bucket =
1454 deserialize_value<std::int16_t>(deserializer) ?
true :
false;
1455 if (hash_compatible && STORE_HASH != hash_stored_for_bucket) {
1458 "Can't deserialize a map with a different StoreHash "
1459 "than the one used during the serialization when "
1460 "hash compatibility is used");
1464 deserialize_value<slz_size_type>(deserializer);
1466 deserialize_value<slz_size_type>(deserializer);
1467 const float min_load_factor = deserialize_value<float>(deserializer);
1468 const float max_load_factor = deserialize_value<float>(deserializer);
1474 "Invalid min_load_factor. Check that the serializer "
1475 "and deserializer support floats correctly as they "
1476 "can be converted implicitly to ints.");
1483 "Invalid max_load_factor. Check that the serializer "
1484 "and deserializer support floats correctly as they "
1485 "can be converted implicitly to ints.");
1491 if (bucket_count_ds == 0) {
1496 if (!hash_compatible) {
1497 reserve(numeric_cast<size_type>(nb_elements,
1498 "Deserialized nb_elements is too big."));
1499 for (
slz_size_type ibucket = 0; ibucket < bucket_count_ds; ibucket++) {
1500 const distance_type dist_from_ideal_bucket =
1501 deserialize_value<std::int16_t>(deserializer);
1502 if (dist_from_ideal_bucket !=
1504 if (hash_stored_for_bucket) {
1508 insert(deserialize_value<value_type>(deserializer));
1514 m_bucket_count = numeric_cast<
size_type>(
1515 bucket_count_ds,
"Deserialized bucket_count is too big.");
1520 if (m_bucket_count != bucket_count_ds) {
1522 "The GrowthPolicy is not the same even "
1523 "though hash_compatible is true.");
1526 m_nb_elements = numeric_cast<
size_type>(
1527 nb_elements,
"Deserialized nb_elements is too big.");
1528 m_buckets_data.resize(m_bucket_count);
1529 m_buckets = m_buckets_data.data();
1531 for (bucket_entry& bucket : m_buckets_data) {
1532 const distance_type dist_from_ideal_bucket =
1533 deserialize_value<std::int16_t>(deserializer);
1534 if (dist_from_ideal_bucket !=
1537 if (hash_stored_for_bucket) {
1539 truncated_hash = deserialize_value<std::uint32_t>(deserializer);
1542 bucket.set_value_of_empty_bucket(
1543 dist_from_ideal_bucket, truncated_hash,
1544 deserialize_value<value_type>(deserializer));
1548 if (!m_buckets_data.empty()) {
1549 m_buckets_data.back().set_as_last_bucket();
1566 "MINIMUM_MAX_LOAD_FACTOR should be < MAXIMUM_MAX_LOAD_FACTOR");
1568 "MINIMUM_MIN_LOAD_FACTOR should be < MAXIMUM_MIN_LOAD_FACTOR");
1570 "MAXIMUM_MIN_LOAD_FACTOR should be < MINIMUM_MAX_LOAD_FACTOR");
1576 static const slz_size_type SERIALIZATION_PROTOCOL_VERSION = 1;
1584 return &empty_bucket;
1588 buckets_container_type m_buckets_data;
1611 float m_min_load_factor;
1612 float m_max_load_factor;
1614 bool m_grow_on_next_insert;
1623 bool m_try_shrink_on_next_insert;
void set_hash(truncated_hash_type) noexcept
iterator insert_or_assign(const_iterator hint, K &&key, M &&obj)
static const distance_type EMPTY_MARKER_DIST_FROM_IDEAL_BUCKET
static truncated_hash_type truncate_hash(std::size_t hash) noexcept
iterator emplace_hint(const_iterator hint, Args &&...args)
float load_factor() const
typename KeySelect::key_type key_type
size_type max_bucket_count() const
robin_iterator & operator=(const robin_iterator &other)=default
iterator try_emplace_hint(const_iterator hint, K &&key, Args &&...args)
bucket_entry(bool last_bucket) noexcept
std::forward_iterator_tag iterator_category
robin_hash(robin_hash &&other) noexcept(std::is_nothrow_move_constructible< Hash >::value &&std::is_nothrow_move_constructible< KeyEqual >::value &&std::is_nothrow_move_constructible< GrowthPolicy >::value &&std::is_nothrow_move_constructible< buckets_container_type >::value)
bool last_bucket() const noexcept
void deserialize(Deserializer &deserializer, bool hash_compatible)
U::value_type & value() const
distance_type dist_from_ideal_bucket() const noexcept
std::int16_t distance_type
size_type count(const K &key, std::size_t hash) const
STATIC_INLINE size_t Hash(const char *s, size_t len)
std::pair< iterator, bool > insert_or_assign(K &&key, M &&obj)
#define PXR_TSL_RH_UNUSED(x)
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
bool bucket_hash_equal(std::size_t hash) const noexcept
truncated_hash_type truncated_hash() const noexcept
friend bool operator==(const robin_iterator &lhs, const robin_iterator &rhs)
value_type & value() noexcept
GLsizei const GLfloat * value
robin_iterator & operator++()
const U::value_type & value() const
robin_iterator(const robin_iterator<!TIsConst > &other) noexcept
robin_hash & operator=(const robin_hash &other)
reference operator*() const
void swap(robin_hash &other)
void swap(T &lhs, T &rhs)
void serialize(Serializer &serializer) const
U::value_type & operator[](K &&key)
static constexpr float MINIMUM_MAX_LOAD_FACTOR
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
std::pair< iterator, iterator > equal_range(const K &key)
bool contains(const K &key) const
void rehash(size_type count_)
robin_iterator() noexcept
const robin_hash::key_type & key() const
const T & clamp(const T &v, const T &lo, const T &hi)
std::pair< iterator, bool > emplace(Args &&...args)
iterator insert_hint(const_iterator hint, P &&value)
float max_load_factor() const
size_type count(const K &key) const
#define pxr_tsl_rh_assert(expr)
const_iterator cend() const noexcept
bucket_entry(const bucket_entry &other) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
size_type erase(const K &key, std::size_t hash)
std::ptrdiff_t difference_type
const value_type & value() const noexcept
bool contains(const K &key, std::size_t hash) const
const_iterator end() const noexcept
IMATH_NAMESPACE::V2f float
robin_iterator< true > const_iterator
std::uint64_t slz_size_type
std::pair< iterator, iterator > equal_range(const K &key, std::size_t hash)
void swap_with_value_in_bucket(distance_type &dist_from_ideal_bucket, truncated_hash_type &hash, value_type &value)
std::uint32_t truncated_hash_type
void min_load_factor(float ml)
robin_hash & operator=(robin_hash &&other)
robin_hash(size_type bucket_count, const Hash &hash, const KeyEqual &equal, const Allocator &alloc, float min_load_factor=DEFAULT_MIN_LOAD_FACTOR, float max_load_factor=DEFAULT_MAX_LOAD_FACTOR)
#define PXR_TSL_RH_LIKELY(exp)
std::ptrdiff_t difference_type
iterator find(const K &key, std::size_t hash)
const_iterator begin() const noexcept
robin_hash(const robin_hash &other)
bool empty() const noexcept
static const distance_type DIST_FROM_IDEAL_BUCKET_LIMIT
std::pair< iterator, bool > insert(P &&value)
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
robin_iterator operator++(int)
size_type max_size() const noexcept
std::pair< Key, T > value_type
std::pair< iterator, bool > try_emplace(K &&key, Args &&...args)
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t hash) const
bucket_entry(bucket_entry &&other) noexcept(std::is_nothrow_move_constructible< value_type >::value)
iterator erase(const_iterator pos)
static constexpr float MAXIMUM_MAX_LOAD_FACTOR
const value_type & const_reference
const_iterator cbegin() const noexcept
const value_type * const_pointer
#define PXR_TSL_RH_THROW_OR_TERMINATE(ex, msg)
const typename robin_hash::value_type value_type
const_iterator find(const K &key, std::size_t hash) const
GT_API const UT_StringHolder version
float min_load_factor() const
iterator begin() noexcept
__hostdev__ uint64_t last(uint32_t i) const
iterator mutable_iterator(const_iterator pos)
const U::value_type & at(const K &key, std::size_t hash) const
static constexpr float MINIMUM_MIN_LOAD_FACTOR
IMATH_HOSTDEVICE constexpr int ceil(T x) IMATH_NOEXCEPT
void set_hash(truncated_hash_type hash) noexcept
hasher hash_function() const
robin_iterator< false > iterator
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
bool empty() const noexcept
bool bucket_hash_equal(std::size_t) const noexcept
LeafData & operator=(const LeafData &)=delete
static constexpr float DEFAULT_MIN_LOAD_FACTOR
iterator erase(const_iterator first, const_iterator last)
const U::value_type & at(const K &key) const
static constexpr float MAXIMUM_MIN_LOAD_FACTOR
void set_value_of_empty_bucket(distance_type dist_from_ideal_bucket, truncated_hash_type hash, Args &&...value_type_args)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
U::value_type & at(const K &key, std::size_t hash)
**If you just want to fire and args
size_type size() const noexcept
const_iterator find(const K &key) const
void set_as_last_bucket() noexcept
bucket_entry & operator=(const bucket_entry &other) noexcept(std::is_nothrow_copy_constructible< value_type >::value)
iterator find(const K &key)
static constexpr float DEFAULT_MAX_LOAD_FACTOR
U::value_type & at(const K &key)
truncated_hash_type truncated_hash() const noexcept
friend bool operator!=(const robin_iterator &lhs, const robin_iterator &rhs)
allocator_type get_allocator() const
SIM_API const UT_StringHolder distance
size_type erase(const K &key)
void insert(InputIt first, InputIt last)
static const size_type DEFAULT_INIT_BUCKETS_SIZE
pointer operator->() const
void max_load_factor(float ml)
iterator erase(iterator pos)
size_type bucket_count() const
void reserve(size_type count_)