aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahoo-inc.com>2016-11-22 15:30:10 +0100
committerBjørn Christian Seime <bjorncs@yahoo-inc.com>2016-11-22 15:30:21 +0100
commit0a05e44eb7dd03fcd49d6443dbaebd1acb542469 (patch)
tree449ac852abe6017414742617c8e9ab53883cab48 /document
parenta95e98a1f880be49f9ffcda01468b145b42e8b83 (diff)
Implement hashing of BucketSpace and Bucket
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/bucket/bucket.h9
-rw-r--r--document/src/vespa/document/bucket/bucketspace.h7
2 files changed, 16 insertions, 0 deletions
diff --git a/document/src/vespa/document/bucket/bucket.h b/document/src/vespa/document/bucket/bucket.h
index af60027d7e3..cc7aceb4ea7 100644
--- a/document/src/vespa/document/bucket/bucket.h
+++ b/document/src/vespa/document/bucket/bucket.h
@@ -32,6 +32,15 @@ public:
BucketId getBucketId() const noexcept { return _bucketId; }
void print(std::ostream& os) const;
vespalib::string toString() const;
+
+ struct hash {
+ size_t operator () (const Bucket& b) const {
+ size_t hash1 = BucketId::hash()(b.getBucketId());
+ size_t hash2 = BucketSpace::hash()(b.getBucketSpace());
+ // Formula taken from std::hash_combine proposal
+ return hash1 ^ (hash2 + 0x9e3779b9 + (hash1<<6) + (hash1>>2));
+ }
+ };
private:
BucketSpace _bucketSpace;
BucketId _bucketId;
diff --git a/document/src/vespa/document/bucket/bucketspace.h b/document/src/vespa/document/bucket/bucketspace.h
index 22dc6dc98a8..a78004b271b 100644
--- a/document/src/vespa/document/bucket/bucketspace.h
+++ b/document/src/vespa/document/bucket/bucketspace.h
@@ -5,6 +5,7 @@
#include <vespa/vespalib/stllike/string.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <cstdint>
+#include <functional>
#include <iostream>
namespace document {
@@ -24,6 +25,12 @@ public:
Type getId() const noexcept { return _id; }
void print(std::ostream& out) const;
vespalib::string toString() const;
+
+ struct hash {
+ size_t operator () (const BucketSpace& bs) const {
+ return std::hash<Type>()(bs.getId());
+ }
+ };
private:
Type _id;
};