Skip to content

v3: Declarative constraint engine, forward check, and FNV-1a hash sorter#43

Merged
righ merged 3 commits intomasterfrom
feature/use-fnv1a32
Apr 16, 2026
Merged

v3: Declarative constraint engine, forward check, and FNV-1a hash sorter#43
righ merged 3 commits intomasterfrom
feature/use-fnv1a32

Conversation

@righ
Copy link
Copy Markdown
Member

@righ righ commented Apr 16, 2026

v3: Declarative Constraint Engine + FNV-1a Hash Sorter

TypeScript: v3 Core

  • Declarative constraints (constraints: Condition[])

    • Condition types: comparison (eq, ne, gt, lt, gte, lte, in), logical (and, or, not), and custom (escape hatch with dependency keys)
    • Field-to-field comparison via target (e.g. { operator: 'ne', field: 'A', target: 'B' })
    • Custom Comparer interface to override comparison behavior
    • Replaces preFilter / postFilter function-based approach
  • Three-valued evaluation (evaluate.ts)

    • Kleene logic: true (satisfied), false (violated), null (deferred — field not yet set)
    • extractKeys() for dependency tracking per condition
    • AND short-circuits on false, OR short-circuits on true, NOT propagates null
  • Forward check (constraint propagation)

    • Arc-consistency domain pruning for unfilled factors
    • Peer propagation: union-based viability check across candidate values
    • Forced assignment when domain narrows to a single value
    • Returns false immediately when any domain empties
  • Controller rewrite

    • setPair() — snapshot-based validation; row unchanged on failure
    • storableCheck() / markPassedConstraints() with passedIndexes optimization
    • Two-pass initial pruning: direct violations + forward-check chains
    • Row.invalidPairs — prevents greedy from re-attempting failed pairs
    • Rescue phase (Phase 3): individually retries remaining uncovered pairs
    • close() rewritten with depth-first backtracking returning conflictKeys
    • stats getter: totalPairs, prunedPairs, coveredPairs, progress, rowCount, uncoveredPairs, completions
    • isComplete treats null as satisfied (null tolerance)
    • diagnoseUncoveredPairs() for constraint failure reporting
  • Greedy criterion optimization

    • Fast path for strength=2: direct arr[i] * arr[j] (4x speedup on hot path)
    • rowCovered exclusion set
    • invalidPairs skip
    • isCompatible() fast check before full storable()
  • PictModel rewrite

    • _modelConstraints() converts lexer filters + negative rules to Condition[]
    • _buildOptions() passes constraints (not preFilter)
    • _applyNegativePrefix() for ~ output
    • stats / progress getters
    • Comment lines (#) in constraint section ignored
  • Build tooling: webpack → vite, tslint removed, pnpm

Python: v3 Port

All TypeScript v3 features ported:

  • evaluate.py — Three-valued constraint evaluation (same Kleene logic)
  • Controllerconstraints/comparer params, set_pair(), _forward_check(), _storable_check(), _mark_passed_constraints(), two-pass pruning, Row.invalid_pairs, rescue phase, _close() with backtracking, stats, null-tolerant is_complete, _diagnose_uncovered_pairs()
  • Greedy — s=2 fast path, row_covered, invalid_pairs skip, is_compatible()
  • PictModel_model_constraints(), _apply_negative_prefix(), stats/progress, comment ignore
  • Lexerfilter_keys tracking for dependency-aware constraint indexing
  • Backward compatible: pre_filter / post_filter still work; constraints is optional

FNV-1a Hash Sorter

  • Both TS and Python now use FNV-1a 32-bit hash for pair sorting (deterministic, fast)
  • Removes MD5 dependency (hashlib in Python, md5 / ts-md5 in TypeScript)

@righ righ merged commit 5550c55 into master Apr 16, 2026
@righ righ deleted the feature/use-fnv1a32 branch April 16, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant