Skip to content

Commit 511740f

Browse files
committed
fixed bulk sizes, provided compile-time-n bulk ops
1 parent eaa6f29 commit 511740f

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

include/boost/bloom/detail/core.hpp

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ class filter_core:empty_value<Allocator,0>
217217
using difference_type=std::ptrdiff_t;
218218
using pointer=unsigned char*;
219219
using const_pointer=const unsigned char*;
220-
static constexpr std::size_t bulk_insert_size=(8+prefetched_cachelines-1)/prefetched_cachelines;
221-
static constexpr std::size_t bulk_may_contain_size=(8+prefetched_cachelines-1)/prefetched_cachelines;
220+
static constexpr std::size_t bulk_insert_size=16;
221+
static constexpr std::size_t bulk_may_contain_size=16;
222222

223223
explicit filter_core(std::size_t m=0):filter_core{m,allocator_type{}}{}
224224

@@ -392,7 +392,7 @@ class filter_core:empty_value<Allocator,0>
392392
BOOST_FORCEINLINE void bulk_insert(HashStream h,std::size_t n)
393393
{
394394
while(n>=2*bulk_insert_size){
395-
bulk_insert_impl(h,bulk_insert_size);
395+
bulk_insert_impl<bulk_insert_size>(h);
396396
n-=bulk_insert_size;
397397
}
398398
if(n){
@@ -404,7 +404,7 @@ class filter_core:empty_value<Allocator,0>
404404
BOOST_FORCEINLINE void bulk_may_contain(HashStream h,std::size_t n,F f)const
405405
{
406406
while(n>=2*bulk_may_contain_size){
407-
bulk_may_contain_impl(h,bulk_may_contain_size,f);
407+
bulk_may_contain_impl<bulk_may_contain_size>(h,f);
408408
n-=bulk_may_contain_size;
409409
}
410410
if(n){
@@ -729,6 +729,34 @@ class filter_core:empty_value<Allocator,0>
729729
return p;
730730
}
731731

732+
template<std::size_t N,typename HashStream>
733+
BOOST_FORCEINLINE void bulk_insert_impl(HashStream&& h)
734+
{
735+
std::uint64_t hashes[N];
736+
unsigned char* positions[N];
737+
738+
for(auto i=N;i--;){
739+
auto& hash=hashes[i]=h();
740+
auto& p=positions[i];
741+
hs.prepare_hash(hash);
742+
p=next_element(hash);
743+
}
744+
if(BOOST_UNLIKELY(ar.data==nullptr))return;
745+
for(auto j=k-1;j--;){
746+
for(auto i=N;i--;){
747+
auto& hash=hashes[i];
748+
auto& p=positions[i];
749+
set(p,hash);
750+
p=next_element(hash);
751+
}
752+
}
753+
for(auto i=N;i--;){
754+
auto& hash=hashes[i];
755+
auto& p=positions[i];
756+
set(p,hash);
757+
}
758+
}
759+
732760
template<typename HashStream>
733761
BOOST_FORCEINLINE void bulk_insert_impl(HashStream&& h,std::size_t n)
734762
{
@@ -757,6 +785,56 @@ class filter_core:empty_value<Allocator,0>
757785
}
758786
}
759787

788+
template<std::size_t N,typename HashStream,typename F>
789+
BOOST_FORCEINLINE void bulk_may_contain_impl(HashStream&& h,F&& f)const
790+
{
791+
if(k==1){
792+
std::uint64_t hashes[N];
793+
const unsigned char* positions[N];
794+
795+
for(auto i=N;i--;){
796+
auto& hash=hashes[i]=h();
797+
auto& p=positions[i];
798+
hs.prepare_hash(hash);
799+
p=next_element(hash);
800+
}
801+
for(auto i=N;i--;){
802+
auto& hash=hashes[i];
803+
auto& p=positions[i];
804+
f(get(p,hash));
805+
}
806+
}
807+
else{
808+
std::uint64_t hashes[N];
809+
const unsigned char* positions[N];
810+
bool results[N];
811+
812+
for(auto i=N;i--;){
813+
auto& hash=hashes[i]=h();
814+
auto& p=positions[i];
815+
results[i]=true;
816+
hs.prepare_hash(hash);
817+
p=next_element(hash);
818+
}
819+
for(auto j=k-1;j--;){
820+
for(auto i=N;i--;){
821+
auto& hash=hashes[i];
822+
auto& p=positions[i];
823+
auto& res=results[i];
824+
res&=get(p,hash);
825+
p=next_element(hash);
826+
}
827+
}
828+
for(auto i=N;i--;){
829+
auto& hash=hashes[i];
830+
auto& p=positions[i];
831+
auto& res=results[i];
832+
res&=get(p,hash);
833+
f(res);
834+
}
835+
}
836+
}
837+
760838
template<typename HashStream,typename F>
761839
BOOST_FORCEINLINE void bulk_may_contain_impl(
762840
HashStream&& h,std::size_t n,F&& f)const

0 commit comments

Comments
 (0)