public StringBuilder PrintAsTable() { StringBuilder stringBuilder = new StringBuilder(""); for (int i = 0; i < _rowBound; i++) { for (int j = 0; j < _columnBound; j++) { object value; CellKey index = new CellKey() { Row = i, Column = j }; if (_dataTable.TryGetValue(index, out value)) { } stringBuilder.Append($"{value}\t"); } stringBuilder.Append("\n"); } return(stringBuilder); }
public void OnEndCellCalculation(CellKey cellKey, CellValue startValue, CellValue endValue) { // Display cell information, a cell value before calculation and the calculated cell value. string info = String.Format("CellKey: ({0}) Before: {1}, After: {2}", cellKey, startValue, endValue); CreateLogEntry("Cell calculation ends", new string[] { info }); }
void spreadsheetControl1_CustomDrawCell(object sender, DevExpress.XtraSpreadsheet.CustomDrawCellEventArgs e) { CellKey cellkey = new CellKey((e.Cell.Worksheet.Index + 1), e.Cell.ColumnIndex, e.Cell.RowIndex); if (calculationService.CircularReferencedCells.Contains(cellkey)) { e.Graphics.DrawRectangle(new Pen(Color.Red, 1), e.Bounds); } }
// Complete the maxRegion function below. static int maxRegion(int[][] matrix) { var xOffset = new[] { -1, 0, 1, -1 }; var yOffset = new[] { -1, -1, -1, 0 }; var ds = new DisjointSets(); var rows = matrix.Length; var cols = matrix[0].Length; var max = 0; Func <int, int, bool> isValid = (int x, int y) => { return(x >= 0 && x < cols && y >= 0 && y < rows); }; for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { if (matrix[y][x] == 0) { continue; } var current = new CellKey(x, y); ds.AddNew(current); max = Math.Max(max, 1); for (int index = 0; index < xOffset.Length; index++) { var ox = x + xOffset[index]; var oy = y + yOffset[index]; if (!isValid(ox, oy)) { continue; } if (matrix[oy][ox] == 0) { continue; } var offset = new CellKey(ox, oy); if (ds.Find(current) != ds.Find(offset)) { max = Math.Max(max, ds.Union(current, offset)); } } } } return(max); }
public int Union(CellKey left, CellKey right) { var pLeft = Find(left); var pRight = Find(right); Parents[pRight] = pLeft; Counts[pLeft] = Counts[pLeft] + Counts[pRight]; return(Counts[pLeft]); }
public override bool Equals(Object obj) { if (obj == null || !(obj is CellKey)) { return(false); } // assumes other object is one of us, otherwise ClassCastException is thrown CellKey oKey = (CellKey)obj; return(_row == oKey._row && _col == oKey._col); }
public IEvaluationCell GetCell(int rowIndex, int columnIndex) { // cache for performance: ~30% speedup due to caching if (_cellCache == null) { _cellCache = new Dictionary <CellKey, IEvaluationCell>(_xs.LastRowNum * 3); foreach (IRow row in _xs) { int rowNum = row.RowNum; foreach (ICell cell in row) { // cast is safe, the iterator is just defined using the interface CellKey key1 = new CellKey(rowNum, cell.ColumnIndex); IEvaluationCell evalcell1 = new XSSFEvaluationCell((XSSFCell)cell, this); _cellCache.Add(key1, evalcell1); } } } CellKey key = new CellKey(rowIndex, columnIndex); IEvaluationCell evalcell = null; if (_cellCache.ContainsKey(key)) { evalcell = _cellCache[key]; } // If cache is stale, update cache with this one cell // This is a compromise between rebuilding the entire cache // (which would quickly defeat the benefit of the cache) // and not caching at all. // See bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss if (evalcell == null) { XSSFRow row = _xs.GetRow(rowIndex) as XSSFRow; if (row == null) { return(null); } XSSFCell cell = row.GetCell(columnIndex) as XSSFCell; if (cell == null) { return(null); } evalcell = new XSSFEvaluationCell(cell, this); _cellCache[key] = evalcell; } return(evalcell); }
void unboundDS_ValuePushed(object sender, UnboundSourceValuePushedEventArgs e) { var defaultValue = GetDefaultData(e.RowIndex, e.PropertyName); var cellKey = new CellKey(e.RowIndex, e.PropertyName); if (object.Equals(defaultValue, e.Value)) { this.Differences.Remove(cellKey); } else { this.Differences[cellKey] = e.Value; } }
internal void AddCell(int row, int column, SpreadsheetCellModel cell) { var cellKey = new CellKey { Row = row, Column = column }; if (cells.ContainsKey(cellKey)) { cells[cellKey] = cell; } else { cells.Add(cellKey, cell); } }
private void fillCell(CellData data, Dictionary <CellKey, Cell> cellsCache) { int[,] map = getMap(data.CheckPointOffset); TilePos pos = data.Cell.Pos; List <Transition> transitions = new List <Transition>(); foreach (TileDir dir in data.Cell.Dirs) { TilePos iterPos = pos + dir; bool alternative = (!data.Alternative && checkToAlternative(map, pos, iterPos)); bool unknown = checkToUnknown(pos, iterPos, 2); Logger.instance.Assert(0 <= iterPos.X && iterPos.X < gmap.Width && 0 <= iterPos.Y && iterPos.Y < gmap.Height, "WTF?"); if (map[iterPos.X, iterPos.Y] < map[pos.X, pos.Y] || unknown || alternative) { CellKey key = new CellKey(iterPos, data.CheckPointOffset); Cell iterCell = null; if (cellsCache.ContainsKey(key)) { iterCell = cellsCache[key]; } else { iterCell = new Cell(iterPos, gmap.Dirs(iterPos)); } int length = map[iterPos.X, iterPos.Y] - map[pos.X, pos.Y]; if (gmap.Width * gmap.Height != map[iterPos.X, iterPos.Y]) { transitions.Add(new Transition(iterCell, length, checkpointByOffset(data.CheckPointOffset) == iterPos)); hasUnknown |= unknown; } } } data.Cell.setTransitions(transitions); }
public object this[int row, int column] { get { if (row < _rowBound && row >= 0 && column < _columnBound && column >= 0) { var index = new CellKey { Row = row, Column = column }; _dataTable.TryGetValue(index, out var value); return(value); } throw new IndexOutOfRangeException(); } set { if (row < _rowBound && column < _columnBound) { var index = new CellKey { Row = row, Column = column }; //var selectedColumnKeys = _dataTable.Keys // .Where(i => i.Column == column) // .ToArray(); _dataTable[index] = value; var type = DefineColumnType(_dataTable, column); ChangeType(_dataTable, column, type); } else { throw new IndexOutOfRangeException(); } } }
public MockDataFrame(object[][] arr) { RowBound = arr.Length; ColumnBound = 0; _dataTable = new Dictionary <CellKey, object>(); for (int i = 0; i < RowBound; i++) { ColumnBound = arr[i].Length > ColumnBound ? arr[i].Length : ColumnBound; } for (int i = 0; i < RowBound; i++) { for (int j = 0; j < arr[i].Length; j++) { CellKey index = new CellKey() { Row = i, Column = j }; _dataTable.Add(index, arr[i][j]); } } }
private void fillCell(Cell cell, int beginCheckPointOffset, int maxDepth) { Dictionary <CellKey, Cell> cellsCache = new Dictionary <CellKey, Cell>(); cellsCache.Add(new CellKey(cell.Pos, beginCheckPointOffset), cell); Queue <CellData> stack = new Queue <CellData>(); stack.Enqueue(new CellData(cell, beginCheckPointOffset, 0, false)); while (stack.Count > 0) { CellData data = stack.Dequeue(); if (data.Depth >= maxDepth || TileType.Unknown == gmap.Type(data.Cell.Pos)) { continue; } while (data.Cell.Pos == checkpointByOffset(data.CheckPointOffset)) { data.CheckPointOffset++; } fillCell(data, cellsCache); foreach (Transition subData in data.Cell.Transitions) { CellKey key = new CellKey(subData.ToCell.Pos, data.CheckPointOffset); if (!cellsCache.ContainsKey(key)) { stack.Enqueue(new CellData(subData.ToCell, data.CheckPointOffset, data.Depth + 1, subData.Weight > 0)); cellsCache.Add(key, subData.ToCell); } } } }
public DataFrame(object[][] arr) { _dataTable = new Dictionary <CellKey, object>(); _rowBound = arr.Length; _columnBound = 0; for (int i = 0; i < _rowBound; i++) { _columnBound = arr[i].Length > _columnBound ? arr[i].Length : _columnBound; } for (int i = 0; i < _rowBound; i++) { for (int j = 0; j < arr[i].Length; j++) { CellKey index = new CellKey() { Row = i, Column = j }; _dataTable.Add(index, arr[i][j]); var type = DefineColumnType(_dataTable, j); ChangeType(_dataTable, j, type); } } }
public static bool TryGetValue(this ITableCellCache cache, string database, int tableId, int rowNumber, int columnOffset, out DataObject value) { var rowId = new RowId(tableId, rowNumber); var key = new CellKey(database, new CellId(rowId, columnOffset)); return cache.TryGetValue(key, out value); }
public static void Remove(this ITableCellCache cache, string database, int tableId, int rowNumber, int columnOffset) { var rowId = new RowId(tableId, rowNumber); var key = new CellKey(database, new CellId(rowId, columnOffset)); cache.Remove(key); }
internal CachedCell(CellKey key, Field value) { Key = key; Value = value; }
public static void Set(this ITableCellCache cache, string database, int tableId, int rowNumber, int columnOffset, DataObject value) { var rowId = new RowId(tableId, rowNumber); var key = new CellKey(database, new CellId(rowId, columnOffset)); cache.Set(new CachedCell(key, value)); }
internal CachedCell(CellKey key, DataObject value) { Key = key; Value = value; }
public void AddNew(CellKey key) { Parents.Add(key, key); Counts.Add(key, 1); }
public CellKey Find(CellKey value) => Parents[value] == value ? value : Find(Parents[value]);