Skip to content

Commit 22e1b54

Browse files
Support antijoins on arbitrary prefixes
1 parent 3fcd2a3 commit 22e1b54

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/join.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,26 @@ where
9898
}
9999

100100
/// Moves all recent tuples from `input1` that are not present in `input2` into `output`.
101-
pub(crate) fn antijoin<Key: Ord, Val: Ord, Result: Ord>(
102-
input1: &Relation<(Key, Val)>,
103-
input2: &Relation<Key>,
104-
mut logic: impl FnMut(&Key, &Val) -> Result,
105-
) -> Relation<Result> {
101+
pub(crate) fn antijoin<P, A, O>(
102+
input1: &Relation<A>,
103+
input2: &Relation<P>,
104+
mut logic: impl FnMut(A) -> O,
105+
) -> Relation<O>
106+
where
107+
A: Copy + Split<P>,
108+
P: Ord,
109+
O: Ord,
110+
{
106111
let mut tuples2 = &input2[..];
107112

108113
let results = input1
109114
.elements
110115
.iter()
111-
.filter(|(ref key, _)| {
112-
tuples2 = gallop(tuples2, |k| k < key);
113-
tuples2.first() != Some(key)
116+
.filter(|el| {
117+
tuples2 = gallop(tuples2, |p| p < &el.prefix());
118+
tuples2.first() != Some(&el.prefix())
114119
})
115-
.map(|(ref key, ref val)| logic(key, val))
120+
.map(|&el| logic(el))
116121
.collect::<Vec<_>>();
117122

118123
Relation::from_vec(results)

src/relation.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ impl<Tuple: Ord> Relation<Tuple> {
6767
/// tuples with the `logic` closure. Like
6868
/// [`Variable::from_antijoin`] except for use where the inputs
6969
/// are not varying across iterations.
70-
pub fn from_antijoin<Key: Ord, Val1: Ord>(
71-
input1: &Relation<(Key, Val1)>,
72-
input2: &Relation<Key>,
73-
logic: impl FnMut(&Key, &Val1) -> Tuple,
74-
) -> Self {
70+
pub fn from_antijoin<P, A>(
71+
input1: &Relation<A>,
72+
input2: &Relation<P>,
73+
logic: impl FnMut(A) -> Tuple,
74+
) -> Self
75+
where
76+
P: Ord,
77+
A: Copy + Split<P>
78+
{
7579
join::antijoin(input1, input2, logic)
7680
}
7781

src/variable.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,15 @@ impl<Tuple: Ord> Variable<Tuple> {
180180
/// let result = variable.complete();
181181
/// assert_eq!(result.len(), 16);
182182
/// ```
183-
pub fn from_antijoin<K: Ord, V: Ord>(
183+
pub fn from_antijoin<P, A>(
184184
&self,
185-
input1: &Variable<(K, V)>,
186-
input2: &Relation<K>,
187-
logic: impl FnMut(&K, &V) -> Tuple,
188-
) {
185+
input1: &Variable<A>,
186+
input2: &Relation<P>,
187+
logic: impl FnMut(A) -> Tuple,
188+
) where
189+
A: Copy + Split<P>,
190+
P: Ord,
191+
{
189192
self.insert(join::antijoin(&input1.recent.borrow(), input2, logic))
190193
}
191194

0 commit comments

Comments
 (0)