]> git.sesse.net Git - remoteglot-book/blobdiff - hash.cpp
Partition the SSTable; somewhat less efficient space-wise, it seems, but we avoid...
[remoteglot-book] / hash.cpp
diff --git a/hash.cpp b/hash.cpp
new file mode 100644 (file)
index 0000000..72ed743
--- /dev/null
+++ b/hash.cpp
@@ -0,0 +1,14 @@
+#include <farmhash.h>
+#include <algorithm>
+#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<size_t>(len, 10);
+       return util::Fingerprint32(s, len) % num_buckets;
+}