Skip to content

Commit de7ad5a

Browse files
Merge pull request #42 from michalt/from_antijoin
Fix `Relation::from_antijoin` (issue #39)
2 parents 4472c35 + 1bcac7d commit de7ad5a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/join.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ pub(crate) fn join_into_relation<'me, Key: Ord, Val1: Ord, Val2: Ord, Result: Or
7878
}
7979

8080
/// Moves all recent tuples from `input1` that are not present in `input2` into `output`.
81-
pub(crate) fn antijoin<'me, Key: Ord, Val: Ord, Result: Ord>(
82-
input1: impl JoinInput<'me, (Key, Val)>,
81+
pub(crate) fn antijoin<Key: Ord, Val: Ord, Result: Ord>(
82+
input1: &Relation<(Key, Val)>,
8383
input2: &Relation<Key>,
8484
mut logic: impl FnMut(&Key, &Val) -> Result,
8585
) -> Relation<Result> {
8686
let mut tuples2 = &input2[..];
8787

8888
let results = input1
89-
.recent()
89+
.elements
9090
.iter()
9191
.filter(|(ref key, _)| {
9292
tuples2 = gallop(tuples2, |k| k < key);

src/test.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,14 @@ fn passthrough_leaper() {
219219
expected.extend((20..=40).filter_map(|i| (i%4 == 0).then(|| (i, i))));
220220
assert_eq!(&*variable, &expected);
221221
}
222+
223+
#[test]
224+
fn relation_from_antijoin() {
225+
let lhs: Relation<_> = (0 .. 10).map(|x| (x, x)).collect();
226+
let rhs: Relation<_> = (0 .. 10).filter(|x| x % 2 == 0).collect();
227+
let expected: Relation<_> = (0 .. 10).filter(|x| x % 2 == 1).map(|x| (x, x)).collect();
228+
229+
let result = Relation::from_antijoin(&lhs, &rhs, |a, b| (*a, *b));
230+
231+
assert_eq!(result.elements, expected.elements);
232+
}

src/variable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<Tuple: Ord> Variable<Tuple> {
177177
input2: &Relation<K>,
178178
logic: impl FnMut(&K, &V) -> Tuple,
179179
) {
180-
self.insert(join::antijoin(input1, input2, logic))
180+
self.insert(join::antijoin(&input1.recent.borrow(), input2, logic))
181181
}
182182

183183
/// Adds tuples that result from mapping `input`.

0 commit comments

Comments
 (0)