Skip to content

Commit f6b2241

Browse files
committed
antijoin bug v2
1 parent c577a6c commit f6b2241

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ fn main() {
2525

2626
// .. and then start iterating rules!
2727
while iteration.changed() {
28-
// nodes(a,c) <- nodes(a,b), edges(b,c)
28+
// nodes(a,c) <- nodes(a,b), edges(b,c)
2929
nodes_var.from_join(&nodes_var, &edges_var, |_b, &a, &c| (c,a));
3030
}
3131

32-
// extract a `Vec<(u32,u32)>` containing the final results.
33-
let reachable = variable.complete();
32+
// extract the final results.
33+
let reachable: Vec<(u32,u32)> = variable.complete();
3434
}
3535
```

src/join.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ pub fn antijoin_into<Key: Ord, Val: Ord, Result: Ord, F: Fn(&Key, &Val)->Result>
4343
}
4444
}
4545

46-
// elements should be in-order, as just a filter.
47-
let relation = Relation { elements: results };
48-
output.insert(relation);
46+
output.insert(results.into());
4947
}
5048

5149
fn join_helper<K: Ord, V1, V2, F: FnMut(&K, &V1, &V2)>(mut slice1: &[(K,V1)], mut slice2: &[(K,V2)], mut result: F) {
@@ -54,12 +52,12 @@ fn join_helper<K: Ord, V1, V2, F: FnMut(&K, &V1, &V2)>(mut slice1: &[(K,V1)], mu
5452

5553
if slice1[0].0 == slice2[0].0 {
5654

57-
let mut key1_count = 0;
55+
let mut key1_count = 1;
5856
while key1_count < slice1.len() && slice1[0].0 == slice1[key1_count].0 {
5957
key1_count += 1;
6058
}
6159

62-
let mut key2_count = 0;
60+
let mut key2_count = 1;
6361
while key2_count < slice2.len() && slice2[0].0 == slice2[key2_count].0 {
6462
key2_count += 1;
6563
}

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<Tuple: Ord> Variable<Tuple> {
149149
/// pairs are symmetric, this should result in all pairs (x, y) for x and y in 0 .. 11.
150150
///
151151
/// ```
152-
/// use datafrog::*;
152+
/// use datafrog::{Iteration, Relation};
153153
///
154154
/// let mut iteration = Iteration::new();
155155
/// let variable = iteration.variable::<(usize, usize)>("source");
@@ -180,7 +180,7 @@ impl<Tuple: Ord> Variable<Tuple> {
180180
/// pairs (for 0, 3, 6, and 9) which should leave us with 16 total pairs.
181181
///
182182
/// ```
183-
/// use datafrog::*;
183+
/// use datafrog::{Iteration, Relation};
184184
///
185185
/// let mut iteration = Iteration::new();
186186
/// let variable = iteration.variable::<(usize, usize)>("source");
@@ -213,7 +213,7 @@ impl<Tuple: Ord> Variable<Tuple> {
213213
/// pairs (x, y) where x visits y as part of its Collatz journey.
214214
///
215215
/// ```
216-
/// use datafrog::*;
216+
/// use datafrog::{Iteration, Relation};
217217
///
218218
/// let mut iteration = Iteration::new();
219219
/// let variable = iteration.variable::<(usize, usize)>("source");
@@ -294,7 +294,9 @@ impl<Tuple: Ord> VariableTrait for Variable<Tuple> {
294294
let last = self.tuples.borrow_mut().pop().unwrap();
295295
recent = recent.merge(last);
296296
}
297-
self.tuples.borrow_mut().push(recent);
297+
if !recent.is_empty() {
298+
self.tuples.borrow_mut().push(recent);
299+
}
298300

299301
// 2. Move self.to_add into self.recent.
300302
let to_add = self.to_add.borrow_mut().pop();

0 commit comments

Comments
 (0)