block_ops.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright 2025 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See https://www.boost.org/libs/bloom for library home page.
  7. */
  8. #ifndef BOOST_BLOOM_DETAIL_BLOCK_OPS_HPP
  9. #define BOOST_BLOOM_DETAIL_BLOCK_OPS_HPP
  10. #include <boost/config.hpp>
  11. #include <cstdint>
  12. #include <type_traits>
  13. namespace boost{
  14. namespace bloom{
  15. namespace detail{
  16. #if defined(BOOST_MSVC)
  17. #pragma warning(push)
  18. #pragma warning(disable:4714) /* marked as __forceinline not inlined */
  19. #endif
  20. template<typename Block>
  21. struct block_ops
  22. {
  23. using is_extended_block=std::false_type;
  24. using value_type=Block;
  25. static BOOST_FORCEINLINE void zero(Block& x)
  26. {
  27. x=0;
  28. }
  29. static BOOST_FORCEINLINE void set(value_type& x,std::uint64_t n)
  30. {
  31. x|=Block(1)<<n;
  32. }
  33. static BOOST_FORCEINLINE int get_at_lsb(const value_type& x,std::uint64_t n)
  34. {
  35. return static_cast<int>(x>>n);
  36. }
  37. static BOOST_FORCEINLINE void reduce(
  38. int& res,const value_type& x,std::uint64_t n)
  39. {
  40. res&=get_at_lsb(x,n);
  41. }
  42. static BOOST_FORCEINLINE bool testc(const value_type& x,const value_type& y)
  43. {
  44. return (x&y)==y;
  45. }
  46. };
  47. template<typename Block,std::size_t N>
  48. struct block_ops<Block[N]>
  49. {
  50. using is_extended_block=std::true_type;
  51. using value_type=Block[N];
  52. static BOOST_FORCEINLINE void zero(value_type& x)
  53. {
  54. for(std::size_t i=0;i<N;++i)x[i]=0;
  55. }
  56. static BOOST_FORCEINLINE void set(value_type& x,std::uint64_t n)
  57. {
  58. x[n%N]|=Block(1)<<(n/N);
  59. }
  60. static BOOST_FORCEINLINE int get_at_lsb(const value_type& x,std::uint64_t n)
  61. {
  62. return static_cast<int>(x[n%N]>>(n/N));
  63. }
  64. static BOOST_FORCEINLINE void reduce(
  65. int& res,const value_type& x,std::uint64_t n)
  66. {
  67. res&=get_at_lsb(x,n);
  68. }
  69. };
  70. #if defined(BOOST_MSVC)
  71. #pragma warning(pop) /* C4714 */
  72. #endif
  73. } /* namespace detail */
  74. } /* namespace bloom */
  75. } /* namespace boost */
  76. #endif