Skip to content

Commit e6d7bff

Browse files
committed
settled for 32/prefetched_cachelines, cleaned up code
1 parent 9cd13c0 commit e6d7bff

File tree

2 files changed

+79
-177
lines changed

2 files changed

+79
-177
lines changed

include/boost/bloom/detail/core.hpp

Lines changed: 75 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ class filter_core:empty_value<Allocator,0>
218218
using pointer=unsigned char*;
219219
using const_pointer=const unsigned char*;
220220
static constexpr std::size_t bulk_insert_size=
221-
(128+prefetched_cachelines-1)/prefetched_cachelines;
221+
(32+prefetched_cachelines-1)/prefetched_cachelines;
222222
static constexpr std::size_t bulk_may_contain_size=
223-
(128+prefetched_cachelines-1)/prefetched_cachelines;
223+
(32+prefetched_cachelines-1)/prefetched_cachelines;
224224

225225
explicit filter_core(std::size_t m=0):filter_core{m,allocator_type{}}{}
226226

@@ -391,7 +391,7 @@ class filter_core:empty_value<Allocator,0>
391391
}
392392

393393
template<typename HashStream>
394-
BOOST_FORCEINLINE void bulk_insert(HashStream h,std::size_t n)
394+
void bulk_insert(HashStream h,std::size_t n)
395395
{
396396
std::uint64_t hashes[bulk_insert_size];
397397
unsigned char* positions[bulk_insert_size];
@@ -439,20 +439,85 @@ class filter_core:empty_value<Allocator,0>
439439
n-=bulk_insert_size;
440440
}
441441
while(n--)insert(h());
442+
}
442443

