Skip to main content

FiniteCarrier

Struct FiniteCarrier 

Source
pub struct FiniteCarrier<T: Ord> { /* private fields */ }
Expand description

Deterministic explicit finite carrier distinct from inferred tuple support. A deterministic explicit finite carrier.

FiniteCarrier<T> is the first executable G7 carrier boundary. It records admissible values explicitly, even when some values are disconnected from the support of stored tuples. This keeps an explicit carrier semantically distinct from exact support inferred from relations such as crate::BinaryRelation::carrier. Empty and singleton carriers are ordinary first-class values rather than special cases hidden behind relation support.

The starter implementation stores carrier members in a BTreeSet, so membership and iteration are deterministic.

§Examples

use relmath::{BinaryRelation, FiniteCarrier};

let states = FiniteCarrier::from_values(["Draft", "Review", "Archived"]);
let step = BinaryRelation::from_pairs([("Draft", "Review")]);

assert!(states.contains(&"Archived"));
assert_eq!(states.to_vec(), vec!["Archived", "Draft", "Review"]);
assert_eq!(step.carrier().to_vec(), vec!["Draft", "Review"]);

Implementations§

Source§

impl<T: Ord> FiniteCarrier<T>

Source

pub fn new() -> Self

Creates an empty explicit finite carrier.

Source

pub fn from_values<I>(values: I) -> Self
where I: IntoIterator<Item = T>,

Creates an explicit finite carrier from the provided values.

Duplicate values are coalesced into one stored member.

Examples found in repository?
examples/carrier.rs (line 7)
5fn main() {
6    let step = BinaryRelation::from_pairs([("Draft", "Review")]);
7    let states = FiniteCarrier::from_values(["Draft", "Review", "Archived"]);
8
9    let inferred = step.carrier();
10    let inferred_identity = BinaryRelation::identity(&inferred);
11    let explicit_identity = BinaryRelation::identity_on(&states);
12    let reachable = step.reflexive_transitive_closure_on(&states);
13
14    assert_eq!(inferred.to_vec(), vec!["Draft", "Review"]);
15    assert_eq!(
16        inferred_identity.to_vec(),
17        vec![("Draft", "Draft"), ("Review", "Review")]
18    );
19    assert_eq!(
20        explicit_identity.to_vec(),
21        vec![
22            ("Archived", "Archived"),
23            ("Draft", "Draft"),
24            ("Review", "Review"),
25        ]
26    );
27    assert_eq!(states.to_vec(), vec!["Archived", "Draft", "Review"]);
28    assert_eq!(
29        reachable.to_vec(),
30        step.reflexive_transitive_closure(&states.to_unary_relation())
31            .to_vec()
32    );
33    assert!(reachable.is_reflexive_on(&states));
34    assert!(step.is_irreflexive_on(&states));
35    assert!(reachable.contains(&"Archived", &"Archived"));
36    assert!(reachable.contains(&"Draft", &"Review"));
37
38    println!(
39        "explicit carrier: {:?}; inferred support: {:?}; inferred identity: {:?}; explicit identity: {:?}; reachable: {:?}",
40        states.to_vec(),
41        inferred.to_vec(),
42        inferred_identity.to_vec(),
43        explicit_identity.to_vec(),
44        reachable.to_vec()
45    );
46}
Source

pub fn singleton(value: T) -> Self

Creates an explicit finite carrier containing exactly one value.

Source

pub fn len(&self) -> usize

Returns the number of values in the explicit carrier.

Source

pub fn is_empty(&self) -> bool

Returns true when the explicit carrier contains no values.

Source

pub fn insert(&mut self, value: T) -> bool

Inserts a value into the explicit carrier.

Returns true when the value was not already present.

Source

pub fn contains(&self, value: &T) -> bool

Returns true when the explicit carrier contains the given value.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Returns an iterator over carrier values in deterministic order.

Source

pub fn to_unary_relation(&self) -> UnaryRelation<T>
where T: Clone,

Materializes this explicit carrier as a unary relation.

This is an explicit bridge to the published exact APIs and generic code paths that still take UnaryRelation<T> carrier arguments, such as crate::BinaryRelation::identity and older call sites of crate::BinaryRelation::reflexive_transitive_closure.

The conversion is intentionally explicit because it forgets the semantic distinction between an explicitly declared carrier and ordinary unary relation support. For direct carrier-aware exact operations, prefer methods such as crate::BinaryRelation::identity_on and crate::BinaryRelation::reflexive_transitive_closure_on.

§Examples
use relmath::{BinaryRelation, FiniteCarrier};

let step = BinaryRelation::from_pairs([("Draft", "Review")]);
let states = FiniteCarrier::from_values(["Draft", "Review", "Archived"]);

