@@ -339,25 +339,15 @@ impl<T: Ord + Copy> Relation<T> {
339
339
}
340
340
341
341
/// Extend with any value if tuple is present in relation.
342
- pub fn filter_with < ' leap , Tuple : Ord , Func : Fn ( & Tuple ) -> ( Key , Val ) > (
343
- & ' leap self ,
344
- key_func : Func ,
345
- ) -> filter_with:: FilterWith < ' leap , Key , Val , Tuple , Func >
346
- where
347
- Key : ' leap ,
348
- Val : ' leap ,
342
+ pub fn filter_with < F , S > ( & self , key_func : F ) -> filter_with:: FilterWith < ' _ , T , F >
343
+ where F : Fn ( & S ) -> T
349
344
{
350
345
filter_with:: FilterWith :: from ( self , key_func)
351
346
}
352
347
353
348
/// Extend with any value if tuple is absent from relation.
354
- pub fn filter_anti < ' leap , Tuple : Ord , Func : Fn ( & Tuple ) -> ( Key , Val ) > (
355
- & ' leap self ,
356
- key_func : Func ,
357
- ) -> filter_anti:: FilterAnti < ' leap , Key , Val , Tuple , Func >
358
- where
359
- Key : ' leap ,
360
- Val : ' leap ,
349
+ pub fn filter_anti < F , S > ( & self , key_func : F ) -> filter_anti:: FilterAnti < ' _ , T , F >
350
+ where F : Fn ( & S ) -> T
361
351
{
362
352
filter_anti:: FilterAnti :: from ( self , key_func)
363
353
}
@@ -508,46 +498,26 @@ pub(crate) mod filter_with {
508
498
use super :: { Leaper , Leapers , Relation } ;
509
499
510
500
/// Wraps a Relation<Tuple> as a leaper.
511
- pub struct FilterWith < ' leap , Key , Val , Tuple , Func >
512
- where
513
- Key : Ord + ' leap ,
514
- Val : Ord + ' leap ,
515
- Tuple : Ord ,
516
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
517
- {
518
- relation : & ' leap Relation < ( Key , Val ) > ,
519
- key_func : Func ,
520
- old_key_val : Option < ( ( Key , Val ) , bool ) > ,
521
- phantom : :: std:: marker:: PhantomData < Tuple > ,
501
+ pub struct FilterWith < ' a , T , F > {
502
+ relation : & ' a Relation < T > ,
503
+ key_func : F ,
504
+ old_key_val : Option < ( T , bool ) > ,
522
505
}
523
506
524
- impl < ' leap , Key , Val , Tuple , Func > FilterWith < ' leap , Key , Val , Tuple , Func >
525
- where
526
- Key : Ord + ' leap ,
527
- Val : Ord + ' leap ,
528
- Tuple : Ord ,
529
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
530
- {
507
+ impl < ' a , T , F > FilterWith < ' a , T , F > {
531
508
/// Constructs a FilterWith from a relation and key and value function.
532
- pub fn from ( relation : & ' leap Relation < ( Key , Val ) > , key_func : Func ) -> Self {
533
- FilterWith {
534
- relation,
535
- key_func,
536
- old_key_val : None ,
537
- phantom : :: std:: marker:: PhantomData ,
538
- }
509
+ pub fn from ( relation : & ' a Relation < T > , key_func : F ) -> Self {
510
+ FilterWith { relation, key_func, old_key_val : None }
539
511
}
540
512
}
541
513
542
- impl < ' leap , Key , Val , Val2 , Tuple , Func > Leaper < Tuple , Val2 >
543
- for FilterWith < ' leap , Key , Val , Tuple , Func >
514
+ impl < T , S , F , X > Leaper < S , X > for FilterWith < ' _ , T , F >
544
515
where
545
- Key : Ord + ' leap ,
546
- Val : Ord + ' leap ,
547
- Tuple : Ord ,
548
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
516
+ T : Ord ,
517
+ S : Ord ,
518
+ F : Fn ( & S ) -> T ,
549
519
{
550
- fn count ( & mut self , prefix : & Tuple ) -> usize {
520
+ fn count ( & mut self , prefix : & S ) -> usize {
551
521
let key_val = ( self . key_func ) ( prefix) ;
552
522
553
523
if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -560,87 +530,66 @@ pub(crate) mod filter_with {
560
530
self . old_key_val = Some ( ( key_val, is_present) ) ;
561
531
if is_present { usize:: MAX } else { 0 }
562
532
}
563
- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
533
+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
564
534
panic ! ( "FilterWith::propose(): variable apparently unbound." ) ;
565
535
}
566
- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
536
+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
567
537
// Only here because we didn't return zero above, right?
568
538
}
569
539
}
570
540
571
- impl < ' leap , Key , Val , Tuple , Func > Leapers < Tuple , ( ) >
572
- for FilterWith < ' leap , Key , Val , Tuple , Func >
541
+ impl < T , S , F > Leapers < S , ( ) > for FilterWith < ' _ , T , F >
573
542
where
574
- Key : Ord + ' leap ,
575
- Val : Ord + ' leap ,
576
- Tuple : Ord ,
577
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
543
+ Self : Leaper < S , ( ) > ,
578
544
{
579
- fn for_each_count ( & mut self , tuple : & Tuple , mut op : impl FnMut ( usize , usize ) ) {
580
- if <Self as Leaper < Tuple , ( ) > >:: count ( self , tuple) == 0 {
545
+ fn for_each_count ( & mut self , tuple : & S , mut op : impl FnMut ( usize , usize ) ) {
546
+ if <Self as Leaper < S , ( ) > >:: count ( self , tuple) == 0 {
581
547
op ( 0 , 0 )
582
548
} else {
583
549
op ( 0 , 1 )
584
550
}
585
551
}
586
552
587
- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
553
+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
588
554
assert_eq ! ( min_index, 0 ) ;
589
555
values. push ( ( ) ) ;
590
556
}
591
557
592
- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
558
+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
593
559
assert_eq ! ( min_index, 0 ) ;
594
560
assert_eq ! ( values. len( ) , 1 ) ;
595
561
}
596
562
}
597
563
}
598
564
599
565
pub ( crate ) mod filter_anti {
600
-
601
566
use super :: { Leaper , Leapers , Relation } ;
602
567
603
568
/// Wraps a Relation<Tuple> as a leaper.
604
- pub struct FilterAnti < ' leap , Key , Val , Tuple , Func >
605
- where
606
- Key : Ord + ' leap ,
607
- Val : Ord + ' leap ,
608
- Tuple : Ord ,
609
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
610
- {
611
- relation : & ' leap Relation < ( Key , Val ) > ,
612
- key_func : Func ,
613
- old_key_val : Option < ( ( Key , Val ) , bool ) > ,
614
- phantom : :: std:: marker:: PhantomData < Tuple > ,
569
+ pub struct FilterAnti < ' a , T , F > {
570
+ relation : & ' a Relation < T > ,
571
+ key_func : F ,
572
+ old_key_val : Option < ( T , bool ) > ,
615
573
}
616
574
617
- impl < ' leap , Key , Val , Tuple , Func > FilterAnti < ' leap , Key , Val , Tuple , Func >
618
- where
619
- Key : Ord + ' leap ,
620
- Val : Ord + ' leap ,
621
- Tuple : Ord ,
622
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
623
- {
575
+ impl < ' a , T , F > FilterAnti < ' a , T , F > {
624
576
/// Constructs a FilterAnti from a relation and key and value function.
625
- pub fn from ( relation : & ' leap Relation < ( Key , Val ) > , key_func : Func ) -> Self {
577
+ pub fn from ( relation : & ' a Relation < T > , key_func : F ) -> Self {
626
578
FilterAnti {
627
579
relation,
628
580
key_func,
629
581
old_key_val : None ,
630
- phantom : :: std:: marker:: PhantomData ,
631
582
}
632
583
}
633
584
}
634
585
635
- impl < ' leap , Key : Ord , Val : Ord + ' leap , Val2 , Tuple : Ord , Func > Leaper < Tuple , Val2 >
636
- for FilterAnti < ' leap , Key , Val , Tuple , Func >
586
+ impl < T , S , F , X > Leaper < S , X > for FilterAnti < ' _ , T , F >
637
587
where
638
- Key : Ord + ' leap ,
639
- Val : Ord + ' leap ,
640
- Tuple : Ord ,
641
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
588
+ T : Ord ,
589
+ S : Ord ,
590
+ F : Fn ( & S ) -> T ,
642
591
{
643
- fn count ( & mut self , prefix : & Tuple ) -> usize {
592
+ fn count ( & mut self , prefix : & S ) -> usize {
644
593
let key_val = ( self . key_func ) ( prefix) ;
645
594
646
595
if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -653,37 +602,33 @@ pub(crate) mod filter_anti {
653
602
self . old_key_val = Some ( ( key_val, is_present) ) ;
654
603
if is_present { 0 } else { usize:: MAX }
655
604
}
656
- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
605
+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
657
606
panic ! ( "FilterAnti::propose(): variable apparently unbound." ) ;
658
607
}
659
- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
608
+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
660
609
// Only here because we didn't return zero above, right?
661
610
}
662
611
}
663
612
664
- impl < ' leap , Key , Val , Tuple , Func > Leapers < Tuple , ( ) >
665
- for FilterAnti < ' leap , Key , Val , Tuple , Func >
613
+ impl < T , S , F > Leapers < S , ( ) > for FilterAnti < ' _ , T , F >
666
614
where
667
- Key : Ord + ' leap ,
668
- Val : Ord + ' leap ,
669
- Tuple : Ord ,
670
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
615
+ Self : Leaper < S , ( ) > ,
671
616
{
672
- fn for_each_count ( & mut self , tuple : & Tuple , mut op : impl FnMut ( usize , usize ) ) {
673
- if <Self as Leaper < Tuple , ( ) > >:: count ( self , tuple) == 0 {
617
+ fn for_each_count ( & mut self , tuple : & S , mut op : impl FnMut ( usize , usize ) ) {
618
+ if <Self as Leaper < S , ( ) > >:: count ( self , tuple) == 0 {
674
619
op ( 0 , 0 )
675
620
} else {
676
621
op ( 0 , 1 )
677
622
}
678
623
}
679
624
680
- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
625
+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
681
626
// We only get here if `tuple` is *not* a member of `self.relation`
682
627
assert_eq ! ( min_index, 0 ) ;
683
628
values. push ( ( ) ) ;
684
629
}
685
630
686
- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
631
+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
687
632
// We only get here if `tuple` is not a member of `self.relation`
688
633
assert_eq ! ( min_index, 0 ) ;
689
634
assert_eq ! ( values. len( ) , 1 ) ;
0 commit comments