Пример #1
0
        // Detect blocks of formula copies, for finding compact support sets
        public void AddToSupportSets()
        {
            int sheetCols = Cols, sheetRows = Rows;

            cells.Forall((int col, int row, Cell cell) => {
                if (cell is ArrayFormula)
                {
                    // Do not try to detect copies of array formulas.
                    // CHECK THIS!
                    ArrayFormula af = cell as ArrayFormula;
                    af.AddToSupportSets(this, col, row, 1, 1);
                }
                else if (cell is Formula)
                {
                    Formula f = cell as Formula;
                    if (!f.Visited)
                    {
                        Expr expr = f.Expr;
                        // (1) Find a large rectangle containing only formula f
                        // (1a) Find largest square of copies with upper left corner = (col, row)
                        int size = 1;
                        while (col + size < sheetCols && row + size < sheetRows &&
                               CheckCol(col + size, row, expr, size) &&
                               CheckRow(col, row + size, expr, size))
                        {
                            size++;
                        }
                        // All cells in sheet[col..col+size-1, row..row+size-1] contain expression expr
                        // (1b) Try extending square with more rows below
                        int rowSize = size;
                        while (row + rowSize < sheetRows && CheckRow(col, row + rowSize, expr, size - 1))
                        {
                            rowSize++;
                        }
                        // sheet[col..col+size-1, row..row+rows-1] contains expr
                        // (1c) Try extending square with more columns to the right
                        int cols = size;
                        while (col + cols < sheetCols && CheckCol(col + cols, row, expr, size - 1))
                        {
                            cols++;
                        }
                        // sheet[col..col+cols-1, row..row+size-1] contains expr
                        if (rowSize > cols)
                        {
                            cols = size;
                        }
                        else
                        {
                            rowSize = size;
                        }
                        // All cells in sheet[col..col+cols-1, row..row+rows-1] contain expression expr
                        // (2) Mark all cells in the rectangle visited
                        for (int deltaCol = 0; deltaCol < cols; deltaCol++)
                        {
                            for (int deltaRow = 0; deltaRow < rowSize; deltaRow++)
                            {
                                (this[col + deltaCol, row + deltaRow] as Formula).Visited = true;
                            }
                        }
                        // (3) Update the support sets of cells referred to from expr
                        expr.AddToSupportSets(this, col, row, cols, rowSize);
                    }
                }
            });
            this.ResetCellState();             // Undo changes made to the sheet's cells' states
        }
Пример #2
0
 public override void AddToSupportSets(Sheet supported, int col, int row, int cols, int rows)
 {
     e.AddToSupportSets(supported, col, row, cols, rows);
 }