443-
#if 0
444-
while(n>=2*bulk_insert_size){
445-
bulk_insert_impl(h,bulk_insert_size);
446-
n-=bulk_insert_size;
444+
void swap(filter_core& x)noexcept(
445+
allocator_propagate_on_container_swap_t<allocator_type>::value||
446+
allocator_is_always_equal_t<allocator_type>::value)
447+
{
448+
static constexpr auto pocs=
449+
allocator_propagate_on_container_swap_t<allocator_type>::value;
450+
451+
if_constexpr<pocs>([&,this]{
452+
swap_if<pocs>(al(),x.al());
453+
},
454+
[&,this]{ /* else */
455+
BOOST_ASSERT(al()==x.al());
456+
(void)this; /* makes sure captured this is used */
457+
});
458+
std::swap(hs,x.hs);
459+
std::swap(ar,x.ar);
460+
}
461+
462+
void clear()noexcept
463+
{
464+
clear_bytes();
465+
}
466+
467+
void reset(std::size_t m=0)
468+
{
469+
hash_strategy new_hs{requested_range(m)};
470+
std::size_t rng=m?new_hs.range():0;
471+
if(rng!=range()){
472+
auto new_ar=new_array(al(),rng);
473+
delete_array();
474+
hs=new_hs;
475+
ar=new_ar;
447476
}
448-
if(n){
449-
bulk_insert_impl(h,n);
477+
clear_bytes();
478+
}
479+
480+
void reset(std::size_t n,double fpr)
481+
{
482+
reset(capacity_for(n,fpr));
483+
}
484+
485+
filter_core& operator&=(const filter_core& x)
486+
{
487+
combine(x,[](unsigned char& a,unsigned char b){a&=b;});
488+
return *this;
489+
}
490+
491+
filter_core& operator|=(const filter_core& x)
492+
{
493+
combine(x,[](unsigned char& a,unsigned char b){a|=b;});
494+
return *this;
495+
}
496+
497+
BOOST_FORCEINLINE bool may_contain(std::uint64_t hash)const
498+
{
499+
hs.prepare_hash(hash);
500+
#if 1
501+
auto p0=next_element(hash);
502+
for(std::size_t n=k-1;n--;){
503+
auto p=p0;
504+
auto hash0=hash;
505+
p0=next_element(hash);
506+
if(!get(p,hash0))return false;
507+
}
508+
if(!get(p0,hash))return false;
509+
return true;
510+
#else
511+
for(auto n=k;n--;){
512+
auto p=next_element(hash); /* modifies hash */
513+
if(!get(p,hash))return false;
450514
}
515+
return true;
451516
#endif
452517
}
453518

454519
template<typename HashStream,typename F>
455-
BOOST_FORCEINLINE void bulk_may_contain(HashStream h,std::size_t n,F f)const
520+
void bulk_may_contain(HashStream h,std::size_t n,F f)const
456521
{
457522
if(k==1){
458523
std::uint64_t hashes[bulk_may_contain_size];
@@ -543,90 +608,6 @@ class filter_core:empty_value<Allocator,0>
543608
}
544609
while(n--)f(may_contain(h()));
545610
}
546-
#if 0
547-
while(n>=2*bulk_may_contain_size){
548-
bulk_may_contain_impl(h,bulk_may_contain_size,f);
549-
n-=bulk_may_contain_size;
550-
}
551-
if(n){
552-
bulk_may_contain_impl(h,n,f);
553-
}
554-
#endif
555-
}
556-
557-
void swap(filter_core& x)noexcept(
558-
allocator_propagate_on_container_swap_t<allocator_type>::value||
559-
allocator_is_always_equal_t<allocator_type>::value)
560-
{
561-
static constexpr auto pocs=
562-
allocator_propagate_on_container_swap_t<allocator_type>::value;
563-
564-
if_constexpr<pocs>([&,this]{
565-
swap_if<pocs>(al(),x.al());
566-
},
567-
[&,this]{ /* else */
568-
BOOST_ASSERT(al()==x.al());
569-
(void)this; /* makes sure captured this is used */
570-
});
571-
std::swap(hs,x.hs);
572-
std::swap(ar,x.ar);
573-
}
574-
575-
void clear()noexcept
576-
{
577-
clear_bytes();
578-
}
579-
580-
void reset(std::size_t m=0)
581-
{
582-
hash_strategy new_hs{requested_range(m)};
583-
std::size_t rng=m?new_hs.range():0;
584-
if(rng!=range()){
585-
auto new_ar=new_array(al(),rng);
586-
delete_array();
587-
hs=new_hs;
588-
ar=new_ar;
589-
}
590-
clear_bytes();
591-
}
592-
593-
void reset(std::size_t n,double fpr)
594-
{
595-
reset(capacity_for(n,fpr));
596-
}
597-
598-
filter_core& operator&=(const filter_core& x)
599-
{
600-
combine(x,[](unsigned char& a,unsigned char b){a&=b;});
601-
return *this;
602-
}
603-
604-
filter_core& operator|=(const filter_core& x)
605-
{
606-
combine(x,[](unsigned char& a,unsigned char b){a|=b;});
607-
return *this;
608-
}
609-
610-
BOOST_FORCEINLINE bool may_contain(std::uint64_t hash)const
611-
{
612-
hs.prepare_hash(hash);
613-
#if 1
614-
auto p0=next_element(hash);
615-
for(std::size_t n=k-1;n--;){
616-
auto p=p0;
617-
auto hash0=hash;
618-
p0=next_element(hash);
619-
if(!get(p,hash0))return false;
620-
}
621-
if(!get(p0,hash))return false;
622-
return true;
623-
#else
624-
for(auto n=k;n--;){
625-
auto p=next_element(hash); /* modifies hash */
626-
if(!get(p,hash))return false;
627-
}
628-
return true;
629-
#endif
630611
}
631612

632613
friend bool operator==(const filter_core& x,const filter_core& y)
@@ -871,85 +852,6 @@ class filter_core:empty_value<Allocator,0>
871852
return p;
872853
}
873854

