{@inheritDoc}
The generated potential solution is guaranteed to have no
duplicates in any row but could have duplicates in a column or sub-grid.
554590
public Sudoku generateRandomCandidate(Random rng)
    {
        // Clone the template as the basis for this grid.
        Sudoku.Cell[][] rows = template.clone();
        for (int i = 0; i < rows.length; i++)
        {
            rows[i] = template[i].clone();
        }

        // Fill-in the non-fixed cells.
        for (int i = 0; i < rows.length; i++)
        {
            List<Integer> rowValues = nonFixedValues.get(i);
            Collections.shuffle(rowValues);
            int index = 0;
            for (int j = 0; j < rows[i].length; j++)
            {
                if (rows[i][j] == null)
                {
                    rows[i][j] = new Sudoku.Cell(rowValues.get(index), false);
                    ++index;
                }
            }
        }
        return new Sudoku(rows);
    }
1313908
private void setUniqueWhere(Where<DataColumnConstraints, Void> where,
			String constraintName, DataColumnConstraintType constraintType,
			String value) throws SQLException {

		where.eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME, constraintName)
				.and()
				.eq(DataColumnConstraints.COLUMN_CONSTRAINT_TYPE,
						constraintType.getValue());
		if (value == null) {
			where.and().isNull(DataColumnConstraints.COLUMN_VALUE);
		} else {
			where.and().eq(DataColumnConstraints.COLUMN_VALUE, value);
		}

	}
695506
public static boolean cs_dupl(Scs A) {
        int i, j, p, q, nz = 0, n, m, Ap[], Ai[], w[];
        float Ax[];
        if (!Scs_util.CS_CSC(A))
            return (false);
        /* check inputs */
        m = A.m;
        n = A.n;
        Ap = A.p;
        Ai = A.i;
        Ax = A.x;
        w = new int[m]; /* get workspace */
        for (i = 0; i < m; i++)
            w[i] = -1; /* row i not yet seen */
        for (j = 0; j < n; j++) {
            q = nz; /* column j will start at q */
            for (p = Ap[j]; p < Ap[j + 1]; p++) {
                i = Ai[p]; /* A(i,j) is nonzero */
                if (w[i] >= q) {
                    Ax[w[i]] += Ax[p]; /* A(i,j) is a duplicate */
                } else {
                    w[i] = nz; /* record where row i occurs */
                    Ai[nz] = i; /* keep A(i,j) */
                    Ax[nz++] = Ax[p];
                }
            }
            Ap[j] = q; /* record start of column j */
        }
        Ap[n] = nz; /* finalize A */
        return Scs_util.cs_sprealloc(A, 0); /* remove extra space from A */
    }
1001532
private void resolveColumnReferences() {

        if (isDistinctSelect || isGrouped) {
            acceptsSequences = false;
        }

        for (int i = 0; i < rangeVariables.length; i++) {
            Expression e = rangeVariables[i].nonIndexJoinCondition;

            if (e == null) {
                continue;
            }

            resolveColumnReferencesAndAllocate(e, i + 1, false);
        }

        resolveColumnReferencesAndAllocate(queryCondition,
                                           rangeVariables.length, false);

        for (int i = 0; i < indexLimitVisible; i++) {
            resolveColumnReferencesAndAllocate(exprColumns[i],
                                               rangeVariables.length,
                                               acceptsSequences);
        }

        for (int i = indexLimitVisible; i < indexStartOrderBy; i++) {
            resolveColumnReferencesAndAllocate(exprColumns[i],
                                               rangeVariables.length, false);
        }

    /************************* Volt DB Extensions *************************/
        resolveColumnReferencesInGroupBy();
    /**********************************************************************/

        resolveColumnReferencesInOrderBy(sortAndSlice);
    }
36156
public static <R> ImmutableGrid<R> of(int rowCount, int columnCount) {
        return new EmptyGrid<R>(rowCount, columnCount);
    }
