@@ -36,7 +36,7 @@ pub(crate) trait VariableTrait {
36
36
/// of performance. Such a variable cannot be relied on to terminate iterative computation,
37
37
/// and it is important that any cycle of derivations have at least one de-duplicating
38
38
/// variable on it.
39
- pub struct Variable < Tuple : Ord > {
39
+ pub struct Variable < Tuple > {
40
40
/// Should the variable be maintained distinctly.
41
41
pub ( crate ) distinct : bool ,
42
42
/// A useful name for the variable.
@@ -49,6 +49,26 @@ pub struct Variable<Tuple: Ord> {
49
49
pub ( crate ) to_add : Rc < RefCell < Vec < Relation < Tuple > > > > ,
50
50
}
51
51
52
+ impl < Tuple > Variable < Tuple > {
53
+ /// Returns the name used to create this variable.
54
+ pub fn name ( & self ) -> & str {
55
+ self . name . as_str ( )
56
+ }
57
+
58
+ /// Returns the total number of "stable" tuples in this variable.
59
+ pub fn num_stable ( & self ) -> usize {
60
+ self . stable . borrow ( ) . iter ( ) . map ( |x| x. len ( ) ) . sum ( )
61
+ }
62
+
63
+ /// Returns `true` if this variable contains only "stable" tuples.
64
+ ///
65
+ /// Calling `Iteration::changed()` on such `Variables` will not change them unless new tuples
66
+ /// are added.
67
+ pub fn is_stable ( & self ) -> bool {
68
+ self . recent . borrow ( ) . is_empty ( ) && self . to_add . borrow ( ) . is_empty ( )
69
+ }
70
+ }
71
+
52
72
// Operator implementations.
53
73
impl < Tuple : Ord > Variable < Tuple > {
54
74
/// Adds tuples that result from joining `input1` and `input2` --
@@ -251,7 +271,7 @@ impl<Tuple: Ord> Variable<Tuple> {
251
271
}
252
272
}
253
273
254
- impl < Tuple : Ord > Clone for Variable < Tuple > {
274
+ impl < Tuple > Clone for Variable < Tuple > {
255
275
fn clone ( & self ) -> Self {
256
276
Variable {
257
277
distinct : self . distinct ,
@@ -304,8 +324,7 @@ impl<Tuple: Ord> Variable<Tuple> {
304
324
/// asserts that iteration has completed, in that `self.recent` and
305
325
/// `self.to_add` should both be empty.
306
326
pub fn complete ( self ) -> Relation < Tuple > {
307
- assert ! ( self . recent. borrow( ) . is_empty( ) ) ;
308
- assert ! ( self . to_add. borrow( ) . is_empty( ) ) ;
327
+ assert ! ( self . is_stable( ) ) ;
309
328
let mut result: Relation < Tuple > = Vec :: new ( ) . into ( ) ;
310
329
while let Some ( batch) = self . stable . borrow_mut ( ) . pop ( ) {
311
330
result = result. merge ( batch) ;
0 commit comments