@abaplint/runtime 2.7.46 → 2.7.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ICharacter } from "./types/_character";
|
|
2
2
|
import { INumeric } from "./types/_numeric";
|
|
3
|
+
/** input indexes = javascript indexes,
|
|
4
|
+
output index = javascript index */
|
|
3
5
|
export declare function binarySearchFromRow(array: readonly any[], left: number, right: number, keyField: (i: any) => any, keyValue: INumeric | ICharacter, usesTableLine: boolean | undefined): number;
|
|
4
6
|
export declare function binarySearchFrom(array: readonly any[], left: number, right: number, keyField: string, keyValue: INumeric | ICharacter): number;
|
|
5
7
|
export declare function binarySearchTo(array: readonly any[], left: number, right: number, keyField: string, keyValue: INumeric | ICharacter): number;
|
|
@@ -4,10 +4,17 @@ exports.binarySearchTo = exports.binarySearchFrom = exports.binarySearchFromRow
|
|
|
4
4
|
/* eslint-disable max-len */
|
|
5
5
|
const compare_1 = require("./compare");
|
|
6
6
|
const types_1 = require("./types");
|
|
7
|
+
/** input indexes = javascript indexes,
|
|
8
|
+
output index = javascript index */
|
|
7
9
|
function binarySearchFromRow(array, left, right, keyField, keyValue, usesTableLine) {
|
|
10
|
+
if (right <= 0) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
// console.dir("start: " + left + ", " + right);
|
|
8
14
|
const isStructured = array[0] instanceof types_1.Structure;
|
|
9
15
|
while (right - left > 1) {
|
|
10
16
|
const middle = Math.floor(((right - left) / 2) + left);
|
|
17
|
+
// console.dir(left + ", " + right + ", " + middle);
|
|
11
18
|
const a = array[middle];
|
|
12
19
|
let row = undefined;
|
|
13
20
|
if (usesTableLine === false && isStructured === true) {
|
|
@@ -22,6 +29,19 @@ function binarySearchFromRow(array, left, right, keyField, keyValue, usesTableLi
|
|
|
22
29
|
else {
|
|
23
30
|
left = middle;
|
|
24
31
|
}
|
|
32
|
+
// console.dir(left + ", " + right);
|
|
33
|
+
}
|
|
34
|
+
const a = array[left];
|
|
35
|
+
let row = undefined;
|
|
36
|
+
if (usesTableLine === false && isStructured === true) {
|
|
37
|
+
row = a.get();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
row = isStructured ? Object.assign({ table_line: a }, a.get()) : { table_line: a };
|
|
41
|
+
}
|
|
42
|
+
if ((0, compare_1.le)(keyValue, keyField(row))) {
|
|
43
|
+
// console.dir("choose left");
|
|
44
|
+
return left;
|
|
25
45
|
}
|
|
26
46
|
return right;
|
|
27
47
|
}
|
|
@@ -4,6 +4,7 @@ exports.readTable = void 0;
|
|
|
4
4
|
const binary_search_1 = require("../binary_search");
|
|
5
5
|
const compare_1 = require("../compare");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
|
+
/** startIndex = javascript index, return ABAP index */
|
|
7
8
|
function searchWithKey(arr, withKey, startIndex = 0, usesTableLine) {
|
|
8
9
|
const isStructured = arr[0] instanceof types_1.Structure;
|
|
9
10
|
for (let index = startIndex; index < arr.length; index++) {
|
|
@@ -110,7 +111,7 @@ function readTable(table, options) {
|
|
|
110
111
|
// note: it currently only uses the first key field for binary search, todo
|
|
111
112
|
const first = options.withKeyValue[0];
|
|
112
113
|
const arr = table.array();
|
|
113
|
-
const startIndex = (0, binary_search_1.binarySearchFromRow)(arr, 0, arr.length, first.key, first.value, options.usesTableLine)
|
|
114
|
+
const startIndex = (0, binary_search_1.binarySearchFromRow)(arr, 0, arr.length - 1, first.key, first.value, options.usesTableLine);
|
|
114
115
|
const searchResult = searchWithKey(arr, options.withKey, startIndex, options.usesTableLine);
|
|
115
116
|
found = searchResult.found;
|
|
116
117
|
foundIndex = searchResult.foundIndex;
|