Skip to content

Commit

Permalink
Fix misspelled word occurrence
Browse files Browse the repository at this point in the history
  • Loading branch information
sequba committed Jan 2, 2025
1 parent a398fb1 commit 24f7d04
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/DependencyGraph/TopSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class TopSort<T> {
* Returns vertices in order of topological sort, but vertices that are on cycles are kept separate.
*
* @param modifiedNodes - seed for computation. During engine init run, all of the vertices of grap. In recomputation run, changed vertices.
* @param operatingFunction - recomputes value of a node, and returns whether a change occured
* @param operatingFunction - recomputes value of a node, and returns whether a change occurred
* @param onCycle - action to be performed when node is on cycle
*/
public getTopSortedWithSccSubgraphFrom(
Expand Down
24 changes: 12 additions & 12 deletions src/Lookup/AdvancedFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export abstract class AdvancedFind {
) {
}

public advancedFind(keyMatcher: (arg: RawInterpreterValue) => boolean, rangeValue: SimpleRangeValue, { returnOccurence }: AdvancedFindOptions = { returnOccurence: 'first' }): number {
public advancedFind(keyMatcher: (arg: RawInterpreterValue) => boolean, rangeValue: SimpleRangeValue, { returnOccurrence }: AdvancedFindOptions = { returnOccurrence: 'first' }): number {
const range = rangeValue.range
const values: InternalScalarValue[] = (range === undefined)
? rangeValue.valuesFromTopLeftCorner()
: this.dependencyGraph.computeListOfValuesInRange(range)

const initialIterationIndex = returnOccurence === 'first' ? 0 : values.length-1
const iterationCondition = returnOccurence === 'first' ? (i: number) => i < values.length : (i: number) => i >= 0
const incrementIndex = returnOccurence === 'first' ? (i: number) => i+1 : (i: number) => i-1
const initialIterationIndex = returnOccurrence === 'first' ? 0 : values.length-1
const iterationCondition = returnOccurrence === 'first' ? (i: number) => i < values.length : (i: number) => i >= 0
const incrementIndex = returnOccurrence === 'first' ? (i: number) => i+1 : (i: number) => i-1

for (let i = initialIterationIndex; iterationCondition(i); i = incrementIndex(i)) {
if (keyMatcher(getRawValue(values[i]))) {
Expand All @@ -41,16 +41,16 @@ export abstract class AdvancedFind {
return NOT_FOUND
}

protected basicFind(searchKey: RawNoErrorScalarValue, rangeValue: SimpleRangeValue, searchCoordinate: 'col' | 'row', { ordering, ifNoMatch, returnOccurence }: SearchOptions): number {
protected basicFind(searchKey: RawNoErrorScalarValue, rangeValue: SimpleRangeValue, searchCoordinate: 'col' | 'row', { ordering, ifNoMatch, returnOccurrence }: SearchOptions): number {
const normalizedSearchKey = typeof searchKey === 'string' ? forceNormalizeString(searchKey) : searchKey
const range = rangeValue.range

if (range === undefined) {
return this.findNormalizedValue(normalizedSearchKey, rangeValue.valuesFromTopLeftCorner(), ifNoMatch, returnOccurence)
return this.findNormalizedValue(normalizedSearchKey, rangeValue.valuesFromTopLeftCorner(), ifNoMatch, returnOccurrence)
}

if (ordering === 'none') {
return this.findNormalizedValue(normalizedSearchKey, this.dependencyGraph.computeListOfValuesInRange(range), ifNoMatch, returnOccurence)
return this.findNormalizedValue(normalizedSearchKey, this.dependencyGraph.computeListOfValuesInRange(range), ifNoMatch, returnOccurrence)
}

return findLastOccurrenceInOrderedRange(
Expand All @@ -61,13 +61,13 @@ export abstract class AdvancedFind {
)
}

protected findNormalizedValue(searchKey: RawNoErrorScalarValue, searchArray: InternalScalarValue[], ifNoMatch: 'returnLowerBound' | 'returnUpperBound' | 'returnNotFound' = 'returnNotFound', returnOccurence: 'first' | 'last' = 'first'): number {
protected findNormalizedValue(searchKey: RawNoErrorScalarValue, searchArray: InternalScalarValue[], ifNoMatch: 'returnLowerBound' | 'returnUpperBound' | 'returnNotFound' = 'returnNotFound', returnOccurrence: 'first' | 'last' = 'first'): number {
const normalizedArray = searchArray
.map(getRawValue)
.map(val => typeof val === 'string' ? forceNormalizeString(val) : val)

if (ifNoMatch === 'returnNotFound') {
return returnOccurence === 'first' ? normalizedArray.indexOf(searchKey) : normalizedArray.lastIndexOf(searchKey)
return returnOccurrence === 'first' ? normalizedArray.indexOf(searchKey) : normalizedArray.lastIndexOf(searchKey)
}

const compareFn = ifNoMatch === 'returnLowerBound'
Expand All @@ -77,9 +77,9 @@ export abstract class AdvancedFind {
let bestValue: RawNoErrorScalarValue = ifNoMatch === 'returnLowerBound' ? -Infinity : Infinity
let bestIndex = NOT_FOUND

const initialIterationIndex = returnOccurence === 'first' ? 0 : normalizedArray.length-1
const iterationCondition = returnOccurence === 'first' ? (i: number) => i < normalizedArray.length : (i: number) => i >= 0
const incrementIndex = returnOccurence === 'first' ? (i: number) => i+1 : (i: number) => i-1
const initialIterationIndex = returnOccurrence === 'first' ? 0 : normalizedArray.length-1
const iterationCondition = returnOccurrence === 'first' ? (i: number) => i < normalizedArray.length : (i: number) => i >= 0
const incrementIndex = returnOccurrence === 'first' ? (i: number) => i+1 : (i: number) => i-1

for (let i = initialIterationIndex; iterationCondition(i); i = incrementIndex(i)) {
const value = normalizedArray[i] as RawNoErrorScalarValue
Expand Down
20 changes: 10 additions & 10 deletions src/Lookup/ColumnIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ export class ColumnIndex implements ColumnSearchStrategy {
}
}

public find(searchKey: RawNoErrorScalarValue, rangeValue: SimpleRangeValue, { ordering, ifNoMatch, returnOccurence }: SearchOptions): number {
public find(searchKey: RawNoErrorScalarValue, rangeValue: SimpleRangeValue, { ordering, ifNoMatch, returnOccurrence }: SearchOptions): number {
if (ifNoMatch == null) {
ifNoMatch = 'returnNotFound'
}

if (returnOccurence == null) {
returnOccurence = ordering === 'none' ? 'first' : 'last'
if (returnOccurrence == null) {
returnOccurrence = ordering === 'none' ? 'first' : 'last'
}

const resultUsingColumnIndex = this.findUsingColumnIndex(searchKey, rangeValue, returnOccurence)
return resultUsingColumnIndex !== undefined ? resultUsingColumnIndex : this.binarySearchStrategy.find(searchKey, rangeValue, { ordering, ifNoMatch, returnOccurence })
const resultUsingColumnIndex = this.findUsingColumnIndex(searchKey, rangeValue, returnOccurrence)
return resultUsingColumnIndex !== undefined ? resultUsingColumnIndex : this.binarySearchStrategy.find(searchKey, rangeValue, { ordering, ifNoMatch, returnOccurrence })
}

private findUsingColumnIndex(key: RawNoErrorScalarValue, rangeValue: SimpleRangeValue, returnOccurence: 'first' | 'last'): Maybe<number> {
private findUsingColumnIndex(key: RawNoErrorScalarValue, rangeValue: SimpleRangeValue, returnOccurrence: 'first' | 'last'): Maybe<number> {
const range = rangeValue.range
if (range === undefined) {
return undefined
Expand All @@ -139,15 +139,15 @@ export class ColumnIndex implements ColumnSearchStrategy {
return undefined
}

const rowNumber = ColumnIndex.findRowBelongingToRange(valueIndexForTheKey, range, returnOccurence)
const rowNumber = ColumnIndex.findRowBelongingToRange(valueIndexForTheKey, range, returnOccurrence)
return rowNumber !== undefined ? rowNumber - range.start.row : undefined
}

private static findRowBelongingToRange(valueIndex: ValueIndex, range: AbsoluteCellRange, returnOccurence: 'first' | 'last'): Maybe<number> {
private static findRowBelongingToRange(valueIndex: ValueIndex, range: AbsoluteCellRange, returnOccurrence: 'first' | 'last'): Maybe<number> {
const start = range.start.row
const end = range.end.row

const positionInIndex = returnOccurence === 'first'
const positionInIndex = returnOccurrence === 'first'
? findInOrderedArray(start, valueIndex.index, 'upperBound')
: findInOrderedArray(end, valueIndex.index, 'lowerBound')

Expand All @@ -162,7 +162,7 @@ export class ColumnIndex implements ColumnSearchStrategy {
}


public advancedFind(keyMatcher: (arg: RawInterpreterValue) => boolean, range: SimpleRangeValue, options: AdvancedFindOptions = { returnOccurence: 'first' }): number {
public advancedFind(keyMatcher: (arg: RawInterpreterValue) => boolean, range: SimpleRangeValue, options: AdvancedFindOptions = { returnOccurrence: 'first' }): number {
return this.binarySearchStrategy.advancedFind(keyMatcher, range, options)
}

Expand Down
4 changes: 2 additions & 2 deletions src/Lookup/SearchStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {ColumnIndex} from './ColumnIndex'
export interface SearchOptions {
ordering: 'asc' | 'desc' | 'none',
ifNoMatch: 'returnLowerBound' | 'returnUpperBound' | 'returnNotFound',
returnOccurence?: 'first' | 'last',
returnOccurrence?: 'first' | 'last',
}

export interface AdvancedFindOptions {
returnOccurence?: 'first' | 'last',
returnOccurrence?: 'first' | 'last',
}

export interface SearchStrategy {
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/plugin/LookupPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class LookupPlugin extends FunctionPlugin implements FunctionPluginTypech
const isWildcardMatchMode = matchMode === 2
const searchOptions: SearchOptions = {
ordering: searchMode === 2 ? 'asc' : searchMode === -2 ? 'desc' : 'none',
returnOccurence: searchMode === -1 ? 'last' : 'first',
returnOccurrence: searchMode === -1 ? 'last' : 'first',
ifNoMatch: matchMode === -1
? 'returnLowerBound'
: matchMode === 1
Expand Down Expand Up @@ -202,7 +202,7 @@ export class LookupPlugin extends FunctionPlugin implements FunctionPluginTypech
return searchStrategy.advancedFind(
this.arithmeticHelper.eqMatcherFunction(key),
range,
{ returnOccurence: searchOptions.returnOccurence }
{ returnOccurrence: searchOptions.returnOccurrence }
)
}

Expand Down
2 changes: 1 addition & 1 deletion test/interpreter/binary-search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('findLastOccurrenceInOrderedArray', () => {
expect(findLastOccurrenceInOrderedArray('xyz', values)).toBe(5)
})

it('returns the last occurence', () => {
it('returns the last occurrence', () => {
const values = [1, 2, 2, 2, 2, 2, 3, 3, 3]
expect(findLastOccurrenceInOrderedArray(2, values)).toBe(5)
})
Expand Down
2 changes: 1 addition & 1 deletion test/interpreter/function-substitute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Function SUBSTITUTE', () => {
expect(engine.getCellValue(adr('A4'))).toEqual('fofofofufo')
})

it('should return the original text if there are not enough occurences of the search string', () => {
it('should return the original text if there are not enough occurrences of the search string', () => {
const engine = HyperFormula.buildFromArray([
['=SUBSTITUTE("foobar", "o", "BAZ", 3)'],
])
Expand Down

0 comments on commit 24f7d04

Please sign in to comment.