assert_eq!(
    step.reflexive_transitive_closure(&states.to_unary_relation())
        .to_vec(),
    step.reflexive_transitive_closure_on(&states).to_vec()
);
Examples found in repository?
examples/carrier.rs (line 30)
5fn main() {
6    let step = BinaryRelation::from_pairs([("Draft", "Review")]);
7    let states = FiniteCarrier::from_values(["Draft", "Review", "Archived"]);
8
9    let inferred = step.carrier();
10    let inferred_identity = BinaryRelation::identity(&inferred);
11    let explicit_identity = BinaryRelation::identity_on(&states);
12    let reachable = step.reflexive_transitive_closure_on(&states);
13
14    assert_eq!(inferred.to_vec(), vec!["Draft", "Review"]);
15    assert_eq!(
16        inferred_identity.to_vec(),
17        vec![("Draft", "Draft"), ("Review", "Review")]
18    );
19    assert_eq!(
20        explicit_identity.to_vec(),
21        vec![
22            ("Archived", "Archived"),
23            ("Draft", "Draft"),
24            ("Review", "Review"),
25        ]
26    );
27    assert_eq!(states.to_vec(), vec!["Archived", "Draft", "Review"]);
28    assert_eq!(
29        reachable.to_vec(),
30        step.reflexive_transitive_closure(&states.to_unary_relation())
31            .to_vec()
32    );
33    assert!(reachable.is_reflexive_on(&states));
34    assert!(step.is_irreflexive_on(&states));
35    assert!(reachable.contains(&"Archived", &"Archived"));
36    assert!(reachable.contains(&"Draft", &"Review"));
37
38    println!(
39        "explicit carrier: {:?}; inferred support: {:?}; inferred identity: {:?}; explicit identity: {:?}; reachable: {:?}",
40        states.to_vec(),
41        inferred.to_vec(),
42        inferred_identity.to_vec(),
43        explicit_identity.to_vec(),
44        reachable.to_vec()
45    );
46}
Source

pub fn to_vec(&self) -> Vec<T>
where T: Clone,

Converts the explicit carrier into a sorted vector of values.

Examples found in repository?
examples/carrier.rs (line 27)
5fn main() {
6    let step = BinaryRelation::from_pairs([("Draft", "Review")]);
7    let states = FiniteCarrier::from_values(["Draft", "Review", "Archived"]);
8
9    let inferred = step.carrier();
10    let inferred_identity = BinaryRelation::identity(&inferred);
11    let explicit_identity = BinaryRelation::identity_on(&states);
12    let reachable = step.reflexive_transitive_closure_on(&states);
13
14    assert_eq!(inferred.to_vec(), vec!["Draft", "Review"]);
15    assert_eq!(
16        inferred_identity.to_vec(),
17        vec![("Draft", "Draft"), ("Review", "Review")]
18    );
19    assert_eq!(
20        explicit_identity.to_vec(),
21        vec![
22            ("Archived", "Archived"),
23            ("Draft", "Draft"),
24            ("Review", "Review"),
25        ]
26    );
27    assert_eq!(states.to_vec(), vec!["Archived", "Draft", "Review"]);
28    assert_eq!(
29        reachable.to_vec(),
30        step.reflexive_transitive_closure(&states.to_unary_relation())
31            .to_vec()
32    );
33    assert!(reachable.is_reflexive_on(&states));
34    assert!(step.is_irreflexive_on(&states));
35    assert!(reachable.contains(&"Archived", &"Archived"));
36    assert!(reachable.contains(&"Draft", &"Review"));
37
38    println!(
39        "explicit carrier: {:?}; inferred support: {:?}; inferred identity: {:?}; explicit identity: {:?}; reachable: {:?}",
40        states.to_vec(),
41        inferred.to_vec(),
42        inferred_identity.to_vec(),
43        explicit_identity.to_vec(),
44        reachable.to_vec()
45    );
46}

Trait Implementations§

Source§

impl<T: Clone + Ord> Clone for FiniteCarrier<T>

Source§

fn clone(&self) -> FiniteCarrier<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> Debug for FiniteCarrier<T>

Source§

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

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

impl<T: Ord> Default for FiniteCarrier<T>

Source§

fn default() -> Self

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

impl<T: Ord> Extend<T> for FiniteCarrier<T>

Source§

fn extend<I: IntoIterator<Item = 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> FromIterator<T> for FiniteCarrier<T>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<'a, T: Ord> IntoIterator for &'a FiniteCarrier<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Ord> IntoIterator for FiniteCarrier<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: PartialEq + Ord> PartialEq for FiniteCarrier<T>

Source§

fn eq(&self, other: &FiniteCarrier<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> Eq for FiniteCarrier<T>

Source§

impl<T: Ord> StructuralPartialEq for FiniteCarrier<T>

Auto Trait Implementations§

§

impl<T> Freeze for FiniteCarrier<T>

§

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

§

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

§

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

§

impl<T> Unpin for FiniteCarrier<T>

§

impl<T> UnsafeUnpin for FiniteCarrier<T>

§

impl<T> UnwindSafe for FiniteCarrier<T>
where T: RefUnwindSafe,

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.