874-
template<typename HashStream>
875-
BOOST_FORCEINLINE void bulk_insert_impl(HashStream&& h,std::size_t n)
876-
{
877-
std::uint64_t hashes[2*bulk_insert_size-1];
878-
unsigned char* positions[2*bulk_insert_size-1];
879-
880-
for(auto i=n;i--;){
881-
auto& hash=hashes[i]=h();
882-
auto& p=positions[i];
883-
hs.prepare_hash(hash);
884-
p=next_element(hash);
885-
}
886-
if(BOOST_UNLIKELY(ar.data==nullptr))return;
887-
for(auto j=k-1;j--;){
888-
for(auto i=n;i--;){
889-
auto& hash=hashes[i];
890-
auto& p=positions[i];
891-
set(p,hash);
892-
p=next_element(hash);
893-
}
894-
}
895-
for(auto i=n;i--;){
896-
auto& hash=hashes[i];
897-
auto& p=positions[i];
898-
set(p,hash);
899-
}
900-
}
901-
902-
template<typename HashStream,typename F>
903-
BOOST_FORCEINLINE void bulk_may_contain_impl(
904-
HashStream&& h,std::size_t n,F&& f)const
905-
{
906-
if(k==1){
907-
std::uint64_t hashes[2*bulk_may_contain_size-1];
908-
const unsigned char* positions[2*bulk_may_contain_size-1];
909-
910-
for(auto i=n;i--;){
911-
auto& hash=hashes[i]=h();
912-
auto& p=positions[i];
913-
hs.prepare_hash(hash);
914-
p=next_element(hash);
915-
}
916-
for(auto i=n;i--;){
917-
auto& hash=hashes[i];
918-
auto& p=positions[i];
919-
f(get(p,hash));
920-
}
921-
}
922-
else{
923-
std::uint64_t hashes[2*bulk_may_contain_size-1];
924-
const unsigned char* positions[2*bulk_may_contain_size-1];
925-
bool results[2*bulk_may_contain_size-1];
926-
927-
for(auto i=n;i--;){
928-
auto& hash=hashes[i]=h();
929-
auto& p=positions[i];
930-
results[i]=true;
931-
hs.prepare_hash(hash);
932-
p=next_element(hash);
933-
}
934-
for(auto j=k-1;j--;){
935-
for(auto i=n;i--;){
936-
auto& hash=hashes[i];
937-
auto& p=positions[i];
938-
auto& res=results[i];
939-
res&=get(p,hash);
940-
p=next_element(hash);
941-
}
942-
}
943-
for(auto i=n;i--;){
944-
auto& hash=hashes[i];
945-
auto& p=positions[i];
946-
auto& res=results[i];
947-
res&=get(p,hash);
948-
f(res);
949-
}
950-
}
951-
}
952-
953855
template<typename F>
954856
void combine(const filter_core& x,F f)
955857
{

include/boost/bloom/filter.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ __declspec(empty_bases) /* activate EBO with multiple inheritance */
248248
}
249249

250250
template<typename InputIterator>
251-
BOOST_FORCEINLINE void insert(InputIterator first,InputIterator last)
251+
void insert(InputIterator first,InputIterator last)
252252
{
253253
insert_impl(
254254
first,last,
@@ -306,7 +306,7 @@ __declspec(empty_bases) /* activate EBO with multiple inheritance */
306306
}
307307

308308
template<typename ForwardIterator,typename F>
309-
BOOST_FORCEINLINE void may_contain(
309+
void may_contain(
310310
ForwardIterator first,ForwardIterator last,F f)const
311311
{
312312
BOOST_BLOOM_STATIC_ASSERT_IS_FORWARD_ITERATOR(ForwardIterator);
@@ -357,14 +357,14 @@ __declspec(empty_bases) /* activate EBO with multiple inheritance */
357357
}
358358

359359
template<typename Iterator>
360-
BOOST_FORCEINLINE void insert_impl(
360+
void insert_impl(
361361
Iterator first,Iterator last,std::false_type /* input iterator */)
362362
{
363363
while(first!=last)insert(*first++);
364364
}
365365

366366
template<typename Iterator>
367-
BOOST_FORCEINLINE void insert_impl(
367+
void insert_impl(
368368
Iterator first,Iterator last,std::true_type /* forward iterator */)
369369
{
370370
super::bulk_insert(

0 commit comments

Comments
 (0)