1 | /* |
2 | * Copyright 2017-present Facebook, Inc. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | /** |
18 | * @author Giuseppe Ottaviano <ott@fb.com> |
19 | * |
20 | * Shared utils for BitVectorCoding.h and EliasFanoCoding.h. |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | #include <stddef.h> |
26 | |
27 | namespace folly { |
28 | namespace compression { |
29 | namespace detail { |
30 | |
31 | /** |
32 | * Helpers to store pointers to forward and skip pointer arrays only |
33 | * if they are used, that is, the quantum is nonzero. If it is 0, the |
34 | * class is empty, and the member is static to keep the syntax valid, |
35 | * thus it will take no space in a derived class thanks to empty base |
36 | * class optimization. |
37 | */ |
38 | template <size_t> |
39 | class ForwardPointers { |
40 | protected: |
41 | explicit ForwardPointers(const unsigned char* ptr) : forwardPointers_(ptr) {} |
42 | const unsigned char* const forwardPointers_; |
43 | }; |
44 | template <> |
45 | class ForwardPointers<0> { |
46 | protected: |
47 | explicit ForwardPointers(const unsigned char*) {} |
48 | constexpr static const unsigned char* const forwardPointers_{}; |
49 | }; |
50 | |
51 | template <size_t> |
52 | class SkipPointers { |
53 | protected: |
54 | explicit SkipPointers(const unsigned char* ptr) : skipPointers_(ptr) {} |
55 | const unsigned char* const skipPointers_; |
56 | }; |
57 | template <> |
58 | class SkipPointers<0> { |
59 | protected: |
60 | explicit SkipPointers(const unsigned char*) {} |
61 | constexpr static const unsigned char* const skipPointers_{}; |
62 | }; |
63 | } // namespace detail |
64 | } // namespace compression |
65 | } // namespace folly |
66 | |