]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/data_structure.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / include / rocksdb / data_structure.h
1 // Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 #pragma once
7
8 #include <assert.h>
9
10 #include <cstddef>
11 #include <cstdint>
12 #include <vector>
13
14 #include "rocksdb/rocksdb_namespace.h"
15
16 namespace ROCKSDB_NAMESPACE {
17
18 // This is a data structure specifically designed as a "Set" for a
19 // pretty small scale of Enum structure. For now, it can support up
20 // to 64 element, and it is expandable in the future.
21 template <typename ENUM_TYPE, ENUM_TYPE MAX_VALUE>
22 class SmallEnumSet {
23 public:
24 SmallEnumSet() : state_(0) {}
25
26 ~SmallEnumSet() {}
27
28 // Return true if the input enum is included in the "Set" (i.e., changes the
29 // internal scalar state successfully), otherwise, it will return false.
30 bool Add(const ENUM_TYPE value) {
31 static_assert(MAX_VALUE <= 63, "Size currently limited to 64");
32 assert(value >= 0 && value <= MAX_VALUE);
33 uint64_t old_state = state_;
34 uint64_t tmp = 1;
35 state_ |= (tmp << value);
36 return old_state != state_;
37 }
38
39 // Return true if the input enum is contained in the "Set".
40 bool Contains(const ENUM_TYPE value) {
41 static_assert(MAX_VALUE <= 63, "Size currently limited to 64");
42 assert(value >= 0 && value <= MAX_VALUE);
43 uint64_t tmp = 1;
44 return state_ & (tmp << value);
45 }
46
47 private:
48 uint64_t state_;
49 };
50
51 } // namespace ROCKSDB_NAMESPACE