640547
function(column){
			var index = -1;
			var j = 0;
			for(var i=0;i < this.gridCompColumnArr.length;i++){
				if(this.gridCompColumnArr[i] == column){
					if(!($('#' + this.options.id + '_header').find('th').eq(i).css('display') == 'none')){
						index = j;
					}
					break;
				}
				if(!($('#' + this.options.id + '_header').find('th').eq(i).css('display') == 'none')){
					j++;
				}
			}
			return index;
		}
786778
@Override
    public void resolveColumnIndexes()
    {
        // First, assert that our topology is sane and then
        // recursively resolve all child/inline column indexes
        IndexScanPlanNode index_scan =
            (IndexScanPlanNode) getInlinePlanNode(PlanNodeType.INDEXSCAN);
        assert(m_children.size() == 2 && index_scan == null);
        for (AbstractPlanNode child : m_children) {
            child.resolveColumnIndexes();
        }

        final NodeSchema outer_schema = m_children.get(0).getOutputSchema();
        final NodeSchema inner_schema = m_children.get(1).getOutputSchema();
        final int outerSize = outer_schema.size();
        final int innerSize = inner_schema.size();

        // resolve predicates
        resolvePredicate(m_preJoinPredicate, outer_schema, inner_schema);
        resolvePredicate(m_joinPredicate, outer_schema, inner_schema);
        resolvePredicate(m_wherePredicate, outer_schema, inner_schema);

        // Resolve subquery expression indexes
        resolveSubqueryColumnIndexes();

        // Resolve TVE indexes for each schema column.
        for (int i = 0; i < m_outputSchemaPreInlineAgg.size(); ++i) {
            SchemaColumn col = m_outputSchemaPreInlineAgg.getColumn(i);

            // These will all be TVEs.
            assert(col.getExpression() instanceof TupleValueExpression);
            TupleValueExpression tve = (TupleValueExpression)col.getExpression();
            int index;
            if (i < outerSize) {
                index = tve.setColumnIndexUsingSchema(outer_schema);
            }
            else {
                index = tve.setColumnIndexUsingSchema(inner_schema);
                index += outerSize;
            }

            if (index == -1) {
                throw new RuntimeException("Unable to find index for column: " +
                                               col.toString());
            }

            tve.setColumnIndex(index);
            tve.setDifferentiator(index);
        }

        // We want the output columns to be ordered like [outer table columns][inner table columns],
        // and further ordered by TVE index within the left- and righthand sides.
        // generateOutputSchema already places outer columns on the left and inner on the right,
        // so we just need to order the left- and righthand sides by TVE index separately.
        m_outputSchemaPreInlineAgg.sortByTveIndex(0, outer_schema.size());
        m_outputSchemaPreInlineAgg.sortByTveIndex(outer_schema.size(), m_outputSchemaPreInlineAgg.size());
        m_hasSignificantOutputSchema = true;

        resolveRealOutputSchema();
    }
1168870
@Override
    public Matrix<T> repelem(final int rowRepeats, final int colRepeats) {
        N.checkArgument(rowRepeats > 0 && colRepeats > 0, "rowRepeats=%s and colRepeats=%s must be bigger than 0", rowRepeats, colRepeats);

        final T[][] c = N.newArray(arrayType, rows * rowRepeats);

        for (int i = 0, len = c.length; i < len; i++) {
            c[i] = N.newArray(componentType, cols * colRepeats);
        }

        for (int i = 0; i < rows; i++) {
            final T[] fr = c[i * rowRepeats];

            for (int j = 0; j < cols; j++) {
                N.copy(Array.repeat(a[i][j], colRepeats), 0, fr, j * colRepeats, colRepeats);
            }

            for (int k = 1; k < rowRepeats; k++) {
                N.copy(fr, 0, c[i * rowRepeats + k], 0, fr.length);
            }
        }

        return new Matrix<T>(c);
    }
