Skip to content

Commit e426586

Browse files
committed
allow selection.get to return a qid
1 parent 659bfcf commit e426586

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/selection.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,10 @@ export class DataSelection {
798798
return this.deeptable.highest_known_ix;
799799
}
800800

801+
802+
get(i: number | undefined, returnQid: false): StructRowProxy | undefined;
803+
get(i: number | undefined, returnQid: true): [number, number] | undefined;
804+
801805
/**
802806
*
803807
* Returns the nth element in the selection. This is a bit tricky because
@@ -807,8 +811,9 @@ export class DataSelection {
807811
* tile until we find the nth match.
808812
*
809813
* @param i the index of the row to get. If less than zero, will return
814+
* @param returnQid if true, returns a tuple of [tile index, row index] instead of the row data
810815
*/
811-
get(i: number | undefined = undefined): StructRowProxy | undefined {
816+
get(i: number | undefined = undefined, returnQid: boolean = false): StructRowProxy | [number, number] | undefined {
812817
if (i === undefined) {
813818
i = this.cursor;
814819
}
@@ -1041,7 +1046,6 @@ export class SortedDataSelection extends DataSelection {
10411046
sortOperation: (a: StructRowProxy) => number,
10421047
order: 'ascending' | 'descending' = 'ascending',
10431048
tKey: string | undefined = undefined,
1044-
name: string | undefined = undefined,
10451049
): Promise<SortedDataSelection> {
10461050
const key = tKey || Math.random().toFixed(10).slice(2);
10471051
const newer = new SortedDataSelection(
@@ -1068,7 +1072,7 @@ export class SortedDataSelection extends DataSelection {
10681072
newer.tiles = await Promise.all(withSort);
10691073
newer.selectionSize = newer.tiles.reduce((sum, t) => sum + t.matchCount, 0);
10701074
newer.evaluationSetSize = newer.tiles.reduce(
1071-
(sum, t) => sum + t.tile.metadata.nPoints,
1075+
(sum: number, t: SelectionTile) : number => sum + t.tile.metadata.nPoints,
10721076
0,
10731077
);
10741078
return newer;
@@ -1108,11 +1112,15 @@ export class SortedDataSelection extends DataSelection {
11081112
};
11091113
}
11101114

1115+
get(i: number | undefined, returnQid: false): StructRowProxy | undefined;
1116+
get(i: number | undefined, returnQid: true): [number, number] | undefined;
1117+
1118+
11111119
/**
11121120
* Returns the k-th element in the sorted selection.
11131121
* This implementation uses Quickselect with a pivot selected from actual data.
11141122
*/
1115-
get(k: number): StructRowProxy | undefined {
1123+
get(k: number | undefined = undefined, returnQid: boolean = false): StructRowProxy | [number, number] | undefined {
11161124
if (k >= this.selectionSize || k < -this.selectionSize) {
11171125
return undefined;
11181126
}
@@ -1125,6 +1133,9 @@ export class SortedDataSelection extends DataSelection {
11251133
const actualK = this.order === 'ascending' ? k : this.selectionSize - k - 1;
11261134
// Implement Quickselect over the combined data
11271135
const result = quickSelect(actualK, this.tiles, this.key, true);
1136+
if (returnQid) {
1137+
return [result.tix, result.rix];
1138+
}
11281139
return result ? result.row : undefined;
11291140
}
11301141

@@ -1222,7 +1233,7 @@ export class TileSorter
12221233
continue;
12231234
}
12241235
// All values left of pointer are less than targetValue.
1225-
let pointer;
1236+
let pointer : number;
12261237
if (this.order === 'ascending') {
12271238
pointer = bisectLeft(rawSortInfo.values, sortValue);
12281239
} else {
@@ -1324,6 +1335,7 @@ interface QuickSortTile {
13241335
type QuickSelectResult = {
13251336
row: StructRowProxy;
13261337
tix: number;
1338+
rix: number;
13271339
// Needed if you want to set pointers
13281340
sortIndex: number;
13291341
sortValue: number;
@@ -1361,6 +1373,7 @@ function quickSelect(
13611373
sortIndex: start,
13621374
sortValue: values[start],
13631375
tix: t.tile.tix,
1376+
rix: recordIndex,
13641377
};
13651378
}
13661379
}
@@ -1459,6 +1472,7 @@ function selectInEqualTiles(
14591472
return {
14601473
row: t.tile.record_batch.get(recordIndex),
14611474
tix: t.tile.tix,
1475+
rix: recordIndex,
14621476
sortIndex: idxInTile,
14631477
sortValue: values[idxInTile],
14641478
};

0 commit comments

Comments
 (0)