MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / prepareBaseCases

Function prepareBaseCases

src/compute-engine/sequence.ts:170–192  ·  view source on GitHub ↗

* Prepare and sort base cases for matching. * Order: exact matches first, then patterns with fewer variables (more specific first).

(
  base: Map<number | string, Expression>
)

Source from the content-addressed store, hash-verified

168 pattern: ParsedPattern;
169 value: Expression;
170 /** Number of variables in pattern (more specific = fewer variables) */
171 variableCount: number;
172}
173
174/**
175 * Prepare and sort base cases for matching.
176 * Order: exact matches first, then patterns with fewer variables (more specific first).
177 */
178function prepareBaseCases(
179 base: Map<number | string, Expression>
180): PreparedBaseCase[] {
181 const cases: PreparedBaseCase[] = [];
182
183 for (const [key, value] of base) {
184 const pattern = parseBasePattern(key);
185 const variableCount = pattern.values.filter(
186 (v) => typeof v === 'string'
187 ).length;
188 cases.push({ pattern, value, variableCount });
189 }
190
191 // Sort: exact matches first, then by ascending variable count
192 cases.sort((a, b) => {
193 if (a.pattern.type !== b.pattern.type) {
194 return a.pattern.type === 'exact' ? -1 : 1;
195 }

Callers 1

createSequenceHandlerFunction · 0.85

Calls 1

parseBasePatternFunction · 0.85

Tested by

no test coverage detected