Skip to content

Commit afb2235

Browse files
committed
implemented continuous bulk ops
1 parent 7b5e115 commit afb2235

File tree

1 file changed

+113
-3
lines changed

1 file changed

+113
-3
lines changed

include/boost/bloom/detail/core.hpp

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,11 @@ 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=16;
221-
static constexpr std::size_t bulk_may_contain_size=16;
220+
static constexpr std::size_t bulk_insert_size=
221+
(32+prefetched_cachelines-1)/prefetched_cachelines;
222+
static constexpr std::size_t bulk_may_contain_size=
223+
(32+prefetched_cachelines-1)/prefetched_cachelines;
224+
222225

223226
explicit filter_core(std::size_t m=0):filter_core{m,allocator_type{}}{}
224227

@@ -391,25 +394,132 @@ class filter_core:empty_value<Allocator,0>
391394
template<typename HashStream>
392395
BOOST_FORCEINLINE void bulk_insert(HashStream h,std::size_t n)
393396
{
394-
while(n>=2*bulk_insert_size){
397+
std::uint64_t hashes[bulk_insert_size];
398+
unsigned char* positions[bulk_insert_size];
399+
400+
if(n>=2*bulk_insert_size){
401+
for(auto i=bulk_insert_size;i--;){
402+
auto& hash=hashes[i]=h();
403+
auto& p=positions[i];
404+
hs.prepare_hash(hash);
405+
p=next_element(hash);
406+
}
407+
if(BOOST_UNLIKELY(ar.data==nullptr))return;
408+
do{
409+
for(auto j=k-1;j--;){
410+
for(auto i=bulk_insert_size;i--;){
411+
auto& hash=hashes[i];
412+
auto& p=positions[i];
413+
set(p,hash);
414+
p=next_element(hash);
415+
}
416+
}
417+
for(auto i=bulk_insert_size;i--;){
418+
auto& hash=hashes[i];
419+
auto& p=positions[i];
420+
set(p,hash);
421+
hash=h();
422+
hs.prepare_hash(hash);
423+
p=next_element(hash);
424+
}
425+
n-=bulk_insert_size;
426+
}while(n>=2*bulk_insert_size);
427+
for(auto j=k-1;j--;){
428+
for(auto i=bulk_insert_size;i--;){
429+
auto& hash=hashes[i];
430+
auto& p=positions[i];
431+
set(p,hash);
432+
p=next_element(hash);
433+
}
434+
}
435+
for(auto i=bulk_insert_size;i--;){
436+
auto& hash=hashes[i];
437+
auto& p=positions[i];
438+
set(p,hash);
439+
}
440+
n-=bulk_insert_size;
441+
}
442+
while(n--)insert(h());
443+
444+
#if 0
445+
while(n>=2*bulk_insert_size){
395446
bulk_insert_impl(h,bulk_insert_size);
396447
n-=bulk_insert_size;
397448
}
398449
if(n){
399450
bulk_insert_impl(h,n);
400451
}
452+
#endif
401453
}
402454

403455
template<typename HashStream,typename F>
404456
BOOST_FORCEINLINE void bulk_may_contain(HashStream h,std::size_t n,F f)const
405457
{
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];
461+
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--;){
473+
for(auto i=bulk_may_contain_size;i--;){
474+
auto& hash=hashes[i];
475+
auto& p=positions[i];
476+
auto& res=results[i];
477+
res&=get(p,hash);
478+
p=next_element(hash);
479+
}
480+
}
481+
for(auto i=bulk_may_contain_size;i--;){
482+
auto& hash=hashes[i];
483+
auto& p=positions[i];
484+
auto& res=results[i];
485+
res&=get(p,hash);
486+
f(res);
487+
hash=h();
488+
hs.prepare_hash(hash);
489+
p=next_element(hash);
490+
res=true;
491+
}
492+
n-=bulk_may_contain_size;
493+
}while(n>=2*bulk_may_contain_size);
494+
for(auto j=k-1;j--;){
495+
for(auto i=bulk_may_contain_size;i--;){
496+
auto& hash=hashes[i];
497+
auto& p=positions[i];
498+
auto& res=results[i];
499+
res&=get(p,hash);
500+
p=next_element(hash);
501+
}
502+
}
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;
511+
}
512+
while(n--)f(may_contain(h()));
513+
514+
#if 0
406515
while(n>=2*bulk_may_contain_size){
407516
bulk_may_contain_impl(h,bulk_may_contain_size,f);
408517
n-=bulk_may_contain_size;
409518
}
410519
if(n){
411520
bulk_may_contain_impl(h,n,f);
412521
}
522+
#endif
413523
}
414524

415525
void swap(filter_core& x)noexcept(

0 commit comments

Comments
 (0)