134948
public function groupByColumns()
	{
		$data = $this->dataProvider->getData();
		if (count($data) == 0) {
			return;
		}

		if (!is_array($this->mergeColumns)) {
			$this->mergeColumns = array($this->mergeColumns);
		}
		if (!is_array($this->extraRowColumns)) {
			$this->extraRowColumns = array($this->extraRowColumns);
		}

		//store columns for group. Set object for existing columns in grid and string for attributes
		$groupColumns = array_unique(array_merge($this->mergeColumns, $this->extraRowColumns));
		foreach ($groupColumns as $key => $colName) {
			foreach ($this->columns as $column) {
				if (property_exists($column, 'name') && $column->name == $colName) {
					$groupColumns[$key] = $column;
					break;
				}
			}
		}


		//values for first row
		$lastStored = $this->getRowValues($groupColumns, $data[0], 0);
		foreach ($lastStored as $colName => $value) {
			$lastStored[$colName] = array(
				'value' => $value,
				'count' => 1,
				'index' => 0,
			);
		}

		//iterate data
		$rowcount = count($data);
		for ($i = 1; $i < $rowcount; $i++) {
			//save row values in array
			$current = $this->getRowValues($groupColumns, $data[$i], $i);

			//define is change occured. Need this extra foreach for correctly proceed extraRows
			$changedColumns = array();
			foreach ($current as $colName => $curValue) {
				if ($curValue != $lastStored[$colName]['value']) {
					$changedColumns[] = $colName;
				}
			}

			/**
			 * if this flag = true -> we will write change (to $this->_changes) for all grouping columns.
			 * It's required when change of any column from extraRowColumns occurs
			 */
			$saveChangeForAllColumns = (count(array_intersect($changedColumns, $this->extraRowColumns)) > 0);

			/**
			 * this changeOccurred related to foreach below. It is required only for mergeType == self::MERGE_NESTED,
			 * to write change for all nested columns when change of previous column occurred
			 */
			$changeOccurred = false;
			foreach ($current as $colName => $curValue) {
				//value changed
				$valueChanged = ($curValue != $lastStored[$colName]['value']);
				//change already occured in this loop and mergeType set to MERGETYPE_NESTED
				$saveChange = $valueChanged || ($changeOccurred && $this->mergeType == self::MERGE_NESTED);

				if ($saveChangeForAllColumns || $saveChange) {
					$changeOccurred = true;

					//store in class var
					$prevIndex = $lastStored[$colName]['index'];
					$this->_changes[$prevIndex]['columns'][$colName] = $lastStored[$colName];
					if (!isset($this->_changes[$prevIndex]['count'])) {
						$this->_changes[$prevIndex]['count'] = $lastStored[$colName]['count'];
					}

					//update lastStored for particular column
					$lastStored[$colName] = array(
						'value' => $curValue,
						'count' => 1,
						'index' => $i,
					);

				} else {
					$lastStored[$colName]['count']++;
				}
			}
		}

		//storing for last row
		foreach ($lastStored as $colName => $v) {
			$prevIndex = $v['index'];
			$this->_changes[$prevIndex]['columns'][$colName] = $v;

			if (!isset($this->_changes[$prevIndex]['count'])) {
				$this->_changes[$prevIndex]['count'] = $v['count'];
			}
		}
	}
105976
ImmutableCell<V> validateCounts(int rowCount, int columnCount) {
        if (row >= rowCount || column >= columnCount) {
            throw new IndexOutOfBoundsException("Invalid row-column: " + row + "," + column + " for grid " + rowCount + "x" + columnCount);
        }
        return this;
    }
1072689
public <K> DedicatedMultiRowUniquenessConstraint<C> withRow(ColumnFamily<K, C> columnFamily, K rowKey) {
        locks.add(new Row<K>(columnFamily, rowKey));
        return this;
    }
