-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathSearchStrategy.ts
More file actions
69 lines (53 loc) · 2.57 KB
/
SearchStrategy.ts
File metadata and controls
69 lines (53 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @license
* Copyright (c) 2025 Handsoncode. All rights reserved.
*/
import {SimpleCellAddress} from '../Cell'
import {Config} from '../Config'
import {CellValueChange} from '../ContentChanges'
import {DependencyGraph} from '../DependencyGraph'
import {RawInterpreterValue, RawNoErrorScalarValue, RawScalarValue} from '../interpreter/InterpreterValue'
import {SimpleRangeValue} from '../SimpleRangeValue'
import {ColumnsSpan} from '../Span'
import {Statistics} from '../statistics'
import {ColumnBinarySearch} from './ColumnBinarySearch'
import {ColumnIndex} from './ColumnIndex'
export interface SearchOptions {
ordering: 'asc' | 'desc' | 'none',
ifNoMatch: 'returnLowerBound' | 'returnUpperBound' | 'returnNotFound',
returnOccurrence?: 'first' | 'last',
}
export interface AdvancedFindOptions {
returnOccurrence?: 'first' | 'last',
}
export interface SearchStrategy {
/*
* WARNING: Finding lower/upper bounds in unordered ranges is not supported. When ordering === 'none', assumes matchExactly === true
*/
find(searchKey: RawNoErrorScalarValue, range: SimpleRangeValue, options: SearchOptions): number,
advancedFind(keyMatcher: (arg: RawInterpreterValue) => boolean, range: SimpleRangeValue, options: AdvancedFindOptions): number,
}
export interface ColumnSearchStrategy extends SearchStrategy {
add(value: RawInterpreterValue, address: SimpleCellAddress): void,
remove(value: RawInterpreterValue | undefined, address: SimpleCellAddress): void,
change(oldValue: RawInterpreterValue | undefined, newValue: RawInterpreterValue, address: SimpleCellAddress): void,
applyChanges(contentChanges: CellValueChange[]): void,
addColumns(columnsSpan: ColumnsSpan): void,
removeColumns(columnsSpan: ColumnsSpan): void,
removeSheet(sheetId: number): void,
moveValues(range: IterableIterator<[RawScalarValue, SimpleCellAddress]>, toRight: number, toBottom: number, toSheet: number): void,
removeValues(range: IterableIterator<[RawScalarValue, SimpleCellAddress]>): void,
/**
* Forces all lazily-tracked ValueIndex entries to apply any pending transformations,
* bringing every entry's version up to the current LazilyTransformingAstService version.
* Must be called before compacting LazilyTransformingAstService.
*/
forceApplyPostponedTransformations(): void,
}
export function buildColumnSearchStrategy(dependencyGraph: DependencyGraph, config: Config, statistics: Statistics): ColumnSearchStrategy {
if (config.useColumnIndex) {
return new ColumnIndex(dependencyGraph, config, statistics)
} else {
return new ColumnBinarySearch(dependencyGraph)
}
}