block.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_BLOCK_HPP
  9. #define BOOST_BLOOM_BLOCK_HPP
  10. #include <boost/bloom/detail/block_base.hpp>
  11. #include <boost/bloom/detail/block_ops.hpp>
  12. #include <boost/bloom/detail/block_fpr_base.hpp>
  13. #include <cstddef>
  14. #include <cstdint>
  15. namespace boost{
  16. namespace bloom{
  17. template<typename Block,std::size_t K>
  18. struct block:
  19. public detail::block_fpr_base<K>,
  20. private detail::block_base<Block,K>
  21. {
  22. static constexpr std::size_t k=K;
  23. using value_type=Block;
  24. /* NOLINTNEXTLINE(readability-redundant-inline-specifier) */
  25. static inline void mark(value_type& x,std::uint64_t hash)
  26. {
  27. loop(hash,[&](std::uint64_t h){block_ops::set(x,h&mask);});
  28. }
  29. /* NOLINTNEXTLINE(readability-redundant-inline-specifier) */
  30. static inline bool check(const value_type& x,std::uint64_t hash)
  31. {
  32. return check(x,hash,typename block_ops::is_extended_block{});
  33. }
  34. private:
  35. using super=detail::block_base<Block,K>;
  36. using super::mask;
  37. using super::loop;
  38. using super::loop_while;
  39. using block_ops=detail::block_ops<Block>;
  40. /* NOLINTNEXTLINE(readability-redundant-inline-specifier) */
  41. static inline bool check(
  42. const value_type& x,std::uint64_t hash,
  43. std::false_type /* non-extended block */)
  44. {
  45. Block fp;
  46. block_ops::zero(fp);
  47. mark(fp,hash);
  48. return block_ops::testc(x,fp);
  49. }
  50. /* NOLINTNEXTLINE(readability-redundant-inline-specifier) */
  51. static inline bool check(
  52. const value_type& x,std::uint64_t hash,
  53. std::true_type /* extended block */)
  54. {
  55. int res=1;
  56. loop(hash,[&](std::uint64_t h){
  57. res&=block_ops::get_at_lsb(x,h&mask);
  58. });
  59. return res;
  60. }
  61. };
  62. } /* namespace bloom */
  63. } /* namespace boost */
  64. #endif