Simplified selectColumnSizeHeuristic

This commit is contained in:
Matt Low 2021-02-25 00:49:41 -07:00
parent 18e468b17f
commit 058dc13c1c

View File

@ -33,18 +33,13 @@ type SolutionCallback = (output: DNode[]) => boolean;
type ColumnSelector = (header: CNode) => CNode; type ColumnSelector = (header: CNode) => CNode;
function selectColumnSizeHeuristic(header: CNode): CNode { function selectColumnSizeHeuristic(header: CNode): CNode {
let minSize = Infinity; let minColumn = header.right;
let minColumn: CNode | undefined; let curColumn = minColumn;
let curColumn = header;
while ((curColumn = curColumn.right) !== header) { while ((curColumn = curColumn.right) !== header) {
if (curColumn.column.size < minSize) { if (curColumn.size < minColumn.size) {
minSize = curColumn.column.size;
minColumn = curColumn; minColumn = curColumn;
} }
} }
if (!minColumn) {
throw new Error("minColumn is undefined, this shouldn't be possible.");
}
return minColumn; return minColumn;
} }