tint/utils: Default to using Hasher instead of std::hash
STL std::hash<T*> implementations have a tendency of just reinterpreting the pointer as a size_t. This is fast, but produces a bad hash, as most pointers tend to be 4 or 16 byte aligned. The lack of entropy in the LSBs causes clustering of hashmap slots. Use tint::utils::Hasher to get better hashes. Change-Id: Ife768d573cd1875e746ca9d77a4ac19e43b06aca Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99281 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
18dc315ccb
commit
93c2d559a1
|
@ -19,6 +19,7 @@
|
|||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/utils/hash.h"
|
||||
#include "src/tint/utils/hashset.h"
|
||||
|
||||
namespace tint::utils {
|
||||
|
@ -31,7 +32,7 @@ namespace tint::utils {
|
|||
template <typename K,
|
||||
typename V,
|
||||
size_t N,
|
||||
typename HASH = std::hash<K>,
|
||||
typename HASH = Hasher<K>,
|
||||
typename EQUAL = std::equal_to<K>>
|
||||
class Hashmap {
|
||||
/// LazyCreator is a transient structure used to late-build the Entry::value, when inserted into
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <utility>
|
||||
|
||||
#include "src/tint/debug.h"
|
||||
#include "src/tint/utils/hash.h"
|
||||
#include "src/tint/utils/vector.h"
|
||||
|
||||
namespace tint::utils {
|
||||
|
@ -39,7 +40,7 @@ enum class AddAction {
|
|||
|
||||
/// An unordered set that uses a robin-hood hashing algorithm.
|
||||
/// @see the fantastic tutorial: https://programming.guide/robin-hood-hashing.html
|
||||
template <typename T, size_t N, typename HASH = std::hash<T>, typename EQUAL = std::equal_to<T>>
|
||||
template <typename T, size_t N, typename HASH = Hasher<T>, typename EQUAL = std::equal_to<T>>
|
||||
class Hashset {
|
||||
/// A slot is a single entry in the underlying vector.
|
||||
/// A slot can either be empty or filled with a value. If the slot is empty, #hash and #distance
|
||||
|
|
Loading…
Reference in New Issue