57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
"use strict";
|
|||
|
|
|
||
|
|
exports.__esModule = true;
|
||
|
|
exports.AdvancedFind = void 0;
|
||
|
|
var _InterpreterValue = require("../interpreter/InterpreterValue");
|
||
|
|
var _ArithmeticHelper = require("../interpreter/ArithmeticHelper");
|
||
|
|
var _binarySearch = require("../interpreter/binarySearch");
|
||
|
|
/**
|
||
|
|
* @license
|
||
|
|
* Copyright (c) 2024 Handsoncode. All rights reserved.
|
||
|
|
*/
|
||
|
|
|
||
|
|
class AdvancedFind {
|
||
|
|
constructor(dependencyGraph) {
|
||
|
|
this.dependencyGraph = dependencyGraph;
|
||
|
|
}
|
||
|
|
advancedFind(keyMatcher, rangeValue) {
|
||
|
|
let values;
|
||
|
|
const range = rangeValue.range;
|
||
|
|
if (range === undefined) {
|
||
|
|
values = rangeValue.valuesFromTopLeftCorner();
|
||
|
|
} else {
|
||
|
|
values = this.dependencyGraph.computeListOfValuesInRange(range);
|
||
|
|
}
|
||
|
|
for (let i = 0; i < values.length; i++) {
|
||
|
|
if (keyMatcher((0, _InterpreterValue.getRawValue)(values[i]))) {
|
||
|
|
return i;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
/*
|
||
|
|
* WARNING: Finding lower/upper bounds in unordered ranges is not supported. When ordering === 'none', assumes matchExactly === true
|
||
|
|
*/
|
||
|
|
basicFind(searchKey, rangeValue, searchCoordinate, {
|
||
|
|
ordering,
|
||
|
|
matchExactly
|
||
|
|
}) {
|
||
|
|
const normalizedSearchKey = typeof searchKey === 'string' ? (0, _ArithmeticHelper.forceNormalizeString)(searchKey) : searchKey;
|
||
|
|
const range = rangeValue.range;
|
||
|
|
if (range === undefined) {
|
||
|
|
return this.findNormalizedValue(normalizedSearchKey, rangeValue.valuesFromTopLeftCorner());
|
||
|
|
}
|
||
|
|
if (ordering === 'none') {
|
||
|
|
return this.findNormalizedValue(normalizedSearchKey, this.dependencyGraph.computeListOfValuesInRange(range));
|
||
|
|
}
|
||
|
|
return (0, _binarySearch.findLastOccurrenceInOrderedRange)(normalizedSearchKey, range, {
|
||
|
|
searchCoordinate,
|
||
|
|
orderingDirection: ordering,
|
||
|
|
matchExactly
|
||
|
|
}, this.dependencyGraph);
|
||
|
|
}
|
||
|
|
findNormalizedValue(searchKey, searchArray) {
|
||
|
|
return searchArray.map(_InterpreterValue.getRawValue).map(val => typeof val === 'string' ? (0, _ArithmeticHelper.forceNormalizeString)(val) : val).indexOf(searchKey);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
exports.AdvancedFind = AdvancedFind;
|