Skip to main content

Set

Struct Set 

Source
pub struct Set(/* private fields */);
Expand description

A set, enumerated or lazy. Cloning is a reference-count increment.

Enumerated sets are kept normalized: sorted in the run’s ValueOrder without duplicates. Lazy sets (a..b, SUBSET S, [S -> T], S \X T, [a : S], Nat, Int, STRING, Seq(S), and evaluator-driven filters and maps) keep their definition; membership is decided without enumerating, as in TLC. Equality, ordering, hashing and fingerprints stream lazy sets in normalized order rather than materializing them. Infinite sets refuse enumeration with ErrorKind::NotEnumerable.

Implementations§

Source§

impl Set

Source

pub fn stored_elements(&self) -> Option<&[Value]>

Stored explicit elements, without normalization, enumeration or callbacks.

Source

pub fn has_cached_elements(&self) -> bool

Whether normalized element storage has already been cached. This reads storage only; it invokes no provider and grants no authority to reproduce a deferred provider’s conversion or callback history.

Source

pub fn kind(&self) -> SetKind

The set’s kind.

Source

pub fn order(&self) -> ValueOrder

The order the set is sorted in.

Source

pub fn is_infinite(&self) -> bool

Whether the set is infinite (Nat, Int, STRING, Seq(S) for non-empty S, and lazy sets built from those).

Source

pub fn elements(&self, ctx: Ctx) -> Result<Arc<[Value]>>

The elements in normalized order, enumerating if the set is lazy: TLC’s elements()/toSetEnum(). An unnormalized (Raw) set counts as normalized afterwards, as in TLC.

§Errors

ErrorKind::NotEnumerable for an infinite or symbolic set, ErrorKind::TooLarge when the set is too large, and comparison errors from normalization.

Source

pub fn concrete_element_stream( &self, ctx: Ctx, ) -> Result<Option<SetElementStream>>

Streams a concrete set’s raw TLC enumeration over concrete components, without sizing or materializing the complete compound result.

Returns None, without normalization or callbacks, unless this is a finite explicit collection, interval, powerset, product, function set or record set whose complete component storage is concrete and in the same value order. Deferred or symbolic storage keeps its old route. All capability checks precede effects; this selects output storage, never admission.

Constructor emptiness checks precede component normalization, in TLC’s order. Nonempty components are materialized before the first output, so this does not make a huge individual component incremental. Output order follows this set’s construction order; callers must establish that it is their required exploration order. The full result is not cached.

use dive_value::{Ctx, Value};
let ctx = Ctx::dive();
let base = Value::interval(1.into(), 31.into(), ctx);
let Value::Set(powerset) = Value::subset(base, ctx) else {
    return Err("SUBSET must produce a set".into());
};
let mut elements = powerset.concrete_element_stream(ctx)?
    .ok_or("components need another enumeration route")?;
assert_eq!(elements.next(), Some(Value::set(vec![], ctx)?));
§Errors

Required component size/normalization errors. A failed capability check returns None rather than evaluating or refusing an unsupported provider.

Source

pub fn concrete_subset_stream( &self, ctx: Ctx, ) -> Result<Option<ConcreteSubsetStream>>

Prepare a concrete powerset with typed, transactional integer positions. Non-powersets or unknown component storage decline before consumption. The required component size/normalization precedes its first empty value.

§Errors

The same required component errors as Self::concrete_element_stream.

Source

pub fn peek_elements(&self, ctx: Ctx) -> Result<Arc<[Value]>>

The elements in normalized order, without changing TLC’s view of the set or of any set nested in it: Set::elements without its side effects.

§Errors

As Set::elements.

Source

pub fn is_tlc_normalized(&self) -> bool

Whether TLC would treat the set as normalized (always, except for a Raw set that no normalizing operation has touched). This reads representation only; it neither enumerates nor changes the set. It is not a validation certificate.

Source

pub fn size(&self, ctx: Ctx) -> Result<u64>

The number of elements (TLC’s size(), which normalizes).

§Errors

As Set::elements, plus TLC’s size limits in IntMode::Tlc.

Source

pub fn hash64(&self) -> u64

The order-independent hash (see Value::hash64).

Source

pub fn as_interval(&self) -> Option<(&Int, &Int)>

The interval bounds, if this is a..b.

Source

pub fn as_fcn_set(&self) -> Option<(&Value, &Value)>

The domain and range, if this is [S -> T].

Source

pub fn as_rcd_set(&self) -> Option<&[(Atom, Value)]>

The fields and their sets, if this is [a : S, ...], sorted in the set’s order (TLC’s SetOfRcdsValue.sortByNames under ValueOrder::Tlc).

Source

pub fn as_product(&self) -> Option<&[Value]>

The factors, if this is S1 \X ... \X Sn.

Source

pub fn ptr_eq(&self, other: &Self) -> bool

Whether two handles share the same allocation.

Source

pub fn addr(&self) -> usize

The address of the shared allocation: while both handles are alive, two handles have the same address exactly when they are ptr_eq.

Source

pub fn as_deferred(&self) -> Option<&Arc<dyn DeferredSet>>

The evaluator-driven source, if this is a deferred set.

Source

pub fn components(&self) -> Vec<(Option<Atom>, Value)>

The components of a lazy set: the base of SUBSET S or Seq(S), the domain and range of [S -> T], the factors of S1 \X ... \X Sn, or the field sets of [a : S, ...] (with their names); empty for other kinds.

Source

pub fn raw_elements(&self) -> Option<&[Value]>

The elements of an enumerated set as constructed, without normalizing it (TLC’s SetEnumValue.elems before normalize()), or None for other kinds or a set TLC would already treat as normalized.

Trait Implementations§

Source§

impl Clone for Set

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Set

§

impl !UnwindSafe for Set

§

impl Forget for Set

§

impl Freeze for Set

§

impl Move for Set

§

impl Send for Set

§

impl Sync for Set

§

impl Unpin for Set

§

impl UnsafeUnpin for Set

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.