Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pu/inftybinsearch #562

Merged
merged 4 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed a problem with dependencies not collected for specific functions. (#550, #549)
- Fixed a minor problem with dependencies under nested parenthesis. (#549, #558)
- Fixed a problem with HLOOKUP/VLOOKUP getting stuck in binary search. (#559, #562)
- Fixed a problem with logic of dependency resolving. (#561, #563)

## [0.3.0] - 2020-10-22
Expand Down
8 changes: 4 additions & 4 deletions src/AbsoluteCellRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ export class AbsoluteCellRange {
return this.end.col >= maxColumns || this.end.row >= maxRows
}

protected effectiveEndColumn(_dependencyGraph: DependencyGraph): number {
public effectiveEndColumn(_dependencyGraph: DependencyGraph): number {
return this.end.col
}

protected effectiveEndRow(_dependencyGraph: DependencyGraph): number {
public effectiveEndRow(_dependencyGraph: DependencyGraph): number {
return this.end.row
}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ export class AbsoluteColumnRange extends AbsoluteCellRange {
return this.end.col >= maxColumns
}

protected effectiveEndRow(dependencyGraph: DependencyGraph): number {
public effectiveEndRow(dependencyGraph: DependencyGraph): number {
return dependencyGraph.getSheetHeight(this.sheet) - 1
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ export class AbsoluteRowRange extends AbsoluteCellRange {
return this.end.row >= maxRows
}

protected effectiveEndColumn(dependencyGraph: DependencyGraph): number {
public effectiveEndColumn(dependencyGraph: DependencyGraph): number {
return dependencyGraph.getSheetWidth(this.sheet) - 1
}
}
7 changes: 6 additions & 1 deletion src/interpreter/binarySearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import {InterpreterValue} from './InterpreterValue'
* assuming sorted values in range
* */
export function rangeLowerBound(range: AbsoluteCellRange, key: InternalScalarValue, dependencyGraph: DependencyGraph, coordinate: 'row' | 'col'): number {
let end
if(coordinate === 'col') {
end = range.effectiveEndColumn(dependencyGraph)
} else {
end = range.effectiveEndRow(dependencyGraph)
}
const start = range.start[coordinate]
const end = range.end[coordinate]

let centerValueFn
if (coordinate === 'row') {
Expand Down
9 changes: 9 additions & 0 deletions test/interpreter/function-hlookup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,13 @@ describe('Function HLOOKUP', () => {
expect(engine.getCellValue(adr('A1'))).toEqual(0)
})
})

it('should work on row ranges', () => {
const engine = HyperFormula.buildFromArray([
[ '=HLOOKUP(2,2:3,2)'],
[ 1, 2, 3],
[ 'a', 'b', 'c'],
], {binarySearchThreshold: 1})
expect(engine.getCellValue(adr('A1'))).toEqual('b')
})
})
9 changes: 9 additions & 0 deletions test/interpreter/function-vlookup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,13 @@ describe('BinarySearchStrategy', () => {

expect(engine.getCellValue(adr('A1'))).toEqual(0)
})

it('should work on column ranges', () => {
const engine = HyperFormula.buildFromArray([
[ '=VLOOKUP(2,B:C,2)', 1, 'a'],
[null, 2, 'b'],
[null, 3, 'c'],
], {binarySearchThreshold: 1})
expect(engine.getCellValue(adr('A1'))).toEqual('b')
})
})