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
impl Set
Sourcepub fn stored_elements(&self) -> Option<&[Value]>
pub fn stored_elements(&self) -> Option<&[Value]>
Stored explicit elements, without normalization, enumeration or callbacks.
Sourcepub fn has_cached_elements(&self) -> bool
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.
Sourcepub fn order(&self) -> ValueOrder
pub fn order(&self) -> ValueOrder
The order the set is sorted in.
Sourcepub fn is_infinite(&self) -> bool
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).
Sourcepub fn elements(&self, ctx: Ctx) -> Result<Arc<[Value]>>
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.
Sourcepub fn concrete_element_stream(
&self,
ctx: Ctx,
) -> Result<Option<SetElementStream>>
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.
Sourcepub fn concrete_subset_stream(
&self,
ctx: Ctx,
) -> Result<Option<ConcreteSubsetStream>>
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.
Sourcepub fn peek_elements(&self, ctx: Ctx) -> Result<Arc<[Value]>>
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.
Sourcepub fn is_tlc_normalized(&self) -> bool
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.
Sourcepub fn size(&self, ctx: Ctx) -> Result<u64>
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.
Sourcepub fn hash64(&self) -> u64
pub fn hash64(&self) -> u64
The order-independent hash (see Value::hash64).
Sourcepub fn as_interval(&self) -> Option<(&Int, &Int)>
pub fn as_interval(&self) -> Option<(&Int, &Int)>
The interval bounds, if this is a..b.
Sourcepub fn as_fcn_set(&self) -> Option<(&Value, &Value)>
pub fn as_fcn_set(&self) -> Option<(&Value, &Value)>
The domain and range, if this is [S -> T].
Sourcepub fn as_rcd_set(&self) -> Option<&[(Atom, Value)]>
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).
Sourcepub fn as_product(&self) -> Option<&[Value]>
pub fn as_product(&self) -> Option<&[Value]>
The factors, if this is S1 \X ... \X Sn.
Sourcepub fn addr(&self) -> usize
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.
Sourcepub fn as_deferred(&self) -> Option<&Arc<dyn DeferredSet>>
pub fn as_deferred(&self) -> Option<&Arc<dyn DeferredSet>>
The evaluator-driven source, if this is a deferred set.
Sourcepub fn components(&self) -> Vec<(Option<Atom>, Value)>
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.
Sourcepub fn raw_elements(&self) -> Option<&[Value]>
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.