Skip to content

Commit d4f98f9

Browse files
Update tests with new join/antijoin interface
1 parent b02d36b commit d4f98f9

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/test.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn inputs() -> impl Strategy<Value = Vec<(u32, u32)>> {
1111

1212
/// The original way to use datafrog -- computes reachable nodes from a set of edges
1313
fn reachable_with_var_join(edges: &[(u32, u32)]) -> Relation<(u32, u32)> {
14-
let edges: Relation<_> = edges.iter().collect();
14+
let edges: Relation<(u32, u32)> = edges.iter().collect();
1515
let mut iteration = Iteration::new();
1616

1717
let edges_by_successor = iteration.variable::<(u32, u32)>("edges_invert");
@@ -22,15 +22,15 @@ fn reachable_with_var_join(edges: &[(u32, u32)]) -> Relation<(u32, u32)> {
2222

2323
while iteration.changed() {
2424
// reachable(N1, N3) :- edges(N1, N2), reachable(N2, N3).
25-
reachable.from_join(&reachable, &edges_by_successor, |&_, &n3, &n1| (n1, n3));
25+
reachable.from_join(&reachable, &edges_by_successor, |_: (u32,), n3, n1| (n1, n3));
2626
}
2727

2828
reachable.complete()
2929
}
3030

3131
/// Like `reachable`, but using a relation as an input to `from_join`
3232
fn reachable_with_relation_join(edges: &[(u32, u32)]) -> Relation<(u32, u32)> {
33-
let edges: Relation<_> = edges.iter().collect();
33+
let edges: Relation<(u32, u32)> = edges.iter().collect();
3434
let mut iteration = Iteration::new();
3535

3636
// NB. Changed from `reachable_with_var_join`:
@@ -41,7 +41,7 @@ fn reachable_with_relation_join(edges: &[(u32, u32)]) -> Relation<(u32, u32)> {
4141

4242
while iteration.changed() {
4343
// reachable(N1, N3) :- edges(N1, N2), reachable(N2, N3).
44-
reachable.from_join(&reachable, &edges_by_successor, |&_, &n3, &n1| (n1, n3));
44+
reachable.from_join(&reachable, &edges_by_successor, |_: (u32,), n3, n1| (n1, n3));
4545
}
4646

4747
reachable.complete()
@@ -60,7 +60,7 @@ fn reachable_with_leapfrog(edges: &[(u32, u32)]) -> Relation<(u32, u32)> {
6060
// reachable(N1, N3) :- edges(N1, N2), reachable(N2, N3).
6161
reachable.from_leapjoin(
6262
&reachable,
63-
edges_by_successor.extend_with(|&(n2, _)| n2),
63+
edges_by_successor.extend_with(|&(n2, _)| (n2,)),
6464
|&(_, n3), &n1| (n1, n3),
6565
);
6666
}
@@ -86,7 +86,7 @@ fn sum_join_via_var(
8686

8787
while iteration.changed() {
8888
// output(K1, V1 * 100 + V2) :- input1(K1, V1), input2(K1, V2).
89-
output.from_join(&input1, &input2, |&k1, &v1, &v2| (k1, v1 * 100 + v2));
89+
output.from_join(&input1, &input2, |(k1,), v1, v2| (k1, v1 * 100 + v2));
9090
}
9191

9292
output.complete()
@@ -98,9 +98,9 @@ fn sum_join_via_relation(
9898
input1_slice: &[(u32, u32)],
9999
input2_slice: &[(u32, u32)],
100100
) -> Relation<(u32, u32)> {
101-
let input1: Relation<_> = input1_slice.iter().collect();
102-
let input2: Relation<_> = input2_slice.iter().collect();
103-
Relation::from_join(&input1, &input2, |&k1, &v1, &v2| (k1, v1 * 100 + v2))
101+
let input1: Relation<(u32, u32)> = input1_slice.iter().collect();
102+
let input2: Relation<(u32, u32)> = input2_slice.iter().collect();
103+
Relation::from_join(&input1, &input2, |(k1,), v1, v2| (k1, v1 * 100 + v2))
104104
}
105105

106106
proptest! {
@@ -183,7 +183,7 @@ fn leapjoin_from_extend() {
183183
while iteration.changed() {
184184
variable.from_leapjoin(
185185
&variable,
186-
doubles.extend_with(|&(i, _)| i),
186+
doubles.extend_with(|&(i, _)| (i,)),
187187
|&(i, _), &j| (i, j),
188188
);
189189
}
@@ -221,11 +221,11 @@ fn passthrough_leaper() {
221221

222222
#[test]
223223
fn relation_from_antijoin() {
224-
let lhs: Relation<_> = (0 .. 10).map(|x| (x, x)).collect();
225-
let rhs: Relation<_> = (0 .. 10).filter(|x| x % 2 == 0).collect();
224+
let lhs: Relation<(u32, u32)> = (0 .. 10).map(|x| (x, x)).collect();
225+
let rhs: Relation<(u32,)> = (0 .. 10).filter(|x| x % 2 == 0).map(|x| (x,)).collect();
226226
let expected: Relation<_> = (0 .. 10).filter(|x| x % 2 == 1).map(|x| (x, x)).collect();
227227

228-
let result = Relation::from_antijoin(&lhs, &rhs, |a, b| (*a, *b));
228+
let result = Relation::from_antijoin(&lhs, &rhs, |x| x);
229229

230230
assert_eq!(result.elements, expected.elements);
231231
}

src/variable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<Tuple: Ord> Variable<Tuple> {
8484
/// variable.extend((0 .. 10).map(|x| (x + 1, x)));
8585
///
8686
/// while iteration.changed() {
87-
/// variable.from_join(&variable, &variable, |&key, &val1, &val2| (val1, val2));
87+
/// variable.from_join(&variable, &variable, |key: (usize,), val1, val2| (val1, val2));
8888
/// }
8989
///
9090
/// let result = variable.complete();
@@ -120,7 +120,7 @@ impl<Tuple: Ord> Variable<Tuple> {
120120
/// variable.extend((0 .. 10).map(|x| (x + 1, x)));
121121
///
122122
/// while iteration.changed() {
123-
/// variable.from_join_filtered(&variable, &variable, |&key, &val1, &val2| {
123+
/// variable.from_join_filtered(&variable, &variable, |key: (isize,), val1, val2| {
124124
/// ((val1 - val2).abs() <= 3).then(|| (val1, val2))
125125
/// });
126126
/// }
@@ -171,10 +171,10 @@ impl<Tuple: Ord> Variable<Tuple> {
171171
/// let variable = iteration.variable::<(usize, usize)>("source");
172172
/// variable.extend((0 .. 10).map(|x| (x, x + 1)));
173173
///
174-
/// let relation: Relation<_> = (0 .. 10).filter(|x| x % 3 == 0).collect();
174+
/// let relation: Relation<_> = (0 .. 10).filter(|x| x % 3 == 0).map(|x| (x,)).collect();
175175
///
176176
/// while iteration.changed() {
177-
/// variable.from_antijoin(&variable, &relation, |&key, &val| (val, key));
177+
/// variable.from_antijoin(&variable, &relation, |(key, val)| (val, key));
178178
/// }
179179
///
180180
/// let result = variable.complete();

0 commit comments

Comments
 (0)