@@ -315,25 +315,15 @@ impl<T: Ord + Copy> Relation<T> {
315315 }
316316
317317 /// Extend with any value if tuple is present in relation.
318- pub fn filter_with < ' leap , Tuple : Ord , Func : Fn ( & Tuple ) -> ( Key , Val ) > (
319- & ' leap self ,
320- key_func : Func ,
321- ) -> filter_with:: FilterWith < ' leap , Key , Val , Tuple , Func >
322- where
323- Key : ' leap ,
324- Val : ' leap ,
318+ pub fn filter_with < F , S > ( & self , key_func : F ) -> filter_with:: FilterWith < ' _ , T , F >
319+ where F : Fn ( & S ) -> T
325320 {
326321 filter_with:: FilterWith :: from ( self , key_func)
327322 }
328323
329324 /// Extend with any value if tuple is absent from relation.
330- pub fn filter_anti < ' leap , Tuple : Ord , Func : Fn ( & Tuple ) -> ( Key , Val ) > (
331- & ' leap self ,
332- key_func : Func ,
333- ) -> filter_anti:: FilterAnti < ' leap , Key , Val , Tuple , Func >
334- where
335- Key : ' leap ,
336- Val : ' leap ,
325+ pub fn filter_anti < F , S > ( & self , key_func : F ) -> filter_anti:: FilterAnti < ' _ , T , F >
326+ where F : Fn ( & S ) -> T
337327 {
338328 filter_anti:: FilterAnti :: from ( self , key_func)
339329 }
@@ -484,46 +474,26 @@ pub(crate) mod filter_with {
484474 use super :: { Leaper , Leapers , Relation } ;
485475
486476 /// Wraps a Relation<Tuple> as a leaper.
487- pub struct FilterWith < ' leap , Key , Val , Tuple , Func >
488- where
489- Key : Ord + ' leap ,
490- Val : Ord + ' leap ,
491- Tuple : Ord ,
492- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
493- {
494- relation : & ' leap Relation < ( Key , Val ) > ,
495- key_func : Func ,
496- old_key_val : Option < ( ( Key , Val ) , bool ) > ,
497- phantom : :: std:: marker:: PhantomData < Tuple > ,
477+ pub struct FilterWith < ' a , T , F > {
478+ relation : & ' a Relation < T > ,
479+ key_func : F ,
480+ old_key_val : Option < ( T , bool ) > ,
498481 }
499482
500- impl < ' leap , Key , Val , Tuple , Func > FilterWith < ' leap , Key , Val , Tuple , Func >
501- where
502- Key : Ord + ' leap ,
503- Val : Ord + ' leap ,
504- Tuple : Ord ,
505- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
506- {
483+ impl < ' a , T , F > FilterWith < ' a , T , F > {
507484 /// Constructs a FilterWith from a relation and key and value function.
508- pub fn from ( relation : & ' leap Relation < ( Key , Val ) > , key_func : Func ) -> Self {
509- FilterWith {
510- relation,
511- key_func,
512- old_key_val : None ,
513- phantom : :: std:: marker:: PhantomData ,
514- }
485+ pub fn from ( relation : & ' a Relation < T > , key_func : F ) -> Self {
486+ FilterWith { relation, key_func, old_key_val : None }
515487 }
516488 }
517489
518- impl < ' leap , Key , Val , Val2 , Tuple , Func > Leaper < Tuple , Val2 >
519- for FilterWith < ' leap , Key , Val , Tuple , Func >
490+ impl < T , S , F , X > Leaper < S , X > for FilterWith < ' _ , T , F >
520491 where
521- Key : Ord + ' leap ,
522- Val : Ord + ' leap ,
523- Tuple : Ord ,
524- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
492+ T : Ord ,
493+ S : Ord ,
494+ F : Fn ( & S ) -> T ,
525495 {
526- fn count ( & mut self , prefix : & Tuple ) -> usize {
496+ fn count ( & mut self , prefix : & S ) -> usize {
527497 let key_val = ( self . key_func ) ( prefix) ;
528498
529499 if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -536,87 +506,66 @@ pub(crate) mod filter_with {
536506 self . old_key_val = Some ( ( key_val, is_present) ) ;
537507 if is_present { usize:: MAX } else { 0 }
538508 }
539- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
509+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
540510 panic ! ( "FilterWith::propose(): variable apparently unbound." ) ;
541511 }
542- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
512+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
543513 // Only here because we didn't return zero above, right?
544514 }
545515 }
546516
547- impl < ' leap , Key , Val , Tuple , Func > Leapers < Tuple , ( ) >
548- for FilterWith < ' leap , Key , Val , Tuple , Func >
517+ impl < T , S , F > Leapers < S , ( ) > for FilterWith < ' _ , T , F >
549518 where
550- Key : Ord + ' leap ,
551- Val : Ord + ' leap ,
552- Tuple : Ord ,
553- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
519+ Self : Leaper < S , ( ) > ,
554520 {
555- fn for_each_count ( & mut self , tuple : & Tuple , mut op : impl FnMut ( usize , usize ) ) {
556- if <Self as Leaper < Tuple , ( ) > >:: count ( self , tuple) == 0 {
521+ fn for_each_count ( & mut self , tuple : & S , mut op : impl FnMut ( usize , usize ) ) {
522+ if <Self as Leaper < S , ( ) > >:: count ( self , tuple) == 0 {
557523 op ( 0 , 0 )
558524 } else {
559525 op ( 0 , 1 )
560526 }
561527 }
562528
563- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
529+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
564530 assert_eq ! ( min_index, 0 ) ;
565531 values. push ( ( ) ) ;
566532 }
567533
568- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
534+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
569535 assert_eq ! ( min_index, 0 ) ;
570536 assert_eq ! ( values. len( ) , 1 ) ;
571537 }
572538 }
573539}
574540
575541pub ( crate ) mod filter_anti {
576-
577542 use super :: { Leaper , Leapers , Relation } ;
578543
579544 /// Wraps a Relation<Tuple> as a leaper.
580- pub struct FilterAnti < ' leap , Key , Val , Tuple , Func >
581- where
582- Key : Ord + ' leap ,
583- Val : Ord + ' leap ,
584- Tuple : Ord ,
585- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
586- {
587- relation : & ' leap Relation < ( Key , Val ) > ,
588- key_func : Func ,
589- old_key_val : Option < ( ( Key , Val ) , bool ) > ,
590- phantom : :: std:: marker:: PhantomData < Tuple > ,
545+ pub struct FilterAnti < ' a , T , F > {
546+ relation : & ' a Relation < T > ,
547+ key_func : F ,
548+ old_key_val : Option < ( T , bool ) > ,
591549 }
592550
593- impl < ' leap , Key , Val , Tuple , Func > FilterAnti < ' leap , Key , Val , Tuple , Func >
594- where
595- Key : Ord + ' leap ,
596- Val : Ord + ' leap ,
597- Tuple : Ord ,
598- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
599- {
551+ impl < ' a , T , F > FilterAnti < ' a , T , F > {
600552 /// Constructs a FilterAnti from a relation and key and value function.
601- pub fn from ( relation : & ' leap Relation < ( Key , Val ) > , key_func : Func ) -> Self {
553+ pub fn from ( relation : & ' a Relation < T > , key_func : F ) -> Self {
602554 FilterAnti {
603555 relation,
604556 key_func,
605557 old_key_val : None ,
606- phantom : :: std:: marker:: PhantomData ,
607558 }
608559 }
609560 }
610561
611- impl < ' leap , Key : Ord , Val : Ord + ' leap , Val2 , Tuple : Ord , Func > Leaper < Tuple , Val2 >
612- for FilterAnti < ' leap , Key , Val , Tuple , Func >
562+ impl < T , S , F , X > Leaper < S , X > for FilterAnti < ' _ , T , F >
613563 where
614- Key : Ord + ' leap ,
615- Val : Ord + ' leap ,
616- Tuple : Ord ,
617- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
564+ T : Ord ,
565+ S : Ord ,
566+ F : Fn ( & S ) -> T ,
618567 {
619- fn count ( & mut self , prefix : & Tuple ) -> usize {
568+ fn count ( & mut self , prefix : & S ) -> usize {
620569 let key_val = ( self . key_func ) ( prefix) ;
621570
622571 if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -629,37 +578,33 @@ pub(crate) mod filter_anti {
629578 self . old_key_val = Some ( ( key_val, is_present) ) ;
630579 if is_present { 0 } else { usize:: MAX }
631580 }
632- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
581+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
633582 panic ! ( "FilterAnti::propose(): variable apparently unbound." ) ;
634583 }
635- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
584+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
636585 // Only here because we didn't return zero above, right?
637586 }
638587 }
639588
640- impl < ' leap , Key , Val , Tuple , Func > Leapers < Tuple , ( ) >
641- for FilterAnti < ' leap , Key , Val , Tuple , Func >
589+ impl < T , S , F > Leapers < S , ( ) > for FilterAnti < ' _ , T , F >
642590 where
643- Key : Ord + ' leap ,
644- Val : Ord + ' leap ,
645- Tuple : Ord ,
646- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
591+ Self : Leaper < S , ( ) > ,
647592 {
648- fn for_each_count ( & mut self , tuple : & Tuple , mut op : impl FnMut ( usize , usize ) ) {
649- if <Self as Leaper < Tuple , ( ) > >:: count ( self , tuple) == 0 {
593+ fn for_each_count ( & mut self , tuple : & S , mut op : impl FnMut ( usize , usize ) ) {
594+ if <Self as Leaper < S , ( ) > >:: count ( self , tuple) == 0 {
650595 op ( 0 , 0 )
651596 } else {
652597 op ( 0 , 1 )
653598 }
654599 }
655600
656- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
601+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
657602 // We only get here if `tuple` is *not* a member of `self.relation`
658603 assert_eq ! ( min_index, 0 ) ;
659604 values. push ( ( ) ) ;
660605 }
661606
662- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
607+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
663608 // We only get here if `tuple` is not a member of `self.relation`
664609 assert_eq ! ( min_index, 0 ) ;
665610 assert_eq ! ( values. len( ) , 1 ) ;
0 commit comments