@@ -506,6 +506,7 @@ pub(crate) mod filter_with {
506
506
{
507
507
relation : & ' leap Relation < ( Key , Val ) > ,
508
508
key_func : Func ,
509
+ old_key_val : Option < ( ( Key , Val ) , bool ) > ,
509
510
phantom : :: std:: marker:: PhantomData < Tuple > ,
510
511
}
511
512
@@ -521,6 +522,7 @@ pub(crate) mod filter_with {
521
522
FilterWith {
522
523
relation,
523
524
key_func,
525
+ old_key_val : None ,
524
526
phantom : :: std:: marker:: PhantomData ,
525
527
}
526
528
}
@@ -536,11 +538,16 @@ pub(crate) mod filter_with {
536
538
{
537
539
fn count ( & mut self , prefix : & Tuple ) -> usize {
538
540
let key_val = ( self . key_func ) ( prefix) ;
539
- if self . relation . binary_search ( & key_val) . is_ok ( ) {
540
- usize:: max_value ( )
541
- } else {
542
- 0
541
+
542
+ if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
543
+ if old_key_val == & key_val {
544
+ return if is_present { usize:: MAX } else { 0 } ;
545
+ }
543
546
}
547
+
548
+ let is_present = self . relation . binary_search ( & key_val) . is_ok ( ) ;
549
+ self . old_key_val = Some ( ( key_val, is_present) ) ;
550
+ if is_present { usize:: MAX } else { 0 }
544
551
}
545
552
fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < & ' leap Val2 > ) {
546
553
panic ! ( "FilterWith::propose(): variable apparently unbound." ) ;
@@ -592,6 +599,7 @@ pub(crate) mod filter_anti {
592
599
{
593
600
relation : & ' leap Relation < ( Key , Val ) > ,
594
601
key_func : Func ,
602
+ old_key_val : Option < ( ( Key , Val ) , bool ) > ,
595
603
phantom : :: std:: marker:: PhantomData < Tuple > ,
596
604
}
597
605
@@ -607,6 +615,7 @@ pub(crate) mod filter_anti {
607
615
FilterAnti {
608
616
relation,
609
617
key_func,
618
+ old_key_val : None ,
610
619
phantom : :: std:: marker:: PhantomData ,
611
620
}
612
621
}
@@ -622,11 +631,16 @@ pub(crate) mod filter_anti {
622
631
{
623
632
fn count ( & mut self , prefix : & Tuple ) -> usize {
624
633
let key_val = ( self . key_func ) ( prefix) ;
625
- if self . relation . binary_search ( & key_val) . is_ok ( ) {
626
- 0
627
- } else {
628
- usize:: max_value ( )
634
+
635
+ if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
636
+ if old_key_val == & key_val {
637
+ return if is_present { 0 } else { usize:: MAX } ;
638
+ }
629
639
}
640
+
641
+ let is_present = self . relation . binary_search ( & key_val) . is_ok ( ) ;
642
+ self . old_key_val = Some ( ( key_val, is_present) ) ;
643
+ if is_present { 0 } else { usize:: MAX }
630
644
}
631
645
fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < & ' leap Val2 > ) {
632
646
panic ! ( "FilterAnti::propose(): variable apparently unbound." ) ;
0 commit comments