* Convert a QM term (for minterms) to a Expression. * Each term becomes an And of literals.
( term: QMTerm, variables: string[], ce: ComputeEngine )
| 931 | while (currentTerms.size > 0) { |
| 932 | const nextTerms: Map<string, { term: QMTerm; combined: boolean }> = |
| 933 | new Map(); |
| 934 | |
| 935 | // Group terms by number of 1s |
| 936 | const groups: Map<number, Array<{ key: string; term: QMTerm }>> = new Map(); |
| 937 | for (const [key, { term }] of currentTerms) { |
| 938 | const ones = countOnes(term); |
| 939 | if (!groups.has(ones)) { |
| 940 | groups.set(ones, []); |
| 941 | } |
| 942 | groups.get(ones)!.push({ key, term }); |
| 943 | } |
| 944 | |
| 945 | // Try to combine adjacent groups (differ by one 1) |
| 946 | const sortedGroupKeys = Array.from(groups.keys()).sort((a, b) => a - b); |
| 947 | |
| 948 | for (let i = 0; i < sortedGroupKeys.length - 1; i++) { |
| 949 | const group1 = groups.get(sortedGroupKeys[i])!; |
| 950 | const group2 = groups.get(sortedGroupKeys[i + 1])!; |
| 951 | |
| 952 | for (const { key: key1, term: term1 } of group1) { |
| 953 | for (const { key: key2, term: term2 } of group2) { |
| 954 | const diffPos = canCombine(term1, term2); |
| 955 | if (diffPos !== -1) { |
| 956 | // Mark both as combined |
| 957 | const entry1 = currentTerms.get(key1)!; |
no test coverage detected