Skip to main content

ValidTimeSupport

Struct ValidTimeSupport 

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

Source

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

pub fn from_intervals<I>(intervals: I) -> Self
where 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")]
);
Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true when the support contains no intervals.

Source

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

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

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

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

pub fn to_vec(&self) -> Vec<Interval<T>>

Returns the canonical interval list as a vector.

Examples found in repository?
examples/valid_time.rs (line 35)
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>

Source§

fn clone(&self) -> ValidTimeSupport<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<T: Debug + Ord + Clone> Debug for ValidTimeSupport<T>

Source§

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

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

impl<T: Ord + Clone> Default for ValidTimeSupport<T>

Source§

fn default() -> Self

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

impl<T: Ord + Clone> Extend<Interval<T>> for ValidTimeSupport<T>

Source§

fn extend<I: IntoIterator<Item = 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<T: Ord + Clone> FromIterator<Interval<T>> for ValidTimeSupport<T>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: PartialEq + Ord + Clone> PartialEq for ValidTimeSupport<T>

Source§

fn eq(&self, other: &ValidTimeSupport<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<T: Eq + Ord + Clone> Eq for ValidTimeSupport<T>

Source§

impl<T: Ord + Clone> StructuralPartialEq for ValidTimeSupport<T>

Auto Trait Implementations§

§

impl<T> Freeze for ValidTimeSupport<T>

§

impl<T> RefUnwindSafe for ValidTimeSupport<T>
where T: RefUnwindSafe,

§

impl<T> Send for ValidTimeSupport<T>
where T: Send,

§

impl<T> Sync for ValidTimeSupport<T>
where T: Sync,

§

impl<T> Unpin for ValidTimeSupport<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ValidTimeSupport<T>

§

impl<T> UnwindSafe for ValidTimeSupport<T>
where T: UnwindSafe,

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