Skip to content

Commit 677d82b

Browse files
committed
special-cased bulk_may_contain for k=1
1 parent afb2235 commit 677d82b

File tree

1 file changed

+66
-34
lines changed

1 file changed

+66
-34
lines changed

include/boost/bloom/detail/core.hpp

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -455,62 +455,94 @@ class filter_core:empty_value<Allocator,0>
455455
template<typename HashStream,typename F>
456456
BOOST_FORCEINLINE void bulk_may_contain(HashStream h,std::size_t n,F f)const
457457
{
458-
std::uint64_t hashes[bulk_may_contain_size];
459-
const unsigned char* positions[bulk_may_contain_size];
460-
bool results[bulk_may_contain_size];
458+
if(k==1){
459+
std::uint64_t hashes[bulk_may_contain_size];
460+
const unsigned char* positions[bulk_may_contain_size];
461461

462-
if(n>=2*bulk_may_contain_size){
463-
for(auto i=bulk_may_contain_size;i--;){
464-
auto& hash=hashes[i]=h();
465-
auto& p=positions[i];
466-
auto& res=results[i];
467-
hs.prepare_hash(hash);
468-
p=next_element(hash);
469-
res=true;
470-
}
471-
do{
472-
for(auto j=k-1;j--;){
462+
if(n>=2*bulk_may_contain_size){
463+
for(auto i=bulk_may_contain_size;i--;){
464+
auto& hash=hashes[i]=h();
465+
auto& p=positions[i];
466+
hs.prepare_hash(hash);
467+
p=next_element(hash);
468+
}
469+
do{
473470
for(auto i=bulk_may_contain_size;i--;){
474471
auto& hash=hashes[i];
475472
auto& p=positions[i];
476-
auto& res=results[i];
477-
res&=get(p,hash);
473+
f(get(p,hash));
474+
hash=h();
475+
hs.prepare_hash(hash);
478476
p=next_element(hash);
479477
}
480-
}
478+
n-=bulk_may_contain_size;
479+
}while(n>=2*bulk_may_contain_size);
481480
for(auto i=bulk_may_contain_size;i--;){
482481
auto& hash=hashes[i];
483482
auto& p=positions[i];
483+
f(get(p,hash));
484+
}
485+
n-=bulk_may_contain_size;
486+
}
487+
while(n--)f(may_contain(h()));
488+
}
489+
else{
490+
std::uint64_t hashes[bulk_may_contain_size];
491+
const unsigned char* positions[bulk_may_contain_size];
492+
bool results[bulk_may_contain_size];
493+
494+
if(n>=2*bulk_may_contain_size){
495+
for(auto i=bulk_may_contain_size;i--;){
496+
auto& hash=hashes[i]=h();
497+
auto& p=positions[i];
484498
auto& res=results[i];
485-
res&=get(p,hash);
486-
f(res);
487-
hash=h();
488499
hs.prepare_hash(hash);
489500
p=next_element(hash);
490501
res=true;
491502
}
492-
n-=bulk_may_contain_size;
493-
}while(n>=2*bulk_may_contain_size);
494-
for(auto j=k-1;j--;){
503+
do{
504+
for(auto j=k-1;j--;){
505+
for(auto i=bulk_may_contain_size;i--;){
506+
auto& hash=hashes[i];
507+
auto& p=positions[i];
508+
auto& res=results[i];
509+
res&=get(p,hash);
510+
p=next_element(hash);
511+
}
512+
}
513+
for(auto i=bulk_may_contain_size;i--;){
514+
auto& hash=hashes[i];
515+
auto& p=positions[i];
516+
auto& res=results[i];
517+
res&=get(p,hash);
518+
f(res);
519+
hash=h();
520+
hs.prepare_hash(hash);
521+
p=next_element(hash);
522+
res=true;
523+
}
524+
n-=bulk_may_contain_size;
525+
}while(n>=2*bulk_may_contain_size);
526+
for(auto j=k-1;j--;){
527+
for(auto i=bulk_may_contain_size;i--;){
528+
auto& hash=hashes[i];
529+
auto& p=positions[i];
530+
auto& res=results[i];
531+
res&=get(p,hash);
532+
p=next_element(hash);
533+
}
534+
}
495535
for(auto i=bulk_may_contain_size;i--;){
496536
auto& hash=hashes[i];
497537
auto& p=positions[i];
498538
auto& res=results[i];
499539
res&=get(p,hash);
500-
p=next_element(hash);
540+
f(res);
501541
}
542+
n-=bulk_may_contain_size;
502543
}
503-
for(auto i=bulk_may_contain_size;i--;){
504-
auto& hash=hashes[i];
505-
auto& p=positions[i];
506-
auto& res=results[i];
507-
res&=get(p,hash);
508-
f(res);
509-
}
510-
n-=bulk_may_contain_size;
544+
while(n--)f(may_contain(h()));
511545
}
512-
while(n--)f(may_contain(h()));
513-
514546
#if 0
515547
while(n>=2*bulk_may_contain_size){
516548
bulk_may_contain_impl(h,bulk_may_contain_size,f);

0 commit comments

Comments
 (0)