Open rhalbersma opened 7 years ago
Sounds like an interesting example, thanks.
Never mind the double notification for this pull request. I hadn't properly synced with your repo before sending the PR. AFAICS, my hard history rewrite leaves only the latest commit in the PR.
Applications are e.g. chess engines, where the wrapped type represents the full chess Position object.
That is REALLY COOL!! Thanks for sharing this!
I would like to propose adding an
identity_hash
that stores its input bytes as result.The use cases for this simple hash function are for thin wrapper classes around regular value types that cache their hash keys. E.g. below is a sketch of such a wrapper class that holds a value and its hash key. This key can be computed in the wrapper's constructor by
xstd::uhash
using any full-fledged hash function (fnv1a
here, but also Murmur, City or evenstd::hash
).Once the key has been computed and wrapped, the wrapper object itself can be stored inside a
std::unordered_set<wrap, xstd::uhash<acme::identity_hash>>
. This saves recomputing the hash key.The proposed
identity_hash
would enable thehash_append
framework for these type of data structures. This also paves the way for (but does not depend on) using a tabulation hashing algorithm (where the key is incrementally updated when the wrapped value is mutated; caching the key is required in order to achieve this).Applications are e.g. chess engines, where the wrapped type represents the full chess Position object. Storing the hash key and incrementally updating it as the underlying position changes, is standard practice in every top board game program (chess, checkers, Go). Similar optimizations are done in protein design and other backtracking search applications where small incremental changes and their inverses are done to the data structure.
I can send a PR if you would welcome
identity_hash
(I'm obivously not proposing the wrapper class).