2
2
3
3
use super :: { Variable , Relation } ;
4
4
5
- pub fn join_into < Key : Ord , Val1 : Ord , Val2 : Ord , Result : Ord , F : Fn ( & Key , & Val1 , & Val2 ) -> Result > (
5
+ pub fn join_into < Key : Ord , Val1 : Ord , Val2 : Ord , Result : Ord > (
6
6
input1 : & Variable < ( Key , Val1 ) > ,
7
7
input2 : & Variable < ( Key , Val2 ) > ,
8
8
output : & Variable < Result > ,
9
- logic : F ) {
9
+ mut logic : impl FnMut ( & Key , & Val1 , & Val2 ) -> Result ) {
10
10
11
11
let mut results = Vec :: new ( ) ;
12
12
13
13
let recent1 = input1. recent . borrow ( ) ;
14
14
let recent2 = input2. recent . borrow ( ) ;
15
15
16
- for batch2 in input2. stable . borrow ( ) . iter ( ) {
17
- join_helper ( & recent1, & batch2, |k, v1, v2| results. push ( logic ( k, v1, v2) ) ) ;
18
- }
16
+ { // scoped to let `closure` drop borrow of `results`.
19
17
20
- for batch1 in input1. stable . borrow ( ) . iter ( ) {
21
- join_helper ( & batch1, & recent2, |k, v1, v2| results. push ( logic ( k, v1, v2) ) ) ;
22
- }
18
+ let mut closure = |k : & Key , v1 : & Val1 , v2 : & Val2 | results. push ( logic ( k, v1, v2) ) ;
19
+
20
+ for batch2 in input2. stable . borrow ( ) . iter ( ) {
21
+ join_helper ( & recent1, & batch2, & mut closure) ;
22
+ }
23
23
24
- join_helper ( & recent1, & recent2, |k, v1, v2| results. push ( logic ( k, v1, v2) ) ) ;
24
+ for batch1 in input1. stable . borrow ( ) . iter ( ) {
25
+ join_helper ( & batch1, & recent2, & mut closure) ;
26
+ }
27
+
28
+ join_helper ( & recent1, & recent2, & mut closure) ;
29
+ }
25
30
26
31
output. insert ( Relation :: from_vec ( results) ) ;
27
32
}
28
33
29
34
/// Moves all recent tuples from `input1` that are not present in `input2` into `output`.
30
- pub fn antijoin_into < Key : Ord , Val : Ord , Result : Ord , F : Fn ( & Key , & Val ) -> Result > (
35
+ pub fn antijoin_into < Key : Ord , Val : Ord , Result : Ord > (
31
36
input1 : & Variable < ( Key , Val ) > ,
32
37
input2 : & Relation < Key > ,
33
38
output : & Variable < Result > ,
34
- logic : F ) {
39
+ mut logic : impl FnMut ( & Key , & Val ) -> Result ) {
35
40
36
41
let mut results = Vec :: new ( ) ;
37
42
let mut tuples2 = & input2[ ..] ;
@@ -46,7 +51,10 @@ pub fn antijoin_into<Key: Ord, Val: Ord, Result: Ord, F: Fn(&Key, &Val)->Result>
46
51
output. insert ( Relation :: from_vec ( results) ) ;
47
52
}
48
53
49
- fn join_helper < K : Ord , V1 , V2 , F : FnMut ( & K , & V1 , & V2 ) > ( mut slice1 : & [ ( K , V1 ) ] , mut slice2 : & [ ( K , V2 ) ] , mut result : F ) {
54
+ fn join_helper < K : Ord , V1 , V2 > (
55
+ mut slice1 : & [ ( K , V1 ) ] ,
56
+ mut slice2 : & [ ( K , V2 ) ] ,
57
+ mut result : impl FnMut ( & K , & V1 , & V2 ) ) {
50
58
51
59
while !slice1. is_empty ( ) && !slice2. is_empty ( ) {
52
60
@@ -81,7 +89,7 @@ fn join_helper<K: Ord, V1, V2, F: FnMut(&K, &V1, &V2)>(mut slice1: &[(K,V1)], mu
81
89
}
82
90
}
83
91
84
- pub fn gallop < T , F : Fn ( & T ) -> bool > ( mut slice : & [ T ] , cmp : F ) -> & [ T ] {
92
+ pub fn gallop < T > ( mut slice : & [ T ] , mut cmp : impl FnMut ( & T ) -> bool ) -> & [ T ] {
85
93
// if empty slice, or already >= element, return
86
94
if slice. len ( ) > 0 && cmp ( & slice[ 0 ] ) {
87
95
let mut step = 1 ;
0 commit comments