pub struct ValidTimeSupport<T: Ord + Clone> { /* private fields */ }Expand description
Deterministic canonical valid-time support for one fact.
ValidTimeSupport<T> stores half-open intervals in canonical
lexicographic order. Overlapping or directly adjacent intervals are
coalesced, so user-visible support never contains redundant fragments.
Support can then be queried for overlap with one interval or restricted to
one interval window without losing deterministic canonical order.
This is the interval support attached to one stored fact. It is distinct from the exact support of a relation, which forgets time and keeps only which facts are present.
§Examples
use relmath::temporal::{Interval, ValidTimeSupport};
let support = ValidTimeSupport::from_intervals([
Interval::new(3, 5).expect("expected valid interval"),
Interval::new(1, 3).expect("expected valid interval"),
Interval::new(6, 7).expect("expected valid interval"),
Interval::new(4, 6).expect("expected valid interval"),
]);
assert_eq!(
support.to_vec(),
vec![Interval::new(1, 7).expect("expected valid interval")]
);
assert!(support.contains(&4));
assert!(!support.contains(&7));Implementations§
Source§impl<T: Ord + Clone> ValidTimeSupport<T>
impl<T: Ord + Clone> ValidTimeSupport<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates empty valid-time support.
A ValidTimeRelation does not store empty support for a fact, so
absent facts return None rather than an empty support value. This
constructor is still useful for standalone inspection and testing.
§Examples
use relmath::temporal::ValidTimeSupport;
let empty = ValidTimeSupport::<i32>::new();
assert!(empty.is_empty());
assert_eq!(empty.len(), 0);Sourcepub fn from_intervals<I>(intervals: I) -> Selfwhere
I: IntoIterator<Item = Interval<T>>,
pub fn from_intervals<I>(intervals: I) -> Selfwhere
I: IntoIterator<Item = Interval<T>>,
Creates canonical valid-time support from intervals.
The resulting support is sorted and coalesced deterministically.
§Examples
use relmath::temporal::{Interval, ValidTimeSupport};
let support = ValidTimeSupport::from_intervals([
Interval::new(2, 4).expect("expected valid interval"),
Interval::new(1, 2).expect("expected valid interval"),
]);
assert_eq!(
support.to_vec(),
vec![Interval::new(1, 4).expect("expected valid interval")]
);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of canonical support intervals.
For one stored fact, this counts canonical support fragments rather than time points or inserted raw intervals.
Sourcepub fn contains(&self, point: &T) -> bool
pub fn contains(&self, point: &T) -> bool
Returns true when point is covered by some support interval.
§Examples
use relmath::temporal::{Interval, ValidTimeSupport};
let support =
ValidTimeSupport::from_intervals([Interval::new(2, 4).expect("expected valid interval")]);
assert!(support.contains(&2));
assert!(support.contains(&3));
assert!(!support.contains(&4));Sourcepub fn overlaps(&self, constraint: &Interval<T>) -> bool
pub fn overlaps(&self, constraint: &Interval<T>) -> bool
Returns true when some support interval overlaps constraint.
Direct boundary-only contact does not count as overlap under half-open semantics.
§Examples
use relmath::temporal::{Interval, ValidTimeSupport};
let support = ValidTimeSupport::from_intervals([
Interval::new(1, 3).expect("expected valid interval"),
Interval::new(5, 7).expect("expected valid interval"),
]);
assert!(support.overlaps(&Interval::new(2, 6).expect("expected valid interval")));
assert!(!support.overlaps(&Interval::new(3, 5).expect("expected valid interval")));Sourcepub fn restrict_to(&self, constraint: &Interval<T>) -> Self
pub fn restrict_to(&self, constraint: &Interval<T>) -> Self
Restricts this support to the overlap with constraint.
The returned support remains canonical: overlapping or directly adjacent fragments are coalesced deterministically. When no interval overlaps the constraint, this returns empty support.
§Examples
use relmath::temporal::{Interval, ValidTimeSupport};
let support = ValidTimeSupport::from_intervals([
Interval::new(1, 3).expect("expected valid interval"),
Interval::new(5, 7).expect("expected valid interval"),
]);
assert_eq!(
support
.restrict_to(&Interval::new(2, 6).expect("expected valid interval"))
.to_vec(),
vec![
Interval::new(2, 3).expect("expected valid interval"),
Interval::new(5, 6).expect("expected valid interval"),
]
);
assert!(
support
.restrict_to(&Interval::new(3, 5).expect("expected valid interval"))
.is_empty()
);Sourcepub fn iter(&self) -> impl Iterator<Item = &Interval<T>>
pub fn iter(&self) -> impl Iterator<Item = &Interval<T>>
Returns an iterator over canonical support intervals.
§Examples
use relmath::temporal::{Interval, ValidTimeSupport};
let support = ValidTimeSupport::from_intervals([
Interval::new(4, 6).expect("expected valid interval"),
Interval::new(1, 3).expect("expected valid interval"),
]);
assert_eq!(
support.iter().cloned().collect::<Vec<_>>(),
vec![
Interval::new(1, 3).expect("expected valid interval"),
Interval::new(4, 6).expect("expected valid interval"),
]
);Sourcepub fn to_vec(&self) -> Vec<Interval<T>>
pub fn to_vec(&self) -> Vec<Interval<T>>
Returns the canonical interval list as a vector.
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}Trait Implementations§
Source§impl<T: Clone + Ord + Clone> Clone for ValidTimeSupport<T>
impl<T: Clone + Ord + Clone> Clone for ValidTimeSupport<T>
Source§fn clone(&self) -> ValidTimeSupport<T>
fn clone(&self) -> ValidTimeSupport<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Ord + Clone> Extend<Interval<T>> for ValidTimeSupport<T>
impl<T: Ord + Clone> Extend<Interval<T>> for ValidTimeSupport<T>
Source§fn extend<I: IntoIterator<Item = Interval<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = 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)