private void Uncover(DataObject headerColumn) { foreach (var row in EnumerateNodes(headerColumn, o => o.Up)) { foreach (var column in EnumerateNodes(row, o => o.Left)) { column.Down.Up = column; column.Up.Down = column; column.Header.Size++; } } headerColumn.Right.Left = headerColumn; headerColumn.Left.Right = headerColumn; }
private void InsertDoublyLinkedNode(DataObject left, ColumnObject up, DataObject node) { node.InsertHorizontalNode(left.Left, left); node.InsertVerticalNode(up.Up, up); node.Header = up; node.Header.Size++; }
private void CreateConstraints(uint matrixRow, uint[] matrixColumns, uint row, uint column, uint value) { DataObject left = null; foreach (var matrixColumn in matrixColumns) { var node = new DataObject { Row = row, Column = column, Value = ++value }; if (left == null) { left = node; } var up = _columnHeaders[matrixColumn]; _constraintMatrix[matrixRow, matrixColumn] = node; InsertDoublyLinkedNode(left, up, node); } }
private IEnumerable<DataObject> EnumerateNodes(DataObject start, Func<DataObject, DataObject> function) { var node = start; while ((node = function(node)) != start) { yield return node; } }
private void Cover(DataObject headerColumn) { headerColumn.Right.Left = headerColumn.Left; headerColumn.Left.Right = headerColumn.Right; foreach (var row in EnumerateNodes(headerColumn, o => o.Down)) { foreach (var column in EnumerateNodes(row, o => o.Right)) { column.Down.Up = column.Up; column.Up.Down = column.Down; column.Header.Size--; } } }