620175
protected void processGrid( int cols, int rows, boolean ignoreBorder, Calculator calculator ) throws Exception {
        ExecutionPlanner planner = createDefaultPlanner();
        planner.setNumberOfTasks(rows * cols);

        int startC = 0;
        int startR = 0;
        int endC = cols;
        int endR = rows;
        if (ignoreBorder) {
            startC = 1;
            startR = 1;
            endC = cols - 1;
            endR = rows - 1;
        }
        for( int r = startR; r < endR; r++ ) {
            for( int c = startC; c < endC; c++ ) {
                int _c = c, _r = r;
                planner.submit(() -> {
                    if (!pm.isCanceled()) {
                        calculator.calculate(_c, _r);
                    }
                });
            }
        }
        planner.join();
    }
914015
@Override
    public StringColumn unique() {
        List<String> strings = new ArrayList<>(lookupTable.asSet());
        return StringColumn.create(name() + " Unique values", strings);
    }
655685
private static void checkDuplicates(ImmutableList<SQLPPTriplesMap> mappings)
            throws DuplicateMappingException {

        Set<SQLPPTriplesMap> mappingSet = new HashSet<>(mappings);

        int duplicateCount = mappings.size() - mappingSet.size();

        /**
         * If there are some triplesMaps, finds them
         */
        if (duplicateCount > 0) {
            Set<String> duplicateIds = new HashSet<>();
            int remaining = duplicateCount;
            for (SQLPPTriplesMap mapping : mappings) {
                if (mappingSet.contains(mapping)) {
                    mappingSet.remove(mapping);
                }
                /**
                 * Duplicate
                 */
                else {
                    duplicateIds.add(mapping.getId());
                    if (--remaining == 0)
                        break;
                }
            }
            //TODO: indicate the source
            throw new DuplicateMappingException(String.format("Found %d duplicates in the following ids: %s",
                    duplicateCount, duplicateIds.toString()));
        }
    }
595651
public void consistencyCheck() {
        for (int iRow = 0; iRow < 9; iRow++) {
            for (int iCol = 0; iCol < 9; iCol++) {
                Cell cell = cells[iRow][iCol];
                Integer value = cell.getValue();
                if (value != null) {
                    if (! cell.getFree().isEmpty()) {
                        throw new IllegalStateException("free not empty");
                    }
                    // any containing group
                    for (Cell other: cell.getExCells()) {
                        // must not occur in any of the other cells
                        if (value.equals(other.getValue())) {
                            throw new IllegalStateException("duplicate");
                        }
                        // must not occur in the permissibles of any of the other cells
                        if (other.getFree().contains(value)) {
                            throw new IllegalStateException("not eliminated");
                        }
                    }
                }
            }
        }
        
        for (int i = 0; i < rows.length; i++) {
            Set<Integer> aSet = new HashSet<Integer>();
            for (int j = 0; j < rows[i].getCells().size(); j++) {
                Cell cell = rows[i].getCells().get(j);
                Integer value = cell.getValue();
                if (value != null) {
                    aSet.add(value);
                } else {
                    aSet.addAll(cell.getFree());
                }
            }
            if (! aSet.equals(CellGroup.ALL_NINE)) {
                throw new IllegalStateException("deficit in row");
            }
        }
        
        for (int i = 0; i < cols.length; i++) {
            Set<Integer> aSet = new HashSet<Integer>();
            for (int j = 0; j < cols[i].getCells().size(); j++) {
                Cell cell = cols[i].getCells().get(j);
                Integer value = cell.getValue();
                if (value != null) {
                    aSet.add(value);
                } else {
                    aSet.addAll(cell.getFree());
                }
            }
            if (! aSet.equals(CellGroup.ALL_NINE)) {
                throw new IllegalStateException("deficit in column");
            }
        }

        for (int ir = 0; ir < sqrs.length; ir++) {
            for (int ic = 0; ic < sqrs[ir] .length; ic++) {
                Set<Integer> aSet = new HashSet<Integer>();
                for (int j = 0; j < sqrs[ir][ic].getCells().size(); j++) {
                    Cell cell = sqrs[ir][ic].getCells().get(j);
                    Integer value = cell.getValue();
                    if (value != null) {
                        aSet.add(value);
                    } else {
                        aSet.addAll(cell.getFree());
                    }
                }
                if (! aSet.equals(CellGroup.ALL_NINE)) {
                    throw new IllegalStateException("deficit in square");
                }
            }
        }
        System.out.println("+++ check OK +++");
    }
