@@ -377,6 +377,7 @@ pub(crate) mod extend_with {
377
377
start : usize ,
378
378
end : usize ,
379
379
key_func : Func ,
380
+ old_key : Option < Key > ,
380
381
phantom : :: std:: marker:: PhantomData < Tuple > ,
381
382
}
382
383
@@ -394,6 +395,7 @@ pub(crate) mod extend_with {
394
395
start : 0 ,
395
396
end : 0 ,
396
397
key_func,
398
+ old_key : None ,
397
399
phantom : :: std:: marker:: PhantomData ,
398
400
}
399
401
}
@@ -409,11 +411,16 @@ pub(crate) mod extend_with {
409
411
{
410
412
fn count ( & mut self , prefix : & Tuple ) -> usize {
411
413
let key = ( self . key_func ) ( prefix) ;
412
- self . start = binary_search ( & self . relation . elements , |x| & x. 0 < & key) ;
413
- let slice1 = & self . relation [ self . start ..] ;
414
- let slice2 = gallop ( slice1, |x| & x. 0 <= & key) ;
415
- self . end = self . relation . len ( ) - slice2. len ( ) ;
416
- slice1. len ( ) - slice2. len ( )
414
+ if self . old_key . as_ref ( ) != Some ( & key) {
415
+ self . start = binary_search ( & self . relation . elements , |x| & x. 0 < & key) ;
416
+ let slice1 = & self . relation [ self . start ..] ;
417
+ let slice2 = gallop ( slice1, |x| & x. 0 <= & key) ;
418
+ self . end = self . relation . len ( ) - slice2. len ( ) ;
419
+
420
+ self . old_key = Some ( key) ;
421
+ }
422
+
423
+ self . end - self . start
417
424
}
418
425
fn propose ( & mut self , _prefix : & Tuple , values : & mut Vec < & ' leap Val > ) {
419
426
let slice = & self . relation [ self . start ..self . end ] ;
@@ -452,6 +459,8 @@ pub(crate) mod extend_with {
452
459
}
453
460
454
461
pub ( crate ) mod extend_anti {
462
+ use std:: ops:: Range ;
463
+
455
464
use super :: { binary_search, Leaper , Relation } ;
456
465
use crate :: join:: gallop;
457
466
@@ -465,6 +474,7 @@ pub(crate) mod extend_anti {
465
474
{
466
475
relation : & ' leap Relation < ( Key , Val ) > ,
467
476
key_func : Func ,
477
+ old_key : Option < ( Key , Range < usize > ) > ,
468
478
phantom : :: std:: marker:: PhantomData < Tuple > ,
469
479
}
470
480
@@ -480,6 +490,7 @@ pub(crate) mod extend_anti {
480
490
ExtendAnti {
481
491
relation,
482
492
key_func,
493
+ old_key : None ,
483
494
phantom : :: std:: marker:: PhantomData ,
484
495
}
485
496
}
@@ -501,10 +512,23 @@ pub(crate) mod extend_anti {
501
512
}
502
513
fn intersect ( & mut self , prefix : & Tuple , values : & mut Vec < & ' leap Val > ) {
503
514
let key = ( self . key_func ) ( prefix) ;
504
- let start = binary_search ( & self . relation . elements , |x| & x. 0 < & key) ;
505
- let slice1 = & self . relation [ start..] ;
506
- let slice2 = gallop ( slice1, |x| & x. 0 <= & key) ;
507
- let mut slice = & slice1[ ..( slice1. len ( ) - slice2. len ( ) ) ] ;
515
+
516
+ let range = match self . old_key . as_ref ( ) {
517
+ Some ( ( old, range) ) if old == & key => range. clone ( ) ,
518
+
519
+ _ => {
520
+ let start = binary_search ( & self . relation . elements , |x| & x. 0 < & key) ;
521
+ let slice1 = & self . relation [ start..] ;
522
+ let slice2 = gallop ( slice1, |x| & x. 0 <= & key) ;
523
+ let range = start..self . relation . len ( ) -slice2. len ( ) ;
524
+
525
+ self . old_key = Some ( ( key, range. clone ( ) ) ) ;
526
+
527
+ range
528
+ }
529
+ } ;
530
+
531
+ let mut slice = & self . relation [ range] ;
508
532
if !slice. is_empty ( ) {
509
533
values. retain ( |v| {
510
534
slice = gallop ( slice, |kv| & kv. 1 < v) ;
@@ -529,6 +553,7 @@ pub(crate) mod filter_with {
529
553
{
530
554
relation : & ' leap Relation < ( Key , Val ) > ,
531
555
key_func : Func ,
556
+ old_key_val : Option < ( ( Key , Val ) , bool ) > ,
532
557
phantom : :: std:: marker:: PhantomData < Tuple > ,
533
558
}
534
559
@@ -544,6 +569,7 @@ pub(crate) mod filter_with {
544
569
FilterWith {
545
570
relation,
546
571
key_func,
572
+ old_key_val : None ,
547
573
phantom : :: std:: marker:: PhantomData ,
548
574
}
549
575
}
@@ -559,11 +585,16 @@ pub(crate) mod filter_with {
559
585
{
560
586
fn count ( & mut self , prefix : & Tuple ) -> usize {
561
587
let key_val = ( self . key_func ) ( prefix) ;
562
- if self . relation . binary_search ( & key_val) . is_ok ( ) {
563
- usize:: max_value ( )
564
- } else {
565
- 0
588
+
589
+ if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
590
+ if old_key_val == & key_val {
591
+ return if is_present { usize:: MAX } else { 0 } ;
592
+ }
566
593
}
594
+
595
+ let is_present = self . relation . binary_search ( & key_val) . is_ok ( ) ;
596
+ self . old_key_val = Some ( ( key_val, is_present) ) ;
597
+ if is_present { usize:: MAX } else { 0 }
567
598
}
568
599
fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < & ' leap Val2 > ) {
569
600
panic ! ( "FilterWith::propose(): variable apparently unbound." ) ;
@@ -615,6 +646,7 @@ pub(crate) mod filter_anti {
615
646
{
616
647
relation : & ' leap Relation < ( Key , Val ) > ,
617
648
key_func : Func ,
649
+ old_key_val : Option < ( ( Key , Val ) , bool ) > ,
618
650
phantom : :: std:: marker:: PhantomData < Tuple > ,
619
651
}
620
652
@@ -630,6 +662,7 @@ pub(crate) mod filter_anti {
630
662
FilterAnti {
631
663
relation,
632
664
key_func,
665
+ old_key_val : None ,
633
666
phantom : :: std:: marker:: PhantomData ,
634
667
}
635
668
}
@@ -645,11 +678,16 @@ pub(crate) mod filter_anti {
645
678
{
646
679
fn count ( & mut self , prefix : & Tuple ) -> usize {
647
680
let key_val = ( self . key_func ) ( prefix) ;
648
- if self . relation . binary_search ( & key_val) . is_ok ( ) {
649
- 0
650
- } else {
651
- usize:: max_value ( )
681
+
682
+ if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
683
+ if old_key_val == & key_val {
684
+ return if is_present { 0 } else { usize:: MAX } ;
685
+ }
652
686
}
687
+
688
+ let is_present = self . relation . binary_search ( & key_val) . is_ok ( ) ;
689
+ self . old_key_val = Some ( ( key_val, is_present) ) ;
690
+ if is_present { 0 } else { usize:: MAX }
653
691
}
654
692
fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < & ' leap Val2 > ) {
655
693
panic ! ( "FilterAnti::propose(): variable apparently unbound." ) ;
0 commit comments