Skip to content
Merged
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
41 changes: 4 additions & 37 deletions src/tixrixqid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
} from 'apache-arrow';

import type { Tile } from './deepscatter';
import { Bitmask, DataSelection, Deeptable } from './deepscatter';

Check failure on line 11 in src/tixrixqid.ts

View workflow job for this annotation

GitHub Actions / Run ESLint, TypeScript, and Tests

'Bitmask' is declared but its value is never read.

// The type below indicates that a Qid is not valid if
// there are zero rows selected in the tile.
Expand All @@ -21,11 +21,9 @@
// An Rix is a row index, which is an integer identifier for a row in a tile.
type Rix = number;

// A Rixen is a list of row indices. It must be non-empty.
type Rixen = [Rix, ...Rix[]];

// A Qid is a pair of a Tix and a Rixen. It identifies a set of rows in a tile.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment for Qid to reflect it now represents a pair [Tix, Rix] (a tile index and a single row index), not a Tix with a Rixen array.

Suggested change
// A Qid is a pair of a Tix and a Rixen. It identifies a set of rows in a tile.
// A Qid is a pair [Tix, Rix], representing a tile index and a single row index within that tile.

export type Qid = [Tix, Rixen];
export type Qid = [Tix, Rix];
export type QidArray = Qid[];

export function zxyToTix(z: number, x: number, y: number) {
Expand Down Expand Up @@ -99,7 +97,7 @@
export async function qidToRowProxy(qid: Qid, dataset: Deeptable) {
const tile = await tixToTile(qid[0], dataset);
await tile.get_column('x');
return tile.record_batch.get(qid[1][0]);
return tile.record_batch.get(qid[1]);
}

export function tileKey_to_tix(key: string) {
Expand Down Expand Up @@ -132,10 +130,10 @@
export function getQidFromRow(
row: StructRowProxy,
dataset: Deeptable,
): [number, number] {
): Qid {
const tile = getTileFromRow(row, dataset);
const rix = row[Symbol.for('rowIndex')] as number;
return [tileKey_to_tix(tile.key), rix] as [number, number];
return [tile.tix, rix] satisfies [number, number];
}

export function getTileFromRow(row: StructRowProxy, dataset: Deeptable): Tile {
Expand Down Expand Up @@ -178,37 +176,6 @@
return best_match[0];
}

export function getQidArrayFromRows(
rows: StructRowProxy[],
dataset: Deeptable,
): QidArray {
// TODO: this is really inefficient. We should be able to do this in one pass.
const qids = rows.map((row) => getQidFromRow(row, dataset));
const mapped = new Map<number, [number, ...number[]]>();
for (const qid of qids) {
if (mapped.has(qid[0])) {
mapped.get(qid[0]).push(qid[1]);
} else {
mapped.set(qid[0], [qid[1]]);
}
}
return Array.from(mapped.entries());
}

export function selectQixOnTile(tile: Tile, qidList: QidArray) {
const mask = new Bitmask(tile.record_batch.numRows);
const [z, x, y] = tile.key.split('/').map((d) => parseInt(d));
const tix = zxyToTix(z, x, y);
const rixes = qidList
.filter((d) => d[0] === tix)
.map((d) => d[1])
.flat();
for (const rix of rixes) {
mask.set(rix);
}
return mask.to_arrow();
}

/**
*
* @param hoverDatum A struct row.
Expand Down
Loading