proxygen
GroupVarintDetail.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-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 #pragma once
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 namespace folly {
23 
24 template <typename T>
26 
27 namespace detail {
28 
29 template <typename T>
31 
32 template <>
34  enum : uint32_t {
35  kGroupSize = 4,
36  kHeaderSize = 1,
37  };
38 };
39 
40 template <>
42  enum : uint32_t {
43  kGroupSize = 5,
44  kHeaderSize = 2,
45  };
46 };
47 
48 template <typename T>
50  protected:
52  enum : uint32_t { kHeaderSize = Traits::kHeaderSize };
53 
54  public:
55  typedef T type;
56 
60  enum : uint32_t { kGroupSize = Traits::kGroupSize };
61 
65  enum : uint32_t { kMaxSize = kHeaderSize + sizeof(type) * kGroupSize };
66 
70  static size_t maxSize(size_t n) {
71  // Full groups
72  size_t total = (n / kGroupSize) * kFullGroupSize;
73  // Incomplete last group, if any
74  n %= kGroupSize;
75  if (n) {
76  total += kHeaderSize + n * sizeof(type);
77  }
78  return total;
79  }
80 
84  static size_t totalSize(const T* p, size_t n) {
85  size_t size = 0;
86  for (; n >= kGroupSize; n -= kGroupSize, p += kGroupSize) {
87  size += Derived::size(p);
88  }
89  if (n) {
90  size += Derived::partialSize(p, n);
91  }
92  return size;
93  }
94 
95  private:
97  enum { kFullGroupSize = kHeaderSize + kGroupSize * sizeof(type) };
98 };
99 
100 } // namespace detail
101 } // namespace folly
PskType type
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
static size_t maxSize(size_t n)
static size_t totalSize(const T *p, size_t n)
GroupVarintTraits< T > Traits