Exemple #1
0
        private static void UncoverColumn(ColumnObject c)
        {
            for (var i = c.Up; i != c; i = i.Up)
            {
                for (var j = i.Left; j != i; j = j.Left)
                {
                    j.ListHeader.RelinkDataObject(j);
                }
            }

            c.RelinkColumnHeader();
        }
Exemple #2
0
        private static void CoverColumn(ColumnObject c)
        {
            c.UnlinkColumnHeader();

            for (var i = c.Down; i != c; i = i.Down)
            {
                for (var j = i.Right; j != i; j = j.Right)
                {
                    j.ListHeader.UnlinkDataObject(j);
                }
            }
        }
Exemple #3
0
        private static ColumnObject ChooseColumnWithLeastRows(ColumnObject root)
        {
            ColumnObject chosenColumn = null;

            for (var columnHeader = root.NextColumnObject; columnHeader != root; columnHeader = columnHeader.NextColumnObject)
            {
                if (chosenColumn == null || columnHeader.NumberOfRows < chosenColumn.NumberOfRows)
                {
                    chosenColumn = columnHeader;
                }
            }

            return(chosenColumn);
        }
Exemple #4
0
 private static bool MatrixIsEmpty(ColumnObject root)
 {
     return(root.NextColumnObject == root);
 }
Exemple #5
0
        private static ColumnObject BuildInternalStructure <TData, TRow, TCol>(
            TData data,
            Func <TData, IEnumerable <TRow> > iterateRows,
            Func <TRow, IEnumerable <TCol> > iterateCols,
            Func <TCol, bool> predicate,
            int?numPrimaryColumns = null)
        {
            var root = new ColumnObject();

            int?numColumns           = null;
            var rowIndex             = 0;
            var colIndexToListHeader = new Dictionary <int, ColumnObject>();

            foreach (var row in iterateRows(data))
            {
                DataObject firstDataObjectInThisRow = null;
                var        localRowIndex            = rowIndex;
                var        colIndex = 0;

                foreach (var col in iterateCols(row))
                {
                    if (localRowIndex == 0)
                    {
                        var listHeader      = new ColumnObject();
                        var isPrimaryColumn = !numPrimaryColumns.HasValue || colIndex < numPrimaryColumns.Value;
                        if (isPrimaryColumn)
                        {
                            root.AppendColumnHeader(listHeader);
                        }
                        colIndexToListHeader[colIndex] = listHeader;
                    }

                    if (predicate(col))
                    {
                        var listHeader = colIndexToListHeader[colIndex];
                        var dataObject = new DataObject(listHeader, localRowIndex);

                        if (firstDataObjectInThisRow != null)
                        {
                            firstDataObjectInThisRow.AppendToRow(dataObject);
                        }
                        else
                        {
                            firstDataObjectInThisRow = dataObject;
                        }
                    }

                    colIndex++;
                }

                if (numColumns.HasValue)
                {
                    if (colIndex != numColumns)
                    {
                        throw new ArgumentException("All rows must contain the same number of columns", nameof(data));
                    }
                }
                else
                {
                    numColumns = colIndex;
                }

                rowIndex++;
            }

            return(root);
        }
Exemple #6
0
 public SearchData(ColumnObject root)
 {
     Root = root;
 }