]>
git.proxmox.com Git - ceph.git/blob - 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).
14 #include "rocksdb/rocksdb_namespace.h"
16 namespace ROCKSDB_NAMESPACE
{
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
>
24 SmallEnumSet() : state_(0) {}
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_
;
35 state_
|= (tmp
<< value
);
36 return old_state
!= state_
;
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
);
44 return state_
& (tmp
<< value
);
51 } // namespace ROCKSDB_NAMESPACE