Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/solverforge-scoring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Incremental constraint scoring for SolverForge"

[dependencies]
solverforge-core = { version = "=0.31.5", path = "../solverforge-core" }
smallvec.workspace = true

[lints.rust]
unreachable_pub = "warn"
Expand Down
73 changes: 46 additions & 27 deletions crates/solverforge-scoring/WIREFRAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ migration of the fluent stream families:
- `ExistenceNode<S, L, R, K, LK, RK>::new(left, right, left_key, right_keys,
exists)` answers a pure-key semi/anti join from per-key occurrence counts
(dense arrays for `usize` planning ids via `KeyState` in
`stream/relational/count_state.rs`, hash tables otherwise). The left key
`stream/relational/count_state.rs`, otherwise one key table holding each
key once, addressed by slot). The left key
adapter implements `ViewKey<L::View<'a>>`; the right adapter implements
`RightKeySet<R::View<'a>>` (`UnitKeys` for one key per right row,
`ParentChildKeys` to expand flattened children in place, `GroupRightKeys`
Expand All @@ -87,10 +88,14 @@ migration of the fluent stream families:
result bindings; unmatched targets own their default payloads. `ComplementView`
is `Real(Pair<L, R>)` or `Default(ProjectView<'a, L, T>)`. Duplicate target
rows preserve bag multiplicity, and grouped results have one accumulator owner.
- `JoinNode<S, L, R, P>::new(left, right, condition)` compiles a condition and
produces `Pair<L::View<'a>, R::View<'a>>`; either input can itself be a join.
`Pair<L, R>` has public `left` and `right` fields. Depth is recursive rather
than fixed to a named arity.
- `JoinNode<S, L, R, P, F = AcceptAll>::new(left, right, condition)` compiles a
condition and produces `Pair<L::View<'a>, R::View<'a>>`; either input can
itself be a join. `JoinNode::filtered(left, right, condition, filter)` adds a
row filter `F: FilterPredicate<S, Pair<..>>` that runs when a pair is found,
before it is retained, so a rejected pair is never stored. A pair is emitted
once per change without an identity table: the right probe skips left rows
inserted by the same change. `Pair<L, R>` has public `left` and `right`
fields. Depth is recursive rather than fixed to a named arity.
- `stream::chain::{Chain<S, O, Sc>, ChainBuilder}` is the arity-free fluent continuation:
`stream::cross::Penta::join` returns one, and `Chain::join` nests further `JoinNode`s with no
ceiling; `Chain::filter` wraps the tree in an identity-preserving
Expand Down Expand Up @@ -140,11 +145,16 @@ migration of the fluent stream families:
on: `ViewKey<V>` reads a key out of a view; `EntityKey<F>` lifts an entity
key onto a leaf view, `ChildKey<F>` onto a flattened child view; `PairKey<A, B>`
pairs two keys over one view; `FlattenedPairKey<KB, CK>` pairs the owning
entity's key with the flattened child's key; `GroupKey` reads a grouped row's
own key; and `ViewEqualPlan` is the typed hash-equality plan
over two named view keys.
entity's key with the flattened child's key; and `ViewEqualPlan` is the
typed hash-equality plan over two named view keys. `GroupEqualPlan<K, KeyFn,
Side>` matches a grouped row's own key to `KeyFn` of the other input
(`GroupLeft` or `GroupRight` names the grouped side); it indexes groups by
key hash, so a group's key is stored once, in its group.
- `stream::relational::operator::FilterPredicate<S, V>` is the named predicate
`FilterNode` evaluates; `FlattenSource<S, O>` names a flatten extractor over
`FilterNode`, `JoinNode` and `SelfJoinNode` evaluate. Its
`const ACCEPTS_ALL: bool = false` lets an operator skip resolving rows only
to test them; `AcceptAll` is the predicate that sets it and the default row
filter of both joins; `FlattenSource<S, O>` names a flatten extractor over
an operator view, and `ParentFlatten<Inner>` adapts an entity-level child
extractor to it.
- `stream::cross::QuadBuilder` and `stream::cross::PentaBuilder` are the
Expand All @@ -154,11 +164,13 @@ migration of the fluent stream families:
New file map: `stream/relational/operator.rs`,
`stream/relational/operator/{analysis,collection,complement,complement_view,
existence,filter,flatten,group,group_view,join,joiner_existence,merge,project,
self_join}.rs`,
`stream/relational/{count_state,keyed_plan,view_plan}.rs`,
self_join}.rs`, `stream/relational/operator/join/incremental.rs` (a join's
retained-pair maintenance),
`stream/relational/{count_state,key_table,keyed_plan,view_plan}.rs`,
`stream/relational/view_plan/group.rs`,
`stream/joiner/plan.rs`, `stream/joiner/plan/{executable,hash_scan,conjunction,
composite,mixed_equality,ordered_interval}.rs`, `stream/joiner/row_key.rs`,
`stream/relational/index/{hash,ordered,interval}.rs`,
`stream/relational/index/{hash,hashed,ordered,interval}.rs`,
`stream/relational/hash.rs`, and
`constraint/relational/operator_terminal.rs`. Generational direct side-tables
are internal in `stream/relational/handle_map.rs`; `stream/relational/hash.rs`
Expand Down Expand Up @@ -281,7 +293,7 @@ src/
│ ├── cross.rs — Public `stream::cross` re-exports of the cross-join streams and builders
│ ├── projected.rs — Public `stream::projected` re-exports of the projected streams and builders
│ ├── cross_penta_stream.rs — stream::cross::Penta and its Penta::join → Chain
│ ├── cross_penta_stream/scored.rs — PentaScored operator (tree plus authored filter)
│ ├── cross_penta_stream/scored.rs — PentaRowFilter and the filtered penta tree
│ ├── grouped_stream.rs — Re-exports
│ ├── grouped_stream/base.rs — GroupedConstraintStream
│ ├── grouped_stream/weighting.rs — GroupedConstraintBuilder
Expand All @@ -290,17 +302,18 @@ src/
│ ├── complemented_stream.rs — ComplementedConstraintStream, ComplementedConstraintBuilder
│ ├── cross_bi_stream.rs — Re-exports
│ ├── cross_bi_stream/base.rs — stream::cross::Bi
│ ├── cross_bi_stream/scored.rs — BiUnaryPlan, BiPredicatePlan, BiScored (first-join execution)
│ ├── cross_bi_stream/scored.rs — BiUnaryPlan, BiPredicatePlan, BiRowFilter (first-join execution)
│ ├── cross_bi_stream/view_comparison.rs — ViewComparisonPlan, ViewOverlapPlan (entity conditions over leaf views)
│ ├── cross_bi_stream/grouped.rs — stream::cross::Grouped and builder
│ ├── cross_bi_stream/complemented_grouped.rs — stream::cross::ComplementedGrouped and builder
│ ├── cross_bi_stream/weighting.rs — stream::cross::Builder
│ ├── cross_tri_stream.rs — Re-exports
│ ├── cross_tri_stream/base.rs — stream::cross::Tri and builder
│ ├── cross_tri_stream/base/scored.rs — TriScored operator (tree plus authored filter)
│ ├── cross_tri_stream/base/scored.rs — TriRowFilter and the filtered tri tree
│ ├── flattened_bi_stream.rs — Re-exports
│ ├── flattened_bi_stream/base.rs — FlattenedBiConstraintStream
│ ├── flattened_bi_stream/builder.rs — FlattenedBiConstraintBuilder
│ ├── flattened_bi_stream/scored.rs — FlattenedBiRowFilter, the join's row filter
│ ├── flattened_bi_stream/weighting.rs — Weighting helpers for flattened streams
│ ├── existence_stream.rs — ExistsConstraintStream, ExistsConstraintBuilder, ExistenceMode
│ ├── existence_target.rs — ExistenceTarget trait for direct and flattened existence targets
Expand Down Expand Up @@ -338,7 +351,7 @@ src/
│ │ ├── mod.rs — Re-exports filter types
│ │ ├── traits.rs — UniFilter, BiFilter, TriFilter, QuadFilter, PentaFilter traits
│ │ ├── wrappers.rs — TrueFilter, FnUniFilter, FnBiFilter, FnTriFilter, FnQuadFilter, FnPentaFilter
│ │ ├── adapters.rs — UniBiFilter, UniLeftBiFilter, UniPairFilter, and hidden PairFilter adapters
│ │ ├── adapters.rs — UniBiFilter, UniLeftBiFilter, UniPairFilter, SelfJoinRowFilter, and hidden PairFilter adapters
│ │ ├── composition.rs — AndUniFilter, AndBiFilter, AndTriFilter, AndQuadFilter, AndPentaFilter
│ │ └── tests/
│ │ ├── mod.rs — Test module declarations
Expand Down Expand Up @@ -565,8 +578,8 @@ All `Send + Sync`:
`BiFilter`, `TriFilter`, `QuadFilter` and `PentaFilter` also carry
`const ACCEPTS_ALL: bool = false`. `TrueFilter` sets it, the `And*` filters
set it when both sides do, and the arity-lifting adapters forward it. The
penta boundary (`PentaScored`) passes rows straight through when it holds, so
an unfiltered chain pays no accepted-row bookkeeping.
row filters built from them forward it to `FilterPredicate::ACCEPTS_ALL`, so an
unfiltered self-join never resolves a combination just to test it.

Joined filter indexes are semantic source indexes, not builder-local
placeholders. Same-source joins pass canonical entity indexes; cross-bi passes
Expand Down Expand Up @@ -715,7 +728,8 @@ collection (`stream::projected::ComplementedGroupedBuilder::named()`, including
complement targets keep default rows until matched and each terminal scores
independently.

Flattened bi streams finalize into `OperatorTerminal` over `FlattenedBiScored`;
Flattened bi streams finalize into `OperatorTerminal` over a `JoinNode` whose
row filter is the authored bi filter;
filters receive the A source index and the owning B source index for each
flattened C row. Existence streams finalize into `OperatorTerminal` over
`ExistenceNode`, the pure-key, count-backed semi/anti join; conditions with a
Expand Down Expand Up @@ -884,7 +898,7 @@ ConstraintFactory::<Plan, HardSoftScore>::new()
- Operations: `filter()`, `join()` → `TriConstraintStream`, `penalize(weight_or_fn)`, `reward(weight_or_fn)`
- Low-level constructors: `new_self_join()`, `new_self_join_with_filter()`

**`BiConstraintBuilder<S, A, K, E, KE, F, W, Sc>`** — `named()` → `OperatorTerminal` over a `SelfJoinNode` + `FilterNode` tree
**`BiConstraintBuilder<S, A, K, E, KE, F, W, Sc>`** — `named()` → `OperatorTerminal` over a `SelfJoinNode` whose row filter is the authored filter

**`TriConstraintStream/Builder`** — Same pattern, tri-arity. `join()` →
`QuadConstraintStream`; low-level constructors are `new_self_join()` and
Expand Down Expand Up @@ -923,7 +937,7 @@ further joins); low-level constructors are `new_self_join()` and

**`stream::projected::ComplementedGrouped/Builder`** — Projected grouped complement stream. `penalize(weight_or_fn)`, `reward(weight_or_fn)`, `named()` → `SharedOperatorTerminal` over `ComplementNode(CollectionNode, GroupNode)`. Complement defaults are produced from the complement entity and weighted by key plus collector result.

**`FlattenedBiConstraintStream/Builder`** — Flattened bi stream. `filter()`, `penalize(weight_or_fn)`, `reward(weight_or_fn)`, `named()` → `OperatorTerminal` over `FlattenedBiScored`. Low-level filters receive the A source index and the B owner index for the flattened C row.
**`FlattenedBiConstraintStream/Builder`** — Flattened bi stream. `filter()`, `penalize(weight_or_fn)`, `reward(weight_or_fn)`, `named()` → `OperatorTerminal` over a filtered `JoinNode`. Low-level filters receive the A source index and the B owner index for the flattened C row.

**`ExistsConstraintStream/ExistsConstraintBuilder`** — Existence stream over source-aware direct or flattened collection targets. `penalize(weight_or_fn)`, `reward(weight_or_fn)`, `named()` → `OperatorTerminal` over `ExistenceNode<S, L, R, K, LK, RK>`. There is no separate public indexed existence stream.

Expand Down Expand Up @@ -1015,7 +1029,9 @@ further joins); low-level constructors are `new_self_join()` and

**`LoadBalanceCollector<K, F, M>`** / **`LoadBalanceAccumulator<K>`** / **`LoadBalance<K>`** — Load balance with unfairness metric.
- Factory: `load_balance(key_fn, metric_fn)`
- `LoadBalance<K>` has `loads()` and `unfairness()` methods.
- `LoadBalance<K>` has `loads()` (each item with its total load), `load(&key)`
and `unfairness()` methods. The accumulator stores each item's key once; its
retraction token is the item's slot and metric.

**`RunsCollector<F>`** / **`RunsAccumulator`** / **`Run`** / **`Runs`** — Consecutive unique `i64` point runs with duplicate item accounting.
- Factory: `consecutive_runs(index_fn)`
Expand Down Expand Up @@ -1061,13 +1077,16 @@ The `ScoreDirector` delegates to `ConstraintSet::on_retract_all()` / `on_insert_

### Self-Join Operator

Same-collection n-ary streams build a `SelfJoinNode<S, A, O, K, KE, N>` over
Same-collection n-ary streams build a `SelfJoinNode<S, A, O, K, KE, N, F>` over
their collection source. It buckets input rows by key, emits every increasing
handle tuple of arity `N` per bucket (unique ordered combinations, so a triple
is `i < j < k` for one key), and maintains exact insert/retract deltas over a
retained combo set. The view is `[Leaf<'a, A>; N]` in canonical index order.
The authored filter runs in a `FilterNode` on top, and the terminal is the
shared `OperatorTerminal`. No per-arity incremental engine remains.
is `i < j < k` for one key), and maintains exact insert/retract deltas: each
input row keeps its key and bucket position and each combination its link
positions, so retraction touches only that row's bucket and combinations.
The view is `[Leaf<'a, A>; N]` in canonical index order.
`SelfJoinNode::filtered(input, key, filter)` applies the authored filter
(`SelfJoinRowFilter`) before a combination is retained, and the terminal is
the shared `OperatorTerminal`. No per-arity incremental engine remains.

### Stream Arity Macros

Expand Down
Loading
Loading