@@ -218,9 +218,9 @@ class filter_core:empty_value<Allocator,0>
218
218
using pointer=unsigned char *;
219
219
using const_pointer=const unsigned char *;
220
220
static constexpr std::size_t bulk_insert_size=
221
- (128 +prefetched_cachelines-1 )/prefetched_cachelines;
221
+ (32 +prefetched_cachelines-1 )/prefetched_cachelines;
222
222
static constexpr std::size_t bulk_may_contain_size=
223
- (128 +prefetched_cachelines-1 )/prefetched_cachelines;
223
+ (32 +prefetched_cachelines-1 )/prefetched_cachelines;
224
224
225
225
explicit filter_core (std::size_t m=0 ):filter_core{m,allocator_type{}}{}
226
226
@@ -391,7 +391,7 @@ class filter_core:empty_value<Allocator,0>
391
391
}
392
392
393
393
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)
395
395
{
396
396
std::uint64_t hashes[bulk_insert_size];
397
397
unsigned char * positions[bulk_insert_size];
@@ -439,20 +439,85 @@ class filter_core:empty_value<Allocator,0>
439
439
n-=bulk_insert_size;
440
440
}
441
441
while (n--)insert (h ());
442
+ }
442
443
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;
447
476
}
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;
450
514
}
515
+ return true;
451
516
#endif
452
517
}
453
518
454
519
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
456
521
{
457
522
if (k==1 ){
458
523
std::uint64_t hashes[bulk_may_contain_size];
@@ -543,90 +608,6 @@ class filter_core:empty_value<Allocator,0>
543
608
}
544
609
while (n--)f (may_contain (h ()));
545
610
}
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
630
611
}
631
612
632
613
friend bool operator ==(const filter_core& x,const filter_core& y)
@@ -871,85 +852,6 @@ class filter_core:empty_value<Allocator,0>
871
852
return p;
872
853
}
873
854
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
-
953
855
template <typename F>
954
856
void combine (const filter_core& x,F f)
955
857
{
0 commit comments