pub struct ValidTimeRelation<F: Ord, T: Ord + Clone> { /* private fields */ }Expand description
Deterministic valid-time support attached to exact facts.
ValidTimeRelation<F, T> keeps exact facts in deterministic fact order and
stores canonical valid-time support for each fact. Repeated insertion of a
fact with overlapping or directly adjacent intervals coalesces that fact’s
support. The first temporal operations on top of this surface are
Self::snapshot_at and Self::restrict_to.
In this first G5 slice, only facts with non-empty valid-time support are stored. Exact support materialization forgets time and keeps only which facts are present at all.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let assignments = ValidTimeRelation::from_facts([
(("alice", "review"), Interval::new(1, 3).expect("expected valid interval")),
(("alice", "review"), Interval::new(3, 5).expect("expected valid interval")),
(("bob", "approve"), Interval::new(2, 4).expect("expected valid interval")),
]);
assert_eq!(
assignments
.valid_time_of(&("alice", "review"))
.expect("expected support")
.to_vec(),
vec![Interval::new(1, 5).expect("expected valid interval")]
);
assert!(assignments.is_active_at(&("alice", "review"), &4));
assert!(!assignments.is_active_at(&("alice", "review"), &5));Implementations§
Source§impl<F: Ord, T: Ord + Clone> ValidTimeRelation<F, T>
impl<F: Ord, T: Ord + Clone> ValidTimeRelation<F, T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty valid-time relation.
§Examples
use relmath::{FiniteRelation, temporal::ValidTimeRelation};
let relation = ValidTimeRelation::<(&str, &str), i32>::new();
assert!(relation.is_empty());
assert!(relation.snapshot_at(&0).is_empty());Sourcepub fn from_facts<I>(facts: I) -> Selfwhere
I: IntoIterator<Item = (F, Interval<T>)>,
pub fn from_facts<I>(facts: I) -> Selfwhere
I: IntoIterator<Item = (F, Interval<T>)>,
Creates a valid-time relation from (fact, interval) entries.
Repeated facts combine by deterministic canonical coalescing of valid time support.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([
("alice", Interval::new(1, 3).expect("expected valid interval")),
("alice", Interval::new(3, 5).expect("expected valid interval")),
]);
assert_eq!(
relation
.valid_time_of(&"alice")
.expect("expected support")
.to_vec(),
vec![Interval::new(1, 5).expect("expected valid interval")]
);Examples found in repository?
22fn main() {
23 let evidence = ProvenanceRelation::from_facts([
24 (("alice", "review"), "directory"),
25 (("bob", "approve"), "policy"),
26 ]);
27 let permissions = AnnotatedRelation::from_facts([
28 (("alice", "review"), BooleanSemiring::TRUE),
29 (("bob", "approve"), BooleanSemiring::TRUE),
30 ]);
31 let schedule = ValidTimeRelation::from_facts([
32 (
33 ("alice", "review"),
34 Interval::new(1, 3).expect("expected valid interval"),
35 ),
36 (
37 ("bob", "approve"),
38 Interval::new(2, 4).expect("expected valid interval"),
39 ),
40 ]);
41
42 let exact_evidence = exact_pairs(&evidence);
43 let exact_permissions = exact_pairs(&permissions);
44 let exact_schedule = exact_pairs(&schedule);
45
46 assert_eq!(
47 exact_evidence.to_vec(),
48 vec![("alice", "review"), ("bob", "approve")]
49 );
50 assert_eq!(exact_permissions.to_vec(), exact_evidence.to_vec());
51 assert_eq!(exact_schedule.to_vec(), exact_evidence.to_vec());
52
53 assert_eq!(
54 evidence
55 .why(&("alice", "review"))
56 .expect("expected witness")
57 .to_vec(),
58 vec!["directory"]
59 );
60 assert_eq!(
61 permissions.annotation_of(&("alice", "review")),
62 Some(&BooleanSemiring::TRUE)
63 );
64 assert_eq!(
65 schedule
66 .valid_time_of(&("alice", "review"))
67 .expect("expected interval support")
68 .to_vec(),
69 vec![Interval::new(1, 3).expect("expected valid interval")]
70 );
71
72 println!(
73 "witness={:?}, annotation={:?}, interval_support={:?}, exact_support={:?}",
74 evidence
75 .why(&("alice", "review"))
76 .expect("expected witness")
77 .to_vec(),
78 permissions.annotation_of(&("alice", "review")),
79 schedule
80 .valid_time_of(&("alice", "review"))
81 .expect("expected interval support")
82 .to_vec(),
83 exact_schedule.to_vec()
84 );
85}More examples
8fn main() {
9 let assignments = ValidTimeRelation::from_facts([
10 (
11 ("alice", "review"),
12 Interval::new(1, 3).expect("expected valid interval"),
13 ),
14 (
15 ("alice", "review"),
16 Interval::new(3, 5).expect("expected valid interval"),
17 ),
18 (
19 ("bob", "approve"),
20 Interval::new(2, 4).expect("expected valid interval"),
21 ),
22 ]);
23
24 let alice = UnaryRelation::singleton("alice");
25 let fact_support = assignments.support();
26 let exact_support = assignments.to_binary_relation();
27 let audit_window = Interval::new(2, 4).expect("expected valid interval");
28 let active_at_three = assignments.snapshot_at(&3);
29 let audit_assignments = assignments.restrict_to(&audit_window);
30
31 assert_eq!(
32 assignments
33 .valid_time_of(&("alice", "review"))
34 .expect("expected support")
35 .to_vec(),
36 vec![Interval::new(1, 5).expect("expected valid interval")]
37 );
38 assert!(assignments.is_active_at(&("alice", "review"), &4));
39 assert!(!assignments.is_active_at(&("alice", "review"), &5));
40 assert_eq!(
41 active_at_three.to_vec(),
42 vec![("alice", "review"), ("bob", "approve")]
43 );
44 assert_eq!(
45 fact_support.to_vec(),
46 vec![("alice", "review"), ("bob", "approve")]
47 );
48 assert_eq!(
49 audit_assignments
50 .valid_time_of(&("alice", "review"))
51 .expect("expected support")
52 .to_vec(),
53 vec![Interval::new(2, 4).expect("expected valid interval")]
54 );
55 assert_eq!(
56 audit_assignments.to_binary_relation().to_vec(),
57 vec![("alice", "review"), ("bob", "approve")]
58 );
59 assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);
60
61 println!(
62 "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
63 fact_support.to_vec(),
64 active_at_three.to_vec(),
65 audit_assignments
66 .valid_time_of(&("alice", "review"))
67 .expect("expected support")
68 .to_vec()
69 );
70}Sourcepub fn insert(&mut self, fact: F, interval: Interval<T>) -> bool
pub fn insert(&mut self, fact: F, interval: Interval<T>) -> bool
Inserts one valid interval for a fact.
Returns true when the fact’s stored valid-time support changes.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let mut relation = ValidTimeRelation::new();
assert!(relation.insert("alice", Interval::new(1, 3).expect("expected valid interval")));
assert!(!relation.insert("alice", Interval::new(2, 3).expect("already covered")));Sourcepub fn insert_bounds(
&mut self,
fact: F,
start: T,
end: T,
) -> Result<bool, IntervalError<T>>
pub fn insert_bounds( &mut self, fact: F, start: T, end: T, ) -> Result<bool, IntervalError<T>>
Inserts one interval for a fact from raw bounds.
Returns an explicit error when start >= end.
§Examples
use relmath::temporal::{IntervalError, ValidTimeRelation};
let mut relation = ValidTimeRelation::new();
assert!(relation.insert_bounds("alice", 1, 3).expect("expected valid bounds"));
assert_eq!(
relation.insert_bounds("alice", 3, 3),
Err(IntervalError::InvalidBounds { start: 3, end: 3 })
);Sourcepub fn contains_fact(&self, fact: &F) -> bool
pub fn contains_fact(&self, fact: &F) -> bool
Returns true when the relation contains the given fact with non-empty
valid-time support.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([(
"alice",
Interval::new(1, 3).expect("expected valid interval"),
)]);
assert!(relation.contains_fact(&"alice"));
assert!(!relation.contains_fact(&"bob"));Sourcepub fn valid_time_of(&self, fact: &F) -> Option<&ValidTimeSupport<T>>
pub fn valid_time_of(&self, fact: &F) -> Option<&ValidTimeSupport<T>>
Returns the canonical valid-time support for one fact.
When a fact is absent, this returns None. In this first G5 slice, the
relation does not store empty support as a sentinel value, so None
also means the fact has no stored valid-time support.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([(
"alice",
Interval::new(1, 3).expect("expected valid interval"),
)]);
assert_eq!(
relation.valid_time_of(&"alice").expect("expected support").to_vec(),
vec![Interval::new(1, 3).expect("expected valid interval")]
);
assert!(relation.valid_time_of(&"bob").is_none());Examples found in repository?
22fn main() {
23 let evidence = ProvenanceRelation::from_facts([
24 (("alice", "review"), "directory"),
25 (("bob", "approve"), "policy"),
26 ]);
27 let permissions = AnnotatedRelation::from_facts([
28 (("alice", "review"), BooleanSemiring::TRUE),
29 (("bob", "approve"), BooleanSemiring::TRUE),
30 ]);
31 let schedule = ValidTimeRelation::from_facts([
32 (
33 ("alice", "review"),
34 Interval::new(1, 3).expect("expected valid interval"),
35 ),
36 (
37 ("bob", "approve"),
38 Interval::new(2, 4).expect("expected valid interval"),
39 ),
40 ]);
41
42 let exact_evidence = exact_pairs(&evidence);
43 let exact_permissions = exact_pairs(&permissions);
44 let exact_schedule = exact_pairs(&schedule);
45
46 assert_eq!(
47 exact_evidence.to_vec(),
48 vec![("alice", "review"), ("bob", "approve")]
49 );
50 assert_eq!(exact_permissions.to_vec(), exact_evidence.to_vec());
51 assert_eq!(exact_schedule.to_vec(), exact_evidence.to_vec());
52
53 assert_eq!(
54 evidence
55 .why(&("alice", "review"))
56 .expect("expected witness")
57 .to_vec(),
58 vec!["directory"]
59 );
60 assert_eq!(
61 permissions.annotation_of(&("alice", "review")),
62 Some(&BooleanSemiring::TRUE)
63 );
64 assert_eq!(
65 schedule
66 .valid_time_of(&("alice", "review"))
67 .expect("expected interval support")
68 .to_vec(),
69 vec![Interval::new(1, 3).expect("expected valid interval")]
70 );
71
72 println!(
73 "witness={:?}, annotation={:?}, interval_support={:?}, exact_support={:?}",
74 evidence
75 .why(&("alice", "review"))
76 .expect("expected witness")
77 .to_vec(),
78 permissions.annotation_of(&("alice", "review")),
79 schedule
80 .valid_time_of(&("alice", "review"))
81 .expect("expected interval support")
82 .to_vec(),
83 exact_schedule.to_vec()
84 );
85}More examples
8fn main() {
9 let assignments = ValidTimeRelation::from_facts([
10 (
11 ("alice", "review"),
12 Interval::new(1, 3).expect("expected valid interval"),
13 ),
14 (
15 ("alice", "review"),
16 Interval::new(3, 5).expect("expected valid interval"),
17 ),
18 (
19 ("bob", "approve"),
20 Interval::new(2, 4).expect("expected valid interval"),
21 ),
22 ]);
23
24 let alice = UnaryRelation::singleton("alice");
25 let fact_support = assignments.support();
26 let exact_support = assignments.to_binary_relation();
27 let audit_window = Interval::new(2, 4).expect("expected valid interval");
28 let active_at_three = assignments.snapshot_at(&3);
29 let audit_assignments = assignments.restrict_to(&audit_window);
30
31 assert_eq!(
32 assignments
33 .valid_time_of(&("alice", "review"))
34 .expect("expected support")
35 .to_vec(),
36 vec![Interval::new(1, 5).expect("expected valid interval")]
37 );
38 assert!(assignments.is_active_at(&("alice", "review"), &4));
39 assert!(!assignments.is_active_at(&("alice", "review"), &5));
40 assert_eq!(
41 active_at_three.to_vec(),
42 vec![("alice", "review"), ("bob", "approve")]
43 );
44 assert_eq!(
45 fact_support.to_vec(),
46 vec![("alice", "review"), ("bob", "approve")]
47 );
48 assert_eq!(
49 audit_assignments
50 .valid_time_of(&("alice", "review"))
51 .expect("expected support")
52 .to_vec(),
53 vec![Interval::new(2, 4).expect("expected valid interval")]
54 );
55 assert_eq!(
56 audit_assignments.to_binary_relation().to_vec(),
57 vec![("alice", "review"), ("bob", "approve")]
58 );
59 assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);
60
61 println!(
62 "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
63 fact_support.to_vec(),
64 active_at_three.to_vec(),
65 audit_assignments
66 .valid_time_of(&("alice", "review"))
67 .expect("expected support")
68 .to_vec()
69 );
70}Sourcepub fn is_active_at(&self, fact: &F, point: &T) -> bool
pub fn is_active_at(&self, fact: &F, point: &T) -> bool
Returns true when fact is active at point.
Absent facts are never active.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([(
"alice",
Interval::new(1, 3).expect("expected valid interval"),
)]);
assert!(relation.is_active_at(&"alice", &1));
assert!(!relation.is_active_at(&"alice", &3));
assert!(!relation.is_active_at(&"bob", &1));Examples found in repository?
8fn main() {
9 let assignments = ValidTimeRelation::from_facts([
10 (
11 ("alice", "review"),
12 Interval::new(1, 3).expect("expected valid interval"),
13 ),
14 (
15 ("alice", "review"),
16 Interval::new(3, 5).expect("expected valid interval"),
17 ),
18 (
19 ("bob", "approve"),
20 Interval::new(2, 4).expect("expected valid interval"),
21 ),
22 ]);
23
24 let alice = UnaryRelation::singleton("alice");
25 let fact_support = assignments.support();
26 let exact_support = assignments.to_binary_relation();
27 let audit_window = Interval::new(2, 4).expect("expected valid interval");
28 let active_at_three = assignments.snapshot_at(&3);
29 let audit_assignments = assignments.restrict_to(&audit_window);
30
31 assert_eq!(
32 assignments
33 .valid_time_of(&("alice", "review"))
34 .expect("expected support")
35 .to_vec(),
36 vec![Interval::new(1, 5).expect("expected valid interval")]
37 );
38 assert!(assignments.is_active_at(&("alice", "review"), &4));
39 assert!(!assignments.is_active_at(&("alice", "review"), &5));
40 assert_eq!(
41 active_at_three.to_vec(),
42 vec![("alice", "review"), ("bob", "approve")]
43 );
44 assert_eq!(
45 fact_support.to_vec(),
46 vec![("alice", "review"), ("bob", "approve")]
47 );
48 assert_eq!(
49 audit_assignments
50 .valid_time_of(&("alice", "review"))
51 .expect("expected support")
52 .to_vec(),
53 vec![Interval::new(2, 4).expect("expected valid interval")]
54 );
55 assert_eq!(
56 audit_assignments.to_binary_relation().to_vec(),
57 vec![("alice", "review"), ("bob", "approve")]
58 );
59 assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);
60
61 println!(
62 "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
63 fact_support.to_vec(),
64 active_at_three.to_vec(),
65 audit_assignments
66 .valid_time_of(&("alice", "review"))
67 .expect("expected support")
68 .to_vec()
69 );
70}Sourcepub fn iter(&self) -> impl Iterator<Item = (&F, &ValidTimeSupport<T>)>
pub fn iter(&self) -> impl Iterator<Item = (&F, &ValidTimeSupport<T>)>
Returns an iterator over facts and valid-time support in deterministic fact order.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([
("bob", Interval::new(2, 4).expect("expected valid interval")),
("alice", Interval::new(1, 3).expect("expected valid interval")),
]);
assert_eq!(
relation
.iter()
.map(|(fact, support)| (*fact, support.to_vec()))
.collect::<Vec<_>>(),
vec![
("alice", vec![Interval::new(1, 3).expect("expected valid interval")]),
("bob", vec![Interval::new(2, 4).expect("expected valid interval")]),
]
);Sourcepub fn support(&self) -> UnaryRelation<F>where
F: Clone,
pub fn support(&self) -> UnaryRelation<F>where
F: Clone,
Returns the exact support relation of stored facts as a unary relation.
This materialization forgets time and keeps only which facts have
non-empty valid-time support. Generic code can access the same
relation-level boundary through crate::ExactSupport::exact_support.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([
("Closure", Interval::new(1, 4).expect("expected valid interval")),
("Relations", Interval::new(2, 5).expect("expected valid interval")),
]);
assert_eq!(relation.support().to_vec(), vec!["Closure", "Relations"]);Examples found in repository?
8fn main() {
9 let assignments = ValidTimeRelation::from_facts([
10 (
11 ("alice", "review"),
12 Interval::new(1, 3).expect("expected valid interval"),
13 ),
14 (
15 ("alice", "review"),
16 Interval::new(3, 5).expect("expected valid interval"),
17 ),
18 (
19 ("bob", "approve"),
20 Interval::new(2, 4).expect("expected valid interval"),
21 ),
22 ]);
23
24 let alice = UnaryRelation::singleton("alice");
25 let fact_support = assignments.support();
26 let exact_support = assignments.to_binary_relation();
27 let audit_window = Interval::new(2, 4).expect("expected valid interval");
28 let active_at_three = assignments.snapshot_at(&3);
29 let audit_assignments = assignments.restrict_to(&audit_window);
30
31 assert_eq!(
32 assignments
33 .valid_time_of(&("alice", "review"))
34 .expect("expected support")
35 .to_vec(),
36 vec![Interval::new(1, 5).expect("expected valid interval")]
37 );
38 assert!(assignments.is_active_at(&("alice", "review"), &4));
39 assert!(!assignments.is_active_at(&("alice", "review"), &5));
40 assert_eq!(
41 active_at_three.to_vec(),
42 vec![("alice", "review"), ("bob", "approve")]
43 );
44 assert_eq!(
45 fact_support.to_vec(),
46 vec![("alice", "review"), ("bob", "approve")]
47 );
48 assert_eq!(
49 audit_assignments
50 .valid_time_of(&("alice", "review"))
51 .expect("expected support")
52 .to_vec(),
53 vec![Interval::new(2, 4).expect("expected valid interval")]
54 );
55 assert_eq!(
56 audit_assignments.to_binary_relation().to_vec(),
57 vec![("alice", "review"), ("bob", "approve")]
58 );
59 assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);
60
61 println!(
62 "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
63 fact_support.to_vec(),
64 active_at_three.to_vec(),
65 audit_assignments
66 .valid_time_of(&("alice", "review"))
67 .expect("expected support")
68 .to_vec()
69 );
70}Sourcepub fn snapshot_at(&self, point: &T) -> UnaryRelation<F>where
F: Clone,
pub fn snapshot_at(&self, point: &T) -> UnaryRelation<F>where
F: Clone,
Returns the exact snapshot of facts active at point.
The result is a unary relation over stored facts. Facts are present in
the snapshot exactly when their valid-time support contains point.
When no facts are active, this returns an empty unary relation.
§Examples
use relmath::{FiniteRelation, temporal::{Interval, ValidTimeRelation}};
let assignments = ValidTimeRelation::from_facts([
(("alice", "review"), Interval::new(1, 3).expect("expected valid interval")),
(("alice", "review"), Interval::new(3, 5).expect("expected valid interval")),
(("bob", "approve"), Interval::new(2, 4).expect("expected valid interval")),
]);
assert_eq!(
assignments.snapshot_at(&3).to_vec(),
vec![("alice", "review"), ("bob", "approve")]
);
assert!(assignments.snapshot_at(&5).is_empty());Examples found in repository?
8fn main() {
9 let assignments = ValidTimeRelation::from_facts([
10 (
11 ("alice", "review"),
12 Interval::new(1, 3).expect("expected valid interval"),
13 ),
14 (
15 ("alice", "review"),
16 Interval::new(3, 5).expect("expected valid interval"),
17 ),
18 (
19 ("bob", "approve"),
20 Interval::new(2, 4).expect("expected valid interval"),
21 ),
22 ]);
23
24 let alice = UnaryRelation::singleton("alice");
25 let fact_support = assignments.support();
26 let exact_support = assignments.to_binary_relation();
27 let audit_window = Interval::new(2, 4).expect("expected valid interval");
28 let active_at_three = assignments.snapshot_at(&3);
29 let audit_assignments = assignments.restrict_to(&audit_window);
30
31 assert_eq!(
32 assignments
33 .valid_time_of(&("alice", "review"))
34 .expect("expected support")
35 .to_vec(),
36 vec![Interval::new(1, 5).expect("expected valid interval")]
37 );
38 assert!(assignments.is_active_at(&("alice", "review"), &4));
39 assert!(!assignments.is_active_at(&("alice", "review"), &5));
40 assert_eq!(
41 active_at_three.to_vec(),
42 vec![("alice", "review"), ("bob", "approve")]
43 );
44 assert_eq!(
45 fact_support.to_vec(),
46 vec![("alice", "review"), ("bob", "approve")]
47 );
48 assert_eq!(
49 audit_assignments
50 .valid_time_of(&("alice", "review"))
51 .expect("expected support")
52 .to_vec(),
53 vec![Interval::new(2, 4).expect("expected valid interval")]
54 );
55 assert_eq!(
56 audit_assignments.to_binary_relation().to_vec(),
57 vec![("alice", "review"), ("bob", "approve")]
58 );
59 assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);
60
61 println!(
62 "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
63 fact_support.to_vec(),
64 active_at_three.to_vec(),
65 audit_assignments
66 .valid_time_of(&("alice", "review"))
67 .expect("expected support")
68 .to_vec()
69 );
70}Sourcepub fn restrict_to(&self, constraint: &Interval<T>) -> Selfwhere
F: Clone,
pub fn restrict_to(&self, constraint: &Interval<T>) -> Selfwhere
F: Clone,
Restricts every fact’s valid-time support to constraint.
Facts whose support has no overlap with constraint are omitted from
the returned relation. Remaining support fragments stay in deterministic
fact order and canonical interval order.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let assignments = ValidTimeRelation::from_facts([
(("alice", "review"), Interval::new(1, 3).expect("expected valid interval")),
(("alice", "review"), Interval::new(5, 7).expect("expected valid interval")),
(("bob", "approve"), Interval::new(2, 4).expect("expected valid interval")),
(("carol", "audit"), Interval::new(7, 9).expect("expected valid interval")),
]);
let audit_window = Interval::new(2, 6).expect("expected valid interval");
let restricted = assignments.restrict_to(&audit_window);
assert_eq!(
restricted
.valid_time_of(&("alice", "review"))
.expect("expected support")
.to_vec(),
vec![
Interval::new(2, 3).expect("expected valid interval"),
Interval::new(5, 6).expect("expected valid interval"),
]
);
assert!(!restricted.contains_fact(&("carol", "audit")));Examples found in repository?
8fn main() {
9 let assignments = ValidTimeRelation::from_facts([
10 (
11 ("alice", "review"),
12 Interval::new(1, 3).expect("expected valid interval"),
13 ),
14 (
15 ("alice", "review"),
16 Interval::new(3, 5).expect("expected valid interval"),
17 ),
18 (
19 ("bob", "approve"),
20 Interval::new(2, 4).expect("expected valid interval"),
21 ),
22 ]);
23
24 let alice = UnaryRelation::singleton("alice");
25 let fact_support = assignments.support();
26 let exact_support = assignments.to_binary_relation();
27 let audit_window = Interval::new(2, 4).expect("expected valid interval");
28 let active_at_three = assignments.snapshot_at(&3);
29 let audit_assignments = assignments.restrict_to(&audit_window);
30
31 assert_eq!(
32 assignments
33 .valid_time_of(&("alice", "review"))
34 .expect("expected support")
35 .to_vec(),
36 vec![Interval::new(1, 5).expect("expected valid interval")]
37 );
38 assert!(assignments.is_active_at(&("alice", "review"), &4));
39 assert!(!assignments.is_active_at(&("alice", "review"), &5));
40 assert_eq!(
41 active_at_three.to_vec(),
42 vec![("alice", "review"), ("bob", "approve")]
43 );
44 assert_eq!(
45 fact_support.to_vec(),
46 vec![("alice", "review"), ("bob", "approve")]
47 );
48 assert_eq!(
49 audit_assignments
50 .valid_time_of(&("alice", "review"))
51 .expect("expected support")
52 .to_vec(),
53 vec![Interval::new(2, 4).expect("expected valid interval")]
54 );
55 assert_eq!(
56 audit_assignments.to_binary_relation().to_vec(),
57 vec![("alice", "review"), ("bob", "approve")]
58 );
59 assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);
60
61 println!(
62 "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
63 fact_support.to_vec(),
64 active_at_three.to_vec(),
65 audit_assignments
66 .valid_time_of(&("alice", "review"))
67 .expect("expected support")
68 .to_vec()
69 );
70}Source§impl<Value: Ord + Clone, Time: Ord + Clone> ValidTimeRelation<Value, Time>
impl<Value: Ord + Clone, Time: Ord + Clone> ValidTimeRelation<Value, Time>
Sourcepub fn to_unary_relation(&self) -> UnaryRelation<Value>
pub fn to_unary_relation(&self) -> UnaryRelation<Value>
Converts scalar facts into a unary relation support set.
Generic code can access the same unary materialization boundary through
crate::ToExactUnaryRelation.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([(
"Closure",
Interval::new(1, 4).expect("expected valid interval"),
)]);
assert_eq!(relation.to_unary_relation().to_vec(), vec!["Closure"]);Source§impl<A: Ord + Clone, B: Ord + Clone, Time: Ord + Clone> ValidTimeRelation<(A, B), Time>
impl<A: Ord + Clone, B: Ord + Clone, Time: Ord + Clone> ValidTimeRelation<(A, B), Time>
Sourcepub fn to_binary_relation(&self) -> BinaryRelation<A, B>
pub fn to_binary_relation(&self) -> BinaryRelation<A, B>
Converts pair facts into a binary relation support set.
Generic code can access the same binary materialization boundary
through crate::ToExactBinaryRelation.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let relation = ValidTimeRelation::from_facts([(
("alice", "review"),
Interval::new(1, 3).expect("expected valid interval"),
)]);
assert_eq!(relation.to_binary_relation().to_vec(), vec![("alice", "review")]);Examples found in repository?
8fn main() {
9 let assignments = ValidTimeRelation::from_facts([
10 (
11 ("alice", "review"),
12 Interval::new(1, 3).expect("expected valid interval"),
13 ),
14 (
15 ("alice", "review"),
16 Interval::new(3, 5).expect("expected valid interval"),
17 ),
18 (
19 ("bob", "approve"),
20 Interval::new(2, 4).expect("expected valid interval"),
21 ),
22 ]);
23
24 let alice = UnaryRelation::singleton("alice");
25 let fact_support = assignments.support();
26 let exact_support = assignments.to_binary_relation();
27 let audit_window = Interval::new(2, 4).expect("expected valid interval");
28 let active_at_three = assignments.snapshot_at(&3);
29 let audit_assignments = assignments.restrict_to(&audit_window);
30
31 assert_eq!(
32 assignments
33 .valid_time_of(&("alice", "review"))
34 .expect("expected support")
35 .to_vec(),
36 vec![Interval::new(1, 5).expect("expected valid interval")]
37 );
38 assert!(assignments.is_active_at(&("alice", "review"), &4));
39 assert!(!assignments.is_active_at(&("alice", "review"), &5));
40 assert_eq!(
41 active_at_three.to_vec(),
42 vec![("alice", "review"), ("bob", "approve")]
43 );
44 assert_eq!(
45 fact_support.to_vec(),
46 vec![("alice", "review"), ("bob", "approve")]
47 );
48 assert_eq!(
49 audit_assignments
50 .valid_time_of(&("alice", "review"))
51 .expect("expected support")
52 .to_vec(),
53 vec![Interval::new(2, 4).expect("expected valid interval")]
54 );
55 assert_eq!(
56 audit_assignments.to_binary_relation().to_vec(),
57 vec![("alice", "review"), ("bob", "approve")]
58 );
59 assert_eq!(exact_support.image(&alice).to_vec(), vec!["review"]);
60
61 println!(
62 "fact support: {:?}; active at t=3: {:?}; audit restriction: {:?}",
63 fact_support.to_vec(),
64 active_at_three.to_vec(),
65 audit_assignments
66 .valid_time_of(&("alice", "review"))
67 .expect("expected support")
68 .to_vec()
69 );
70}Source§impl<Value: Ord + Clone, Time: Ord + Clone> ValidTimeRelation<Vec<Value>, Time>
impl<Value: Ord + Clone, Time: Ord + Clone> ValidTimeRelation<Vec<Value>, Time>
Sourcepub fn to_nary_relation<I, S>(
&self,
schema: I,
) -> Result<NaryRelation<Value>, NaryRelationError>
pub fn to_nary_relation<I, S>( &self, schema: I, ) -> Result<NaryRelation<Value>, NaryRelationError>
Converts row facts into an n-ary relation with the given schema.
This method reuses the current NaryRelation validation rules, so
duplicate or blank column names and row-arity mismatches return
NaryRelationError. Generic code can access the same n-ary
materialization boundary through crate::ToExactNaryRelation.
§Examples
use relmath::temporal::{Interval, ValidTimeRelation};
let rows = ValidTimeRelation::from_facts([(
vec!["Alice", "Math", "passed"],
Interval::new(1, 3).expect("expected valid interval"),
)]);
let relation = rows
.to_nary_relation(["student", "course", "status"])
.expect("expected valid n-ary relation");
assert_eq!(relation.to_rows(), vec![vec!["Alice", "Math", "passed"]]);Trait Implementations§
Source§impl<F: Clone + Ord, T: Clone + Ord + Clone> Clone for ValidTimeRelation<F, T>
impl<F: Clone + Ord, T: Clone + Ord + Clone> Clone for ValidTimeRelation<F, T>
Source§fn clone(&self) -> ValidTimeRelation<F, T>
fn clone(&self) -> ValidTimeRelation<F, T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Ord + Clone, T: Ord + Clone> ExactSupport<F> for ValidTimeRelation<F, T>
impl<F: Ord + Clone, T: Ord + Clone> ExactSupport<F> for ValidTimeRelation<F, T>
Source§fn exact_support(&self) -> UnaryRelation<F>
fn exact_support(&self) -> UnaryRelation<F>
Source§impl<F: Ord, T: Ord + Clone> Extend<(F, Interval<T>)> for ValidTimeRelation<F, T>
impl<F: Ord, T: Ord + Clone> Extend<(F, Interval<T>)> for ValidTimeRelation<F, T>
Source§fn extend<I: IntoIterator<Item = (F, Interval<T>)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (F, Interval<T>)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)