313090
void resolveColumnReferencesInGroupBy() {
        if (unresolvedExpressions == null || unresolvedExpressions.isEmpty()) {
            return;
        }

        /**
         * Hsql HashSet does not work properly to remove duplicates, I doubt the hash
         * function or equal function on expression work properly or something else
         * is wrong. So use list
         *
         */
        // resolve GROUP BY columns/expressions
        HsqlList newUnresolvedExpressions = new ArrayListIdentity();

        int size = unresolvedExpressions.size();
        for (int i = 0; i < size; i++) {
            Object obj = unresolvedExpressions.get(i);
            newUnresolvedExpressions.add(obj);
            if (i + 1 < size && obj == unresolvedExpressions.get(i+1)) {
                // unresolvedExpressions is a public member that can be accessed from anywhere and
                // I (xin) am 90% percent sure about the hsql adds the unresolved expression twice
                // together for our targeted GROUP BY alias case.
                // so we want to skip the repeated expression also.
                // For other unresolved expression, it may differs.
                i += 1;
            }
            if (obj instanceof ExpressionColumn == false) {
                continue;
            }
            ExpressionColumn element = (ExpressionColumn) obj;
            if (element.tableName != null) {
                // this alias does not belong to any table
                continue;
            }

            // group by alias which is thought as an column
            if (element.getType() != OpTypes.COLUMN) {
                continue;
            }

            // find the unsolved expression in the groupBy list
            int k = indexLimitVisible;
            int endGroupbyIndex = indexLimitVisible + groupByColumnCount;
            for (; k < endGroupbyIndex; k++) {
                if (element == exprColumns[k]) {
                    break;
                }
            }
            if (k == endGroupbyIndex) {
                // not found in selected list
                continue;
            }
            assert(exprColumns[k].getType() == OpTypes.COLUMN);

            ExpressionColumn exprCol = (ExpressionColumn) exprColumns[k];
            String alias = exprCol.getColumnName();
            if (alias == null) {
                // we should not handle this case (group by constants)
                continue;
            }

            // Find it in the SELECT list.  We need to look at all
            // the select list elements to see if there are more
            // than one.
            int matchcount = 0;
            for (int j = 0; j < indexLimitVisible; j++) {
                Expression selectCol = exprColumns[j];
                if (selectCol.alias == null) {
                    // columns referenced by their alias must have an alias
                    continue;
                }
                if (alias.equals(selectCol.alias.name)) {
                    matchcount += 1;
                    // This may be an alias to an aggregate
                    // column.  But we'll find that later, so
                    // don't check for it here.
                    exprColumns[k] = selectCol;
                    exprColumnList.set(k, selectCol);
                    if (matchcount == 1) {
                        newUnresolvedExpressions.remove(element);
                    }
                }
            }
            if (matchcount > 1) {
                throw new HsqlException(String.format("Group by expression \"%s\" is ambiguous", alias), "", 0);
            }
        }
        unresolvedExpressions = newUnresolvedExpressions;
    }
1221253
function getNextVisibleInidexOfColumn(column) {
    var index = -1,
        flag = false,
        j = 0;
    for (var i = 0; i < this.gridCompColumnArr.length; i++) {
        if (this.gridCompColumnArr[i] == column) {
            if (!($('#' + this.options.id + '_header').find('th').eq(i).css('display') == 'none')) {

                j++;
            }
            flag = true;
        }
        if (flag == true && !($('#' + this.options.id + '_header').find('th').eq(i).css('display') == 'none')) {
            index = j;
            break;
        }
        if (!($('#' + this.options.id + '_header').find('th').eq(i).css('display') == 'none')) {

            j++;
        }
    }
    return index;
}