Skip to main content

UniConstraintStream

Struct UniConstraintStream 

Source
pub struct UniConstraintStream<S, A, E, F, Sc>
where Sc: Score,
{ /* private fields */ }
Expand description

Zero-erasure constraint stream over a single entity type.

UniConstraintStream accumulates filters and can be finalized into an IncrementalUniConstraint via penalize() or reward().

All type parameters are concrete - no trait objects, no Arc allocations in the hot path.

§Type Parameters

  • S - Solution type
  • A - Entity type
  • E - Extractor function type
  • F - Combined filter type
  • Sc - Score type

Implementations§

Source§

impl<S, A, E, F, Sc> UniConstraintStream<S, A, E, F, Sc>
where S: Send + Sync + 'static, A: Send + Sync + 'static, E: CollectionExtract<S, Item = A>, F: UniFilter<S, A>, Sc: Score + 'static,

Source

pub fn project<P>( self, projection: P, ) -> Stream<S, P::Out, SingleSource<S, A, E, F, P, P::Out>, TrueFilter, Sc>
where P: Projection<A> + 'static,

Projects each entity that passes the stream filter into zero or more Out rows emitted by projection.

Source§

impl<S, A, E, F, Sc> UniConstraintStream<S, A, E, F, Sc>
where S: Send + Sync + 'static, A: UnassignedEntity<S>, E: CollectionExtract<S, Item = A>, F: UniFilter<S, A>, Sc: Score + 'static,

Source

pub fn unassigned( self, ) -> UniConstraintStream<S, A, E, AndUniFilter<F, FnUniFilter<fn(&S, &A) -> bool>>, Sc>

Keeps only entities whose planning variable is unassigned, as reported by their UnassignedEntity implementation.

Source§

impl<S, A, E, Sc> UniConstraintStream<S, A, E, TrueFilter, Sc>
where S: Send + Sync + 'static, A: Send + Sync + 'static, E: CollectionExtract<S, Item = A>, Sc: Score + 'static,

Source

pub fn new(extractor: E) -> Self

Creates a new uni-constraint stream with the given extractor.

Source§

impl<S, A, E, F, Sc> UniConstraintStream<S, A, E, F, Sc>
where S: Send + Sync + 'static, A: Send + Sync + 'static, E: CollectionExtract<S, Item = A>, F: UniFilter<S, A>, Sc: Score + 'static,

Source

pub fn flattened<B, Flat>( self, flatten: Flat, ) -> FlattenedCollectionTarget<S, A, B, E, F, FlattenVecExtract<Flat>, Sc>
where E: CollectionExtract<S, Item = A>, B: Send + Sync + 'static, Flat: for<'a> Fn(&'a A) -> &'a Vec<B> + Send + Sync,

Flattens each entity into the children flatten returns, as the right side of if_exists or if_not_exists. Children are read from the solution and never become rows.

Source

pub fn filter<P>( self, predicate: P, ) -> UniConstraintStream<S, A, E, AndUniFilter<F, FnUniFilter<impl Fn(&S, &A) -> bool + Send + Sync>>, Sc>
where P: Fn(&A) -> bool + Send + Sync + 'static,

Adds a filter predicate to the stream.

Source

pub fn join<J>(self, target: J) -> J::Output
where J: JoinTarget<S, A, E, F, Sc>,

Joins this stream using the provided join target.

First keyed equality cross-joins apply this stream’s accumulated unary filter as source membership before key extraction and pair creation. Post-join filters operate on joined rows. Other join dispatches do not receive this left-source filter pushdown.

Source

pub fn group_by<K, KF, C, V, R, Acc>( self, key_fn: KF, collector: C, ) -> GroupedConstraintStream<S, A, K, E, F, KF, C, V, R, Acc, Sc>
where K: Clone + Eq + Hash + Send + Sync + 'static, KF: Fn(&A) -> K + Send + Sync, C: for<'i> Collector<&'i A, Value = V, Result = R, Accumulator = Acc> + Send + Sync + 'static, V: Send + Sync + 'static, R: Send + Sync + 'static, Acc: Accumulator<V, R> + Send + Sync + 'static,

Groups entities by key and aggregates with a collector.

Source

pub fn balance<K, KF>( self, key_fn: KF, ) -> BalanceConstraintStream<S, A, K, E, F, KF, Sc>
where K: Clone + Eq + Hash + Send + Sync + 'static, KF: Fn(&A) -> Option<K> + Send + Sync,

Creates a balance constraint that penalizes uneven distribution across groups.

Source§

impl<S, A, E, F, Sc> UniConstraintStream<S, A, E, F, Sc>
where S: Send + Sync + 'static, A: Send + Sync + 'static, E: CollectionExtract<S, Item = A>, F: UniFilter<S, A>, Sc: Score + 'static,

Source

pub fn if_exists<T>(self, target: T) -> T::Output
where T: ExistenceTarget<S, A, E, F, Sc>,

Keeps entities that have at least one match in target, typically (other_stream, equal_bi(left_key, right_key)).

Source

pub fn if_not_exists<T>(self, target: T) -> T::Output
where T: ExistenceTarget<S, A, E, F, Sc>,

Keeps entities that have no match in target, typically (other_stream, equal_bi(left_key, right_key)).

Source§

impl<S, A, E, F, Sc> UniConstraintStream<S, A, E, F, Sc>
where S: Send + Sync + 'static, A: Send + Sync + 'static, E: CollectionExtract<S, Item = A>, F: UniFilter<S, A>, Sc: Score + 'static,

Source

pub fn penalize<W>( self, weight: W, ) -> UniConstraintBuilder<S, A, E, F, impl Fn(&A) -> Sc + Send + Sync, Sc>
where W: for<'w> ConstraintWeight<(&'w A,), Sc> + Send + Sync,

Penalizes each match by weight.

weight is a fixed score, or a closure over the matched entity returning one. A fixed weight with a non-zero hard level marks the constraint hard; closures are soft unless wrapped in hard_weight.

Source

pub fn reward<W>( self, weight: W, ) -> UniConstraintBuilder<S, A, E, F, impl Fn(&A) -> Sc + Send + Sync, Sc>
where W: for<'w> ConstraintWeight<(&'w A,), Sc> + Send + Sync,

Rewards each match by weight.

weight is a fixed score, or a closure over the matched entity returning one. A fixed weight with a non-zero hard level marks the constraint hard; closures are soft unless wrapped in hard_weight.

Trait Implementations§

Source§

impl<S, A, E, F, Sc> CollectionExtract<S> for UniConstraintStream<S, A, E, F, Sc>
where S: Send + Sync + 'static, A: Send + Sync + 'static, E: CollectionExtract<S, Item = A>, F: UniFilter<S, A>, Sc: Score + 'static,

Source§

type Item = A

The entity type yielded by this extractor.
Source§

fn extract<'s>(&self, s: &'s S) -> &'s [A]

Extracts the entity slice from the solution.
Source§

fn contains(&self, s: &S, item: &A) -> bool

Reports whether this extractor’s own source-level predicate accepts an item.
Source§

fn change_source(&self) -> ChangeSource

The descriptor that owns this source’s rows, or Static when no planning-variable change can alter them. Macro-generated solution source methods attach it through hidden internal support.
Source§

fn planning_id(&self, item: &A) -> Option<String>

The planning id constraint analysis reports for item, rendered as described on EntityRef::planning_id. Read only while explaining a match, never while scoring. Planning-model entity and fact collections report their #[planning_id]; the default reports none.
Source§

impl<S, A, E, F, Sc: Score> Debug for UniConstraintStream<S, A, E, F, Sc>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, A, E, F, Sc> Forget for UniConstraintStream<S, A, E, F, Sc>

§

impl<S, A, E, F, Sc> Freeze for UniConstraintStream<S, A, E, F, Sc>
where E: Freeze, F: Freeze, PhantomData<(fn() -> S, fn() -> A, fn() -> Sc)>: Freeze,

§

impl<S, A, E, F, Sc> Move for UniConstraintStream<S, A, E, F, Sc>

§

impl<S, A, E, F, Sc> RefUnwindSafe for UniConstraintStream<S, A, E, F, Sc>
where E: RefUnwindSafe, F: RefUnwindSafe, PhantomData<(fn() -> S, fn() -> A, fn() -> Sc)>: RefUnwindSafe,

§

impl<S, A, E, F, Sc> Send for UniConstraintStream<S, A, E, F, Sc>
where E: Send, F: Send, PhantomData<(fn() -> S, fn() -> A, fn() -> Sc)>: Send,

§

impl<S, A, E, F, Sc> Sync for UniConstraintStream<S, A, E, F, Sc>
where E: Sync, F: Sync, PhantomData<(fn() -> S, fn() -> A, fn() -> Sc)>: Sync,

§

impl<S, A, E, F, Sc> Unpin for UniConstraintStream<S, A, E, F, Sc>
where E: Unpin, F: Unpin, PhantomData<(fn() -> S, fn() -> A, fn() -> Sc)>: Unpin,

§

impl<S, A, E, F, Sc> UnsafeUnpin for UniConstraintStream<S, A, E, F, Sc>
where E: UnsafeUnpin, F: UnsafeUnpin, PhantomData<(fn() -> S, fn() -> A, fn() -> Sc)>: UnsafeUnpin,

§

impl<S, A, E, F, Sc> UnwindSafe for UniConstraintStream<S, A, E, F, Sc>
where E: UnwindSafe, F: UnwindSafe, PhantomData<(fn() -> S, fn() -> A, fn() -> Sc)>: 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> 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, 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.