UNPKG

simple-graph-query

Version:

TypeScript evaluator for Forge expressions with browser-compatible UMD bundle

40 lines (39 loc) 1.98 kB
import { ExprContext } from "./forge-antlr/ForgeParser"; import { Tuple } from "./ForgeExprEvaluator"; /** * Analyzes set comprehension constraints to detect simple numeric comparison patterns * that can be optimized by generating only valid combinations instead of filtering. */ export interface NumericConstraintPattern { type: 'less_than' | 'greater_than' | 'less_equal' | 'greater_equal' | 'not_equal' | 'none'; leftVar: string; rightVar: string; } /** * Detects if a constraint expression is a simple numeric comparison between two variables. * Currently detects patterns like: a < b, a > b, a <= b, a >= b, a != b * * Note: Uses string matching on expression text which is simple but may miss expressions * with extra whitespace or parentheses. This is intentionally conservative - we prefer * to fall back to the standard approach rather than risk incorrect optimization. * * @param constraintExpr The constraint expression to analyze * @param varNames The variable names in scope * @returns Pattern info if detected, null otherwise */ export declare function detectNumericComparisonPattern(constraintExpr: ExprContext, varNames: string[]): NumericConstraintPattern | null; /** * Checks if all values in the sets are numbers (or tuples containing single numbers). * This is required for numeric comparison optimization to be applicable. */ export declare function areAllNumericSets(sets: Tuple[][]): boolean; /** * Generates optimized combinations for numeric comparison constraints. * Instead of generating all combinations and filtering, generates only valid ones. * * @param varNames Variable names in order * @param quantifiedSets The sets each variable ranges over * @param pattern The detected numeric comparison pattern * @returns Only the tuples that satisfy the constraint */ export declare function generateOptimizedNumericCombinations(varNames: string[], quantifiedSets: Tuple[][], pattern: NumericConstraintPattern): Tuple[];