Skip to content
Merged
Show file tree
Hide file tree
Changes from 108 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
a6da8a9
redoing ops
izulin Mar 20, 2021
91b686c
matrix size
izulin Mar 20, 2021
3ff2031
unary minus
izulin Mar 20, 2021
697bb9d
renaming
izulin Mar 20, 2021
7b5dd07
binary wrapper
izulin Mar 20, 2021
1e92dd2
binary ops refactor
izulin Mar 20, 2021
1245175
bugfix
izulin Mar 20, 2021
b0d9a81
refactor for binary ops
izulin Mar 20, 2021
d57afaf
index
izulin Mar 20, 2021
8617f6b
index test
izulin Mar 21, 2021
4119f5a
binsearch fix
izulin Mar 21, 2021
456f088
refactor of searching
izulin Mar 22, 2021
559833a
.
izulin Mar 22, 2021
d78c0d8
fancy test
izulin Mar 22, 2021
4956d04
speedups
izulin Mar 24, 2021
6b9b875
fix for extracting addresses
izulin Mar 25, 2021
f25d915
no hacks
izulin Mar 25, 2021
7455363
linter
izulin Mar 25, 2021
1bbf34e
bugfix
izulin Mar 25, 2021
1ffebff
small fix
izulin Mar 25, 2021
c8916a4
jest
izulin Mar 27, 2021
8016acf
Merge branch 'develop' into pu/arrays
izulin Apr 9, 2021
741726a
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 9, 2021
8684bd5
refactor
izulin Apr 11, 2021
f557159
refactor of plugins to incorporate typecheck
izulin Apr 11, 2021
a6d29b5
arrayformula implementation + tests
izulin Apr 11, 2021
6144867
docs
izulin Apr 11, 2021
5e9206e
Update jest.config.js
izulin Apr 12, 2021
16e468c
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
b8f0b3d
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
5ebb0e2
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
7057d27
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
22a9333
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
b4e4d2a
Update src/interpreter/Interpreter.ts
izulin Apr 12, 2021
fc184da
linter
izulin Apr 12, 2021
978d729
doc
izulin Apr 13, 2021
08c2a4f
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 13, 2021
e10a54e
doc
izulin Apr 13, 2021
a872106
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 13, 2021
4eeac48
doc
izulin Apr 13, 2021
ae7a64c
Merge branch 'develop' into pu/arrays
izulin Apr 14, 2021
e4c0808
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 14, 2021
8ee1f08
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 14, 2021
a0f8a29
Merge branch 'develop' into pu/arrays
izulin Apr 14, 2021
56a01a7
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 14, 2021
9e19d3c
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 14, 2021
c1156a6
removing support for Matrix Formulas
izulin Apr 19, 2021
60e4f72
almost there
izulin Apr 19, 2021
989562e
Merge branch 'develop' into pu/arrays
izulin Apr 19, 2021
b6efef9
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 19, 2021
e5a4fd2
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 19, 2021
edb82bd
doc
izulin Apr 19, 2021
8157b77
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 19, 2021
7313bf9
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 19, 2021
028c650
Remove references to not existing exception
voodoo11 Apr 21, 2021
2289129
Merge branch 'develop' into pu/oldmatrixnotation
izulin Apr 22, 2021
5dbe491
fixes
izulin Apr 23, 2021
9cab32d
Fix set matrix
voodoo11 Apr 24, 2021
efc5498
Use existing assert
voodoo11 Apr 24, 2021
88ab4ee
Unnecessary public function
voodoo11 Apr 24, 2021
f9f7a6a
tests working
izulin Apr 24, 2021
e19d9db
linter
izulin Apr 24, 2021
920074f
tests fixed
izulin Apr 24, 2021
2008e01
.
izulin Apr 25, 2021
58820f3
Merge branch 'develop' into pu/oldmatrixnotation
izulin Apr 26, 2021
9138f9e
Merge branch 'pu/arrays' into pu/oldmatrix+arrays
izulin Apr 26, 2021
a1652f5
Merge branch 'develop' into pu/arrays
izulin Apr 26, 2021
9c25116
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 26, 2021
6549535
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 26, 2021
e9cfbb0
Merge branch 'pu/oldmatrixnotation' into pu/oldmatrix+arrays
izulin Apr 26, 2021
067e6cd
Merge branch 'pu/arraysbenchmark' into pu/oldmatrix+arrays
izulin Apr 26, 2021
ba55049
Merge branch 'pu/arrays2' into pu/oldmatrix+arrays
izulin Apr 26, 2021
b5a2ed9
doc
izulin Apr 26, 2021
9398e15
Merge branch 'pu/oldmatrixnotation' into pu/oldmatrix+arrays
izulin Apr 26, 2021
21ad7fb
refactor
izulin Apr 26, 2021
64d149b
refactor
izulin Apr 27, 2021
a283857
tests
izulin Apr 27, 2021
16a3e83
cleanup
izulin Apr 27, 2021
3a17e89
linter
izulin Apr 27, 2021
952d6bd
Merge branch 'develop' into pu/arrays
izulin Apr 27, 2021
22d2359
Merge branch 'pu/arrays' into pu/arrays2
izulin Apr 27, 2021
ece605d
Merge branch 'pu/arrays' into pu/arraysbenchmark
izulin Apr 27, 2021
2b4e365
Merge branch 'develop' into pu/oldmatrixnotation
izulin Apr 27, 2021
38926b1
doc
izulin Apr 27, 2021
e2716ec
Merge branch 'pu/oldmatrixnotation' into pu/oldmatrix+arrays
izulin Apr 27, 2021
5e7b9f2
Merge branch 'pu/arrays2' into pu/oldmatrix+arrays
izulin Apr 27, 2021
57be2db
Merge branch 'pu/arraysbenchmark' into pu/oldmatrix+arrays
izulin Apr 27, 2021
95d9596
typing
izulin Apr 28, 2021
6a07bf1
Merge branch 'develop' into pu/mergeall
izulin Apr 28, 2021
b2c5082
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin Apr 28, 2021
a68abf9
Update src/CrudOperations.ts
izulin Apr 28, 2021
9996e2f
Update docs/guide/custom-functions.md
izulin Apr 28, 2021
1f88029
Update docs/guide/custom-functions.md
izulin Apr 28, 2021
c8794b6
Update docs/guide/custom-functions.md
izulin Apr 28, 2021
5355211
minor
izulin Apr 28, 2021
e252eca
more refactors
izulin Apr 28, 2021
977b065
refactor
izulin Apr 29, 2021
0363767
another refactor
izulin Apr 29, 2021
05a0e61
refactor
izulin Apr 29, 2021
0b22fcc
.
izulin Apr 29, 2021
c0577e0
more refactoring of matrixsize
izulin Apr 30, 2021
1f7d48d
tests
izulin Apr 30, 2021
25f2fe5
linter
izulin Apr 30, 2021
429917f
array_constraint function added
izulin May 3, 2021
2ba057a
doc
izulin May 3, 2021
5aa2885
linter
izulin May 3, 2021
89d7ce4
typo
izulin May 3, 2021
ee4fe5c
doc typo
izulin May 3, 2021
7effe9d
unnecessary error message
izulin May 5, 2021
9c13e18
Update src/interpreter/SimpleRangeValue.ts
izulin May 11, 2021
72a8600
Update src/interpreter/SimpleRangeValue.ts
izulin May 11, 2021
3918f04
doc
izulin May 12, 2021
cea2d2e
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin May 12, 2021
ae37770
Merge branch 'pu/mergeall+refactor' into pu/arrayconstraint
izulin May 12, 2021
fd05864
doc
izulin May 12, 2021
89cd12f
doc
izulin May 12, 2021
e5a19e8
Update src/Lookup/RowSearchStrategy.ts
izulin May 14, 2021
c5e40f4
refactor
izulin May 14, 2021
3842609
rename
izulin May 14, 2021
2e2ea6f
doc
izulin May 14, 2021
c0bc246
sorted
izulin May 14, 2021
746d36e
alphabetic
izulin May 14, 2021
4c2851a
Merge branch 'develop' into pu/mergeall
izulin May 14, 2021
1e5a680
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin May 14, 2021
3a7c2c5
.
izulin May 14, 2021
7e3d1d5
..
izulin May 14, 2021
c1bd84b
Merge branch 'pu/mergeall' into pu/mergeall+refactor
izulin May 14, 2021
9a5495b
.
izulin May 14, 2021
8761ae5
fix
izulin May 14, 2021
512234e
Merge branch 'develop' into pu/mergeall+refactor
izulin May 14, 2021
680b01d
Apply suggestions from code review
izulin May 14, 2021
166eb2c
cleanup
izulin May 14, 2021
fb0215d
Merge branch 'pu/mergeall+refactor' into pu/arrayconstraint
izulin May 14, 2021
7a44a56
Merge branch 'develop' into pu/arrayconstraint
izulin May 14, 2021
e70ce91
Merge branch 'develop' into pu/arrayconstraint
izulin May 14, 2021
7b65a92
minor
izulin May 14, 2021
2588eb3
Merge branch 'develop' into pu/arrayconstraint
izulin May 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- **Breaking change**: Removed support for matrix formulas (`{=FORMULA}`) notation. Engine now supports formulas returning array of values (instead of only scalars). (#652)

### Added
- Added support for array arithmetic. (#628)
- Added performance improvements for array handling. (#629)
- Added ARRAYFORMULA function. (#630)
- Added ARRAY_CONSTRAIN function. (#661)

### Fixed
- Fixed an issue with arrays and cruds. (#651)

## [0.6.0] - 2021-04-27

### Changed
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/cell-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@ or example:
* When the VLOOKUP is told to look up values in a column whose
index is out of the scope.
* When the INDEX function is told to return values from rows or
columns that are out of the scope.
columns that are out of the scope.
6 changes: 3 additions & 3 deletions docs/guide/custom-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ export const myTranslations = {
For the simplicity of a basic example, you will not pass any
arguments. However, this method imposes a particular structure to
be used; there are two optional arguments, `ast` and
`formulaAddress`, and the function must return the results of
`state`, and the function must return the results of
the calculations.

```javascript
// arguments here are displayed just to show the structure
public hyper(ast, formulaAddress) {
public hyper(ast, state) {
return 'Hyperformula'.length;
}
};
Expand All @@ -152,7 +152,7 @@ export class CountHF extends FunctionPlugin {
}
};

public hyper(ast, formulaAddress) {
public hyper(ast, state) {
return 'Hyperformula'.length
}
};
Expand Down
28 changes: 28 additions & 0 deletions src/AbsoluteCellRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {CellRange, simpleCellAddress, SimpleCellAddress, SimpleColumnAddress, SimpleRowAddress} from './Cell'
import {DependencyGraph} from './DependencyGraph'
import {Maybe} from './Maybe'
import {AstNodeType, CellAddress, CellRangeAst} from './parser'
import {ColumnRangeAst, RowRangeAst} from './parser/Ast'
import {RowsSpan, Span} from './Span'
Expand Down Expand Up @@ -37,6 +38,17 @@ export class AbsoluteCellRange {
)
}

public static fromCellRangeOrUndef(x: CellRange, baseAddress: SimpleCellAddress): Maybe<AbsoluteCellRange> {
try {
return new AbsoluteCellRange(
new CellAddress(x.start.sheet, x.start.col, x.start.row, x.start.type).toSimpleCellAddress(baseAddress),
new CellAddress(x.end.sheet, x.end.col, x.end.row, x.end.type).toSimpleCellAddress(baseAddress),
)
} catch (e) {
return undefined
}
}

public static spanFrom(topLeftCorner: SimpleCellAddress, width: number, height: number): AbsoluteCellRange {
if (!Number.isFinite(width) && Number.isFinite(height)) {
return new AbsoluteRowRange(topLeftCorner.sheet, topLeftCorner.row, topLeftCorner.row + height - 1)
Expand Down Expand Up @@ -262,6 +274,22 @@ export class AbsoluteCellRange {
return this.width() === other.width() && this.height() === other.height()
}

public addressesArrayMap<T>(dependencyGraph: DependencyGraph, op: (arg: SimpleCellAddress) => T): T[][] {
const ret = []
let currentRow = this.start.row
while (currentRow <= this.effectiveEndRow(dependencyGraph)) {
let currentColumn = this.start.col
const tmp = []
while (currentColumn <= this.effectiveEndColumn(dependencyGraph)) {
tmp.push(op(simpleCellAddress(this.start.sheet, currentColumn, currentRow)))
currentColumn++
}
ret.push(tmp)
currentRow++
}
return ret
}

public* addresses(dependencyGraph: DependencyGraph): IterableIterator<SimpleCellAddress> {
let currentRow = this.start.row
while (currentRow <= this.effectiveEndRow(dependencyGraph)) {
Expand Down
6 changes: 4 additions & 2 deletions src/BuildEngineFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {DependencyGraph} from './DependencyGraph'
import {Evaluator} from './Evaluator'
import {GraphBuilder} from './GraphBuilder'
import {UIElement} from './i18n'
import {MatrixSizePredictor} from './MatrixSize'
import {NamedExpressions} from './NamedExpressions'
import {NumberLiteralHelper} from './NumberLiteralHelper'
import {buildLexerConfig, ParserWithCaching, Unparser} from './parser'
Expand Down Expand Up @@ -71,9 +72,10 @@ export class BuildEngineFactory {
const numberLiteralHelper = new NumberLiteralHelper(config)
const cellContentParser = new CellContentParser(config, dateHelper, numberLiteralHelper)

const crudOperations = new CrudOperations(config, stats, dependencyGraph, columnSearch, parser, cellContentParser, lazilyTransformingAstService, namedExpressions)
const matrixSizePredictor = new MatrixSizePredictor(config, functionRegistry)
const crudOperations = new CrudOperations(config, stats, dependencyGraph, columnSearch, parser, cellContentParser, lazilyTransformingAstService, namedExpressions, matrixSizePredictor)
stats.measure(StatType.GRAPH_BUILD, () => {
const graphBuilder = new GraphBuilder(dependencyGraph, columnSearch, parser, cellContentParser, config, stats)
const graphBuilder = new GraphBuilder(dependencyGraph, columnSearch, parser, cellContentParser, config, stats, matrixSizePredictor)
graphBuilder.buildGraph(sheets)
})

Expand Down
20 changes: 1 addition & 19 deletions src/CellContentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ export namespace CellContent {
}
}

export class MatrixFormula {
constructor(public readonly formula: string) {
}

public formulaWithBraces(): string {
return '{' + this.formula + '}'
}
}

export class Error {
public readonly value: CellError

Expand All @@ -72,7 +63,7 @@ export namespace CellContent {
}
}

export type Type = Number | String | Boolean | Empty | Formula | MatrixFormula | Error
export type Type = Number | String | Boolean | Empty | Formula | Error
}

/**
Expand All @@ -89,13 +80,6 @@ export function isBoolean(text: string): boolean {
return tl === 'true' || tl === 'false'
}

export function isMatrix(text: RawCellContent): boolean {
if (typeof text !== 'string') {
return false
}
return (text.length > 1) && (text.startsWith('{')) && (text.endsWith('}'))
}

export function isError(text: string, errorMapping: Record<string, ErrorType>): boolean {
const upperCased = text.toUpperCase()
const errorRegex = /#[A-Za-z0-9\/]+[?!]?/
Expand Down Expand Up @@ -142,8 +126,6 @@ export class CellContentParser {
} else if (typeof content === 'string') {
if (isBoolean(content)) {
return new CellContent.Boolean(content.toLowerCase() === 'true')
} else if (isMatrix(content)) {
return new CellContent.MatrixFormula(content.substr(1, content.length - 2))
} else if (isFormula(content)) {
return new CellContent.Formula(content)
} else if (isError(content, this.config.errorMapping)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type GPUMode = 'gpu' | 'cpu' | 'dev'
const PossibleGPUModeString: GPUMode[] = ['gpu', 'cpu', 'dev']

export interface ConfigParams {
arrays: boolean, //FIXME
/**
* Specifies if the string comparison is accent sensitive or not.
* Applies to comparison operators only.
Expand Down Expand Up @@ -380,6 +381,7 @@ type ConfigParamsList = keyof ConfigParams
export class Config implements ConfigParams, ParserConfig {

public static defaultConfig: ConfigParams = {
arrays: false,
accentSensitive: false,
caseSensitive: false,
caseFirst: 'lower',
Expand Down Expand Up @@ -420,6 +422,7 @@ export class Config implements ConfigParams, ParserConfig {
currencySymbol: ['$'],
}

public readonly arrays: boolean
/** @inheritDoc */
public readonly caseSensitive: boolean
/** @inheritDoc */
Expand Down Expand Up @@ -524,6 +527,7 @@ export class Config implements ConfigParams, ParserConfig {

constructor(
{
arrays,
accentSensitive,
caseSensitive,
caseFirst,
Expand Down Expand Up @@ -564,6 +568,7 @@ export class Config implements ConfigParams, ParserConfig {
currencySymbol,
}: Partial<ConfigParams> = {},
) {
this.arrays = this.valueFromParam(arrays, 'boolean', 'arrays')
this.accentSensitive = this.valueFromParam(accentSensitive, 'boolean', 'accentSensitive')
this.caseSensitive = this.valueFromParam(caseSensitive, 'boolean', 'caseSensitive')
this.caseFirst = this.valueFromParam(caseFirst, ['upper', 'lower', 'false'], 'caseFirst')
Expand Down
20 changes: 7 additions & 13 deletions src/CrudOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import {AbsoluteCellRange} from './AbsoluteCellRange'
import {invalidSimpleCellAddress, simpleCellAddress, SimpleCellAddress} from './Cell'
import {CellContent, CellContentParser, isMatrix, RawCellContent} from './CellContentParser'
import {CellContent, CellContentParser, RawCellContent} from './CellContentParser'
import {ClipboardCell, ClipboardOperations} from './ClipboardOperations'
import {MatrixSizePredictor} from './MatrixSize'
import {AddColumnsCommand, AddRowsCommand, Operations, RemoveColumnsCommand, RemoveRowsCommand} from './Operations'
import {ColumnSearchStrategy} from './Lookup/SearchStrategy'
import {Config} from './Config'
Expand All @@ -21,7 +22,6 @@ import {
import {
InvalidAddressError,
InvalidArgumentsError,
MatrixFormulasNotSupportedError,
NamedExpressionDoesNotExistError,
NamedExpressionNameIsAlreadyTakenError,
NamedExpressionNameIsInvalidError,
Expand Down Expand Up @@ -88,10 +88,11 @@ export class CrudOperations {
private readonly lazilyTransformingAstService: LazilyTransformingAstService,
/** Storage for named expressions */
private readonly namedExpressions: NamedExpressions,
private readonly matrixSizePredictor: MatrixSizePredictor,
) {
this.operations = new Operations(this.dependencyGraph, this.columnSearch, this.cellContentParser, this.parser, this.stats, this.lazilyTransformingAstService, this.namedExpressions, this.config)
this.clipboardOperations = new ClipboardOperations(this.dependencyGraph, this.operations, this.parser, this.lazilyTransformingAstService, this.config)
this.undoRedo = new UndoRedo(this.config, this.operations)
this.operations = new Operations(dependencyGraph, columnSearch, cellContentParser, parser, stats, lazilyTransformingAstService, namedExpressions, config, matrixSizePredictor)
this.clipboardOperations = new ClipboardOperations(dependencyGraph, this.operations, parser, lazilyTransformingAstService, config)
this.undoRedo = new UndoRedo(config, this.operations)
}

public addRows(sheet: number, ...indexes: ColumnRowIndex[]): void {
Expand Down Expand Up @@ -252,11 +253,6 @@ export class CrudOperations {
if (!(cellContents[i] instanceof Array)) {
throw new InvalidArgumentsError('an array of arrays or a raw cell value.')
}
for (let j = 0; j < cellContents[i].length; j++) {
if (isMatrix(cellContents[i][j])) {
throw new Error('Cant change matrices in batch operation')
}
}
}
}

Expand Down Expand Up @@ -681,9 +677,7 @@ export class CrudOperations {

private ensureNamedExpressionIsValid(expression: RawCellContent): void {
const parsedExpression = this.cellContentParser.parse(expression)
if (parsedExpression instanceof CellContent.MatrixFormula) {
throw new MatrixFormulasNotSupportedError()
} else if (parsedExpression instanceof CellContent.Formula) {
if (parsedExpression instanceof CellContent.Formula) {
const parsingResult = this.parser.parse(parsedExpression.formula, simpleCellAddress(-1, 0, 0))
if (doesContainRelativeReferences(parsingResult.ast)) {
throw new NoRelativeAddressesAllowedError()
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyGraph/AddressMapping/AddressMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import {SimpleCellAddress} from '../../Cell'
import {RawCellContent} from '../../CellContentParser'
import {EmptyValue, InterpreterValue} from '../../interpreter/InterpreterValue'
import {Maybe} from '../../Maybe'
import {ColumnsSpan, RowsSpan} from '../../Span'
import {EmptyCellVertex, MatrixVertex, ValueCellVertex} from '../index'
import {CellVertex} from '../Vertex'
Expand All @@ -28,7 +29,7 @@ export class AddressMapping {
if (!sheetMapping) {
throw new NoSheetWithIdError(address.sheet)
}
return sheetMapping.getCell(address)
return sheetMapping.getCell(address) ?? null
}

public fetchCell(address: SimpleCellAddress): CellVertex {
Expand Down
11 changes: 4 additions & 7 deletions src/DependencyGraph/AddressMapping/DenseStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import {SheetCellAddress, simpleCellAddress, SimpleCellAddress} from '../../Cell'
import {Maybe} from '../../Maybe'
import {ColumnsSpan, RowsSpan} from '../../Span'
import {CellVertex} from '../Vertex'
import {IAddressMappingStrategy} from './IAddressMappingStrategy'
Expand Down Expand Up @@ -33,7 +34,7 @@ export class DenseStrategy implements IAddressMappingStrategy {
}

/** @inheritDoc */
public getCell(address: SheetCellAddress): CellVertex | null {
public getCell(address: SheetCellAddress): Maybe<CellVertex> {
return this.getCellVertex(address.col, address.row)
}

Expand Down Expand Up @@ -190,11 +191,7 @@ export class DenseStrategy implements IAddressMappingStrategy {
}
}

private getCellVertex(x: number, y: number): CellVertex | null {
const row = this.mapping[y]
if (row) {
return this.mapping[y][x] || null
}
return null
private getCellVertex(x: number, y: number): Maybe<CellVertex> {
return this.mapping[y]?.[x]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import {SheetCellAddress, SimpleCellAddress} from '../../Cell'
import {Maybe} from '../../Maybe'
import {ColumnsSpan, RowsSpan} from '../../Span'
import {CellVertex} from '../Vertex'

Expand All @@ -17,7 +18,7 @@ export interface IAddressMappingStrategy {
*
* @param address - cell address
*/
getCell(address: SheetCellAddress): CellVertex | null,
getCell(address: SheetCellAddress): Maybe<CellVertex>,

/**
* Set vertex for given address
Expand Down
9 changes: 3 additions & 6 deletions src/DependencyGraph/AddressMapping/SparseStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import {SheetCellAddress, simpleCellAddress, SimpleCellAddress} from '../../Cell'
import {Maybe} from '../../Maybe'
import {ColumnsSpan, RowsSpan} from '../../Span'
import {CellVertex} from '../Vertex'
import {IAddressMappingStrategy} from './IAddressMappingStrategy'
Expand All @@ -26,12 +27,8 @@ export class SparseStrategy implements IAddressMappingStrategy {
}

/** @inheritDoc */
public getCell(address: SheetCellAddress): CellVertex | null {
const colMapping = this.mapping.get(address.col)
if (!colMapping) {
return null
}
return colMapping.get(address.row) || null
public getCell(address: SheetCellAddress): Maybe<CellVertex> {
return this.mapping.get(address.col)?.get(address.row)
}

/** @inheritDoc */
Expand Down
Loading