CodingDetail.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * @author Giuseppe Ottaviano <ott@fb.com>
  18. *
  19. * Shared utils for BitVectorCoding.h and EliasFanoCoding.h.
  20. */
  21. #pragma once
  22. #include <stddef.h>
  23. namespace folly {
  24. namespace compression {
  25. namespace detail {
  26. /**
  27. * Helpers to store pointers to forward and skip pointer arrays only
  28. * if they are used, that is, the quantum is nonzero. If it is 0, the
  29. * class is empty, and the member is static to keep the syntax valid,
  30. * thus it will take no space in a derived class thanks to empty base
  31. * class optimization.
  32. */
  33. template <size_t>
  34. class ForwardPointers {
  35. protected:
  36. explicit ForwardPointers(const unsigned char* ptr) : forwardPointers_(ptr) {}
  37. const unsigned char* const forwardPointers_;
  38. };
  39. template <>
  40. class ForwardPointers<0> {
  41. protected:
  42. explicit ForwardPointers(const unsigned char*) {}
  43. constexpr static const unsigned char* const forwardPointers_{};
  44. };
  45. template <size_t>
  46. class SkipPointers {
  47. protected:
  48. explicit SkipPointers(const unsigned char* ptr) : skipPointers_(ptr) {}
  49. const unsigned char* const skipPointers_;
  50. };
  51. template <>
  52. class SkipPointers<0> {
  53. protected:
  54. explicit SkipPointers(const unsigned char*) {}
  55. constexpr static const unsigned char* const skipPointers_{};
  56. };
  57. } // namespace detail
  58. } // namespace compression
  59. } // namespace folly