Skip to main content

ValidTimeRelation

Struct ValidTimeRelation 

Source
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>

Source

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());
Source

pub fn from_facts<I>(facts: I) -> Self
where 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?
examples/capability_boundaries.rs (lines 31-40)
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
Hide additional examples
examples/valid_time.rs (lines 9-22)
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

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")));
Source

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 })
);
Source

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"));
Source

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?
examples/capability_boundaries.rs (line 66)
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
Hide additional examples
examples/valid_time.rs (line 33)
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

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?
examples/valid_time.rs (line 38)
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

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")]),
    ]
);
Source

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?
examples/valid_time.rs (line 25)
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

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?
examples/valid_time.rs (line 28)
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

pub fn restrict_to(&self, constraint: &Interval<T>) -> Self
where 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?
examples/valid_time.rs (line 29)
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>

Source

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>

Source

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?
examples/valid_time.rs (line 26)
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>

Source

pub fn to_nary_relation<I, S>( &self, schema: I, ) -> Result<NaryRelation<Value>, NaryRelationError>
where I: IntoIterator<Item = S>, S: Into<String>,

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>

Source§

fn clone(&self) -> ValidTimeRelation<F, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + Ord, T: Debug + Ord + Clone> Debug for ValidTimeRelation<F, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Ord, T: Ord + Clone> Default for ValidTimeRelation<F, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<F: Ord + Clone, T: Ord + Clone> ExactSupport<F> for ValidTimeRelation<F, T>

Source§

fn exact_support(&self) -> UnaryRelation<F>

Returns the exact support of stored facts in deterministic fact order.
Source§

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)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<F: Ord, T: Ord + Clone> FiniteRelation for ValidTimeRelation<F, T>

Source§

fn len(&self) -> usize

Returns the number of stored tuples in the relation.
Source§

fn is_empty(&self) -> bool

Returns true when the relation contains no tuples.
Source§

impl<F: Ord, T: Ord + Clone> FromIterator<(F, Interval<T>)> for ValidTimeRelation<F, T>

Source§

fn from_iter<I: IntoIterator<Item = (F, Interval<T>)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<F: PartialEq + Ord, T: PartialEq + Ord + Clone> PartialEq for ValidTimeRelation<F, T>

Source§

fn eq(&self, other: &ValidTimeRelation<F, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Eq + Ord, T: Eq + Ord + Clone> Eq for ValidTimeRelation<F, T>

Source§

impl<F: Ord, T: Ord + Clone> StructuralPartialEq for ValidTimeRelation<F, T>

Auto Trait Implementations§

§

impl<F, T> Freeze for ValidTimeRelation<F, T>

§

impl<F, T> RefUnwindSafe for ValidTimeRelation<F, T>

§

impl<F, T> Send for ValidTimeRelation<F, T>
where F: Send, T: Send,

§

impl<F, T> Sync for ValidTimeRelation<F, T>
where F: Sync, T: Sync,

§

impl<F, T> Unpin for ValidTimeRelation<F, T>

§

impl<F, T> UnsafeUnpin for ValidTimeRelation<F, T>

§

impl<F, T> UnwindSafe for ValidTimeRelation<F, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<A, B, R> ToExactBinaryRelation<A, B> for R
where A: Ord + Clone, B: Ord + Clone, R: ExactSupport<(A, B)>,

Source§

fn to_binary_relation(&self) -> BinaryRelation<A, B>

Materializes exact pair support as a binary relation.
Source§

impl<T, R> ToExactNaryRelation<T> for R
where T: Ord + Clone, R: ExactSupport<Vec<T>>,

Source§

fn to_nary_relation<I, S>( &self, schema: I, ) -> Result<NaryRelation<T>, NaryRelationError>
where I: IntoIterator<Item = S>, S: Into<String>,

Materializes exact row support as an n-ary relation with the given schema.
Source§

impl<T, R> ToExactUnaryRelation<T> for R
where T: Ord + Clone, R: ExactSupport<T>,

Source§

fn to_unary_relation(&self) -> UnaryRelation<T>

Materializes exact scalar support as a unary relation.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.