@@ -17,13 +17,18 @@ use std::rc::Rc;
17
17
18
18
mod join;
19
19
mod map;
20
- pub mod treefrog;
20
+ mod treefrog;
21
+ pub use treefrog:: {
22
+ extend_anti:: ExtendAnti , extend_with:: ExtendWith , filter_anti:: FilterAnti ,
23
+ filter_with:: FilterWith , Leaper , RelationLeaper ,
24
+ } ;
21
25
22
26
/// A static, ordered list of key-value pairs.
23
27
///
24
28
/// A relation represents a fixed set of key-value pairs. In many places in a
25
29
/// Datalog computation we want to be sure that certain relations are not able
26
30
/// to vary (for example, in antijoins).
31
+ #[ derive( Clone ) ]
27
32
pub struct Relation < Tuple : Ord > {
28
33
/// Sorted list of distinct tuples.
29
34
pub elements : Vec < Tuple > ,
@@ -114,7 +119,7 @@ impl<Tuple: Ord> std::ops::Deref for Relation<Tuple> {
114
119
/// It can inform the user if they have ceased changing, at which point the
115
120
/// computation should be done.
116
121
pub struct Iteration {
117
- variables : Vec < Box < VariableTrait > > ,
122
+ variables : Vec < Box < dyn VariableTrait > > ,
118
123
}
119
124
120
125
impl Iteration {
@@ -222,6 +227,7 @@ impl<Tuple: Ord> Variable<Tuple> {
222
227
) {
223
228
join:: join_into ( input1, input2, self , logic)
224
229
}
230
+
225
231
/// Adds tuples from `input1` whose key is not present in `input2`.
226
232
///
227
233
/// # Examples
@@ -254,6 +260,7 @@ impl<Tuple: Ord> Variable<Tuple> {
254
260
) {
255
261
join:: antijoin_into ( input1, input2, self , logic)
256
262
}
263
+
257
264
/// Adds tuples that result from mapping `input`.
258
265
///
259
266
/// # Examples
@@ -286,6 +293,21 @@ impl<Tuple: Ord> Variable<Tuple> {
286
293
pub fn from_map < T2 : Ord > ( & self , input : & Variable < T2 > , logic : impl FnMut ( & T2 ) -> Tuple ) {
287
294
map:: map_into ( input, self , logic)
288
295
}
296
+
297
+ /// Adds tuples that result from combining `source` with the
298
+ /// relations given in `leapers`. This operation is very flexible
299
+ /// and can be used to do a combination of joins and anti-joins.
300
+ /// The main limitation is that the things being combined must
301
+ /// consist of one dynamic variable (`source`) and then several
302
+ /// fixed relations (`leapers`).
303
+ pub fn from_leapjoin < ' a , SourceTuple : Ord , Val : Ord + ' a > (
304
+ & self ,
305
+ source : & Variable < SourceTuple > ,
306
+ leapers : & mut [ & mut dyn Leaper < ' a , SourceTuple , Val > ] ,
307
+ logic : impl FnMut ( & SourceTuple , & Val ) -> Tuple ,
308
+ ) {
309
+ treefrog:: leapjoin_into ( source, leapers, self , logic)
310
+ }
289
311
}
290
312
291
313
impl < Tuple : Ord > Clone for Variable < Tuple > {
0 commit comments