@@ -339,25 +339,15 @@ impl<T: Ord + Copy> Relation<T> {
339339 }
340340
341341 /// 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
349344 {
350345 filter_with:: FilterWith :: from ( self , key_func)
351346 }
352347
353348 /// 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
361351 {
362352 filter_anti:: FilterAnti :: from ( self , key_func)
363353 }
@@ -508,46 +498,26 @@ pub(crate) mod filter_with {
508498 use super :: { Leaper , Leapers , Relation } ;
509499
510500 /// 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 ) > ,
522505 }
523506
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 > {
531508 /// 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 }
539511 }
540512 }
541513
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 >
544515 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 ,
549519 {
550- fn count ( & mut self , prefix : & Tuple ) -> usize {
520+ fn count ( & mut self , prefix : & S ) -> usize {
551521 let key_val = ( self . key_func ) ( prefix) ;
552522
553523 if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -560,87 +530,66 @@ pub(crate) mod filter_with {
560530 self . old_key_val = Some ( ( key_val, is_present) ) ;
561531 if is_present { usize:: MAX } else { 0 }
562532 }
563- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
533+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
564534 panic ! ( "FilterWith::propose(): variable apparently unbound." ) ;
565535 }
566- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
536+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
567537 // Only here because we didn't return zero above, right?
568538 }
569539 }
570540
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 >
573542 where
574- Key : Ord + ' leap ,
575- Val : Ord + ' leap ,
576- Tuple : Ord ,
577- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
543+ Self : Leaper < S , ( ) > ,
578544 {
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 {
581547 op ( 0 , 0 )
582548 } else {
583549 op ( 0 , 1 )
584550 }
585551 }
586552
587- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
553+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
588554 assert_eq ! ( min_index, 0 ) ;
589555 values. push ( ( ) ) ;
590556 }
591557
592- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
558+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
593559 assert_eq ! ( min_index, 0 ) ;
594560 assert_eq ! ( values. len( ) , 1 ) ;
595561 }
596562 }
597563}
598564
599565pub ( crate ) mod filter_anti {
600-
601566 use super :: { Leaper , Leapers , Relation } ;
602567
603568 /// 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 ) > ,
615573 }
616574
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 > {
624576 /// 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 {
626578 FilterAnti {
627579 relation,
628580 key_func,
629581 old_key_val : None ,
630- phantom : :: std:: marker:: PhantomData ,
631582 }
632583 }
633584 }
634585
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 >
637587 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 ,
642591 {
643- fn count ( & mut self , prefix : & Tuple ) -> usize {
592+ fn count ( & mut self , prefix : & S ) -> usize {
644593 let key_val = ( self . key_func ) ( prefix) ;
645594
646595 if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -653,37 +602,33 @@ pub(crate) mod filter_anti {
653602 self . old_key_val = Some ( ( key_val, is_present) ) ;
654603 if is_present { 0 } else { usize:: MAX }
655604 }
656- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
605+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
657606 panic ! ( "FilterAnti::propose(): variable apparently unbound." ) ;
658607 }
659- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
608+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
660609 // Only here because we didn't return zero above, right?
661610 }
662611 }
663612
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 >
666614 where
667- Key : Ord + ' leap ,
668- Val : Ord + ' leap ,
669- Tuple : Ord ,
670- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
615+ Self : Leaper < S , ( ) > ,
671616 {
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 {
674619 op ( 0 , 0 )
675620 } else {
676621 op ( 0 , 1 )
677622 }
678623 }
679624
680- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
625+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
681626 // We only get here if `tuple` is *not* a member of `self.relation`
682627 assert_eq ! ( min_index, 0 ) ;
683628 values. push ( ( ) ) ;
684629 }
685630
686- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
631+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
687632 // We only get here if `tuple` is not a member of `self.relation`
688633 assert_eq ! ( min_index, 0 ) ;
689634 assert_eq ! ( values. len( ) , 1 ) ;
0 commit comments