Skip to content
Open
Changes from all commits
Commits
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
26 changes: 16 additions & 10 deletions packages/engine-formula/src/basics/inverted-index-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ export class InvertedIndexCache {
}
}

// Because the inverted index cache is used for compare operation, it should be case-insensitive.
let _value = typeof value === 'string' ? value.toLowerCase() : value;
if (_value === '' || _value === null) {
_value = DEFAULT_EMPTY_CELL_KEY;
}
const _value = this.getValueKey(value);

let cellList = columnMap.get(_value);
if (cellList == null) {
Expand All @@ -85,16 +81,26 @@ export class InvertedIndexCache {
cellList.add(row);
}

getCellValuePositions(unitId: string, sheetId: string, column: number) {
return this._cache.get(unitId)?.get(sheetId)?.get(column);
}

getCellPositions(unitId: string, sheetId: string, column: number, value: string | number | boolean | null | symbol, rowsInCache: NumericTuple[]) {
private getValueKey(value: string | number | boolean | null | symbol) {
// Because the inverted index cache is used for compare operation, it should be case-insensitive.
let _value = typeof value === 'string' ? value.toLowerCase() : value;
if (_value === '' || _value === null) {
_value = DEFAULT_EMPTY_CELL_KEY;
}

// Ignore the NUMBER and STRING,such as 2025 and "2025"
if (typeof _value === 'number') {
_value = String(_value);
}
return _value;
}

getCellValuePositions(unitId: string, sheetId: string, column: number) {
return this._cache.get(unitId)?.get(sheetId)?.get(column);
}

getCellPositions(unitId: string, sheetId: string, column: number, value: string | number | boolean | null | symbol, rowsInCache: NumericTuple[]) {
const _value = this.getValueKey(value);
const rows = this._cache.get(unitId)?.get(sheetId)?.get(column)?.get(_value);
return rows && [...rows].filter((row) => rowsInCache.some(([start, end]) => row >= start && row <= end));
}
Expand Down
Loading