blob: e7bed8767d6fc25c53d1da6cec4954bfe69d4814 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "bucketspace.h"
#include "bucketid.h"
#include <vespa/vespalib/stllike/string.h>
#include <cstdint>
namespace document {
class Bucket {
public:
Bucket() noexcept;
Bucket(const Bucket&) noexcept = default;
Bucket& operator=(const Bucket&) noexcept = default;
Bucket(BucketSpace bucketSpace, BucketId bucketId) noexcept : _bucketSpace(bucketSpace), _bucketId(bucketId) {}
bool operator<(const Bucket& other) const noexcept {
if (_bucketSpace == other._bucketSpace) {
return _bucketId < other._bucketId;
}
return _bucketSpace < other._bucketSpace;
}
bool operator==(const Bucket& other) const noexcept {
return _bucketSpace == other._bucketSpace && _bucketId == other._bucketId;
}
bool operator!=(const Bucket& other) const noexcept { return !(operator==(other)); }
BucketSpace getBucketSpace() const noexcept { return _bucketSpace; }
BucketId getBucketId() const noexcept { return _bucketId; }
vespalib::string toString() const;
struct hash {
size_t operator () (const Bucket& b) const noexcept {
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;
};
vespalib::asciistream& operator<<(vespalib::asciistream&, const Bucket&);
std::ostream& operator<<(std::ostream&, const Bucket&);
}
|