File indexing completed on 2026-08-17 08:39:05
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_BLOOM_DETAIL_BLOCK_BASE_HPP
0010 #define BOOST_BLOOM_DETAIL_BLOCK_BASE_HPP
0011
0012 #include <boost/config.hpp>
0013 #include <boost/bloom/detail/constexpr_bit_width.hpp>
0014 #include <boost/bloom/detail/mulx64.hpp>
0015 #include <boost/bloom/detail/type_traits.hpp>
0016 #include <cstddef>
0017 #include <cstdint>
0018
0019 namespace boost{
0020 namespace bloom{
0021 namespace detail{
0022
0023 #if defined(BOOST_MSVC)
0024 #pragma warning(push)
0025 #pragma warning(disable:4714)
0026 #endif
0027
0028
0029
0030
0031
0032 template<typename Block,std::size_t K>
0033 struct block_base
0034 {
0035 static_assert(
0036 is_unsigned_integral_or_extended_unsigned_integral<Block>::value||
0037 (
0038 is_array_of<
0039 Block,is_unsigned_integral_or_extended_unsigned_integral>::value&&
0040 is_power_of_two<array_size<Block>::value>::value
0041 ),
0042 "Block must be an (extended) unsigned integral type or an array T[N] "
0043 "with T an (extended) unsigned integral type and N a power of two");
0044 static constexpr std::size_t k=K;
0045 static constexpr std::size_t hash_width=sizeof(std::uint64_t)*CHAR_BIT;
0046 static constexpr std::size_t block_width=sizeof(Block)*CHAR_BIT;
0047 static constexpr std::size_t mask=block_width-1;
0048 static constexpr std::size_t shift=constexpr_bit_width(mask);
0049 static constexpr std::size_t rehash_k=(hash_width-shift)/shift;
0050
0051 template<typename F>
0052 static BOOST_FORCEINLINE void loop(std::uint64_t hash,F f)
0053 {
0054 for(std::size_t i=0;i<k/rehash_k;++i){
0055 auto h=hash;
0056 for(std::size_t j=0;j<rehash_k;++j){
0057 h>>=shift;
0058 f(h);
0059 }
0060 hash=detail::mulx64(hash);
0061 }
0062 auto h=hash;
0063 for(std::size_t i=0;i<k%rehash_k;++i){
0064 h>>=shift;
0065 f(h);
0066 }
0067 }
0068
0069 template<typename F>
0070 static BOOST_FORCEINLINE bool loop_while(std::uint64_t hash,F f)
0071 {
0072 for(std::size_t i=0;i<k/rehash_k;++i){
0073 auto h=hash;
0074 for(std::size_t j=0;j<rehash_k;++j){
0075 h>>=shift;
0076 if(!f(h))return false;
0077 }
0078 hash=detail::mulx64(hash);
0079 }
0080 auto h=hash;
0081 for(std::size_t i=0;i<k%rehash_k;++i){
0082 h>>=shift;
0083 if(!f(h))return false;
0084 }
0085 return true;
0086 }
0087 };
0088
0089 #if defined(BOOST_MSVC)
0090 #pragma warning(pop)
0091 #endif
0092
0093 }
0094 }
0095 }
0096 #endif