X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=hash.cpp;fp=hash.cpp;h=72ed743533520212e27bc4396292240f8bc343a8;hb=2a322a4ad576d87535ce8a479f7a516da9457e80;hp=0000000000000000000000000000000000000000;hpb=d0b08188b8f9e70f2f5651b179b44e7cf992c85b;p=remoteglot-book diff --git a/hash.cpp b/hash.cpp new file mode 100644 index 0000000..72ed743 --- /dev/null +++ b/hash.cpp @@ -0,0 +1,14 @@ +#include +#include +#include "hash.h" + +using namespace std; + +int hash_key_to_bucket(const char* s, size_t len, int num_buckets) +{ + // We hash only the first 10 bytes; it should be enough to get a + // reasonable spread, but also mostly miss the move, so that + // same position + different move usually land in the same bucket. + len = max(len, 10); + return util::Fingerprint32(s, len) % num_buckets; +}