@@ -315,25 +315,15 @@ impl<T: Ord + Copy> Relation<T> {
315
315
}
316
316
317
317
/// 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
325
320
{
326
321
filter_with:: FilterWith :: from ( self , key_func)
327
322
}
328
323
329
324
/// 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
337
327
{
338
328
filter_anti:: FilterAnti :: from ( self , key_func)
339
329
}
@@ -484,46 +474,26 @@ pub(crate) mod filter_with {
484
474
use super :: { Leaper , Leapers , Relation } ;
485
475
486
476
/// 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 ) > ,
498
481
}
499
482
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 > {
507
484
/// 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 }
515
487
}
516
488
}
517
489
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 >
520
491
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 ,
525
495
{
526
- fn count ( & mut self , prefix : & Tuple ) -> usize {
496
+ fn count ( & mut self , prefix : & S ) -> usize {
527
497
let key_val = ( self . key_func ) ( prefix) ;
528
498
529
499
if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -536,87 +506,66 @@ pub(crate) mod filter_with {
536
506
self . old_key_val = Some ( ( key_val, is_present) ) ;
537
507
if is_present { usize:: MAX } else { 0 }
538
508
}
539
- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
509
+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
540
510
panic ! ( "FilterWith::propose(): variable apparently unbound." ) ;
541
511
}
542
- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
512
+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
543
513
// Only here because we didn't return zero above, right?
544
514
}
545
515
}
546
516
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 >
549
518
where
550
- Key : Ord + ' leap ,
551
- Val : Ord + ' leap ,
552
- Tuple : Ord ,
553
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
519
+ Self : Leaper < S , ( ) > ,
554
520
{
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 {
557
523
op ( 0 , 0 )
558
524
} else {
559
525
op ( 0 , 1 )
560
526
}
561
527
}
562
528
563
- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
529
+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
564
530
assert_eq ! ( min_index, 0 ) ;
565
531
values. push ( ( ) ) ;
566
532
}
567
533
568
- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
534
+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
569
535
assert_eq ! ( min_index, 0 ) ;
570
536
assert_eq ! ( values. len( ) , 1 ) ;
571
537
}
572
538
}
573
539
}
574
540
575
541
pub ( crate ) mod filter_anti {
576
-
577
542
use super :: { Leaper , Leapers , Relation } ;
578
543
579
544
/// 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 ) > ,
591
549
}
592
550
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 > {
600
552
/// 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 {
602
554
FilterAnti {
603
555
relation,
604
556
key_func,
605
557
old_key_val : None ,
606
- phantom : :: std:: marker:: PhantomData ,
607
558
}
608
559
}
609
560
}
610
561
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 >
613
563
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 ,
618
567
{
619
- fn count ( & mut self , prefix : & Tuple ) -> usize {
568
+ fn count ( & mut self , prefix : & S ) -> usize {
620
569
let key_val = ( self . key_func ) ( prefix) ;
621
570
622
571
if let Some ( ( ref old_key_val, is_present) ) = self . old_key_val {
@@ -629,37 +578,33 @@ pub(crate) mod filter_anti {
629
578
self . old_key_val = Some ( ( key_val, is_present) ) ;
630
579
if is_present { 0 } else { usize:: MAX }
631
580
}
632
- fn propose ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
581
+ fn propose ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
633
582
panic ! ( "FilterAnti::propose(): variable apparently unbound." ) ;
634
583
}
635
- fn intersect ( & mut self , _prefix : & Tuple , _values : & mut Vec < Val2 > ) {
584
+ fn intersect ( & mut self , _prefix : & S , _values : & mut Vec < X > ) {
636
585
// Only here because we didn't return zero above, right?
637
586
}
638
587
}
639
588
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 >
642
590
where
643
- Key : Ord + ' leap ,
644
- Val : Ord + ' leap ,
645
- Tuple : Ord ,
646
- Func : Fn ( & Tuple ) -> ( Key , Val ) ,
591
+ Self : Leaper < S , ( ) > ,
647
592
{
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 {
650
595
op ( 0 , 0 )
651
596
} else {
652
597
op ( 0 , 1 )
653
598
}
654
599
}
655
600
656
- fn propose ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
601
+ fn propose ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
657
602
// We only get here if `tuple` is *not* a member of `self.relation`
658
603
assert_eq ! ( min_index, 0 ) ;
659
604
values. push ( ( ) ) ;
660
605
}
661
606
662
- fn intersect ( & mut self , _: & Tuple , min_index : usize , values : & mut Vec < ( ) > ) {
607
+ fn intersect ( & mut self , _: & S , min_index : usize , values : & mut Vec < ( ) > ) {
663
608
// We only get here if `tuple` is not a member of `self.relation`
664
609
assert_eq ! ( min_index, 0 ) ;
665
610
assert_eq ! ( values. len( ) , 1 ) ;
0 commit comments