Skip to content

Commit

Permalink
make the tiles on a selection a struct of info, not twinned lists (#143)
Browse files Browse the repository at this point in the history
Currently, selections maintain a list of tiles and a list of how many matches there are in them that are guaranteed to be the same length by code.

It's better to have a list of records where each record contains *both* of these facts; we'll be using these much more to store sort information in a bit.
<!-- ELLIPSIS_HIDDEN -->


----

| 🚀 | This description was created by 3c779e2  | 
|--------|--------|

refactor: use `SelectionTile` in `DataSelection` for tile management

### Summary:
Refactor `DataSelection` to use `SelectionTile` for managing tiles and match counts, simplifying data handling and preparing for future enhancements.

**Key points**:
- Refactor `DataSelection` to use `SelectionTile` for managing tiles and match counts.
- Introduce `SelectionTile` class in `src/selection.ts`.
- Replace separate `tiles` and `match_count` lists with a single list of `SelectionTile` objects.
- Update methods to use `SelectionTile`, including `moveCursorToPoint()`, `add_or_remove_points()`, and `wrapWithSelectionMetadata()`.
- Adjust iteration and selection logic for `SelectionTile`.
- Fix typo in comment: "untile" to "until".


----
Generated with ❤️ by [ellipsis.dev](https://www.ellipsis.dev)



<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
bmschmidt authored Sep 20, 2024
1 parent 00815d5 commit d70b585
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,21 @@ export class Bitmask {
return result;
}
}
export class DataSelection {
deeptable: Deeptable;
plot: Scatterplot;

class SelectionTile {
public tile: Tile;
// The match count is the number of matches **per tile**;
// used to access numbers by index.
public matchCount?: number;
public indices?: number[];

match_count: number[] = [];
constructor(tile: Tile) {
this.tile = tile;
}
}
export class DataSelection {
deeptable: Deeptable;
plot: Scatterplot;

/**
* name: The name of the selection. This will be used as the colun
Expand Down Expand Up @@ -329,10 +337,10 @@ export class DataSelection {
* The total number of points that have been evaluated for the selection.
*
* This is supplied because deepscatter doesn't evaluate functions on tiles
* untile they are loaded.
* until they are loaded.
*/
evaluationSetSize: number = 0;
tiles: Tile[] = [];
tiles: SelectionTile[] = [];

/**
* Optionally, a user-defined for defining.
Expand Down Expand Up @@ -566,15 +574,12 @@ export class DataSelection {
let currentOffset = 0;
let positionInTile: number;

let current_tile_ix = 0;
for (const match_length of this.match_count) {
const tile = this.tiles[current_tile_ix];
for (const { tile, matchCount } of this.tiles) {
if (tile.key === relevantTile.key) {
positionInTile = rowNumber;
break;
}
current_tile_ix += 1;
currentOffset += match_length;
currentOffset += matchCount;
}

const column = relevantTile.record_batch.getChild(
Expand Down Expand Up @@ -634,7 +639,7 @@ export class DataSelection {
});

await selection.ready;
for (const tile of this.tiles) {
for (const { tile } of this.tiles) {
// This one we actually apply. We'll see if that gets to be slow.
await tile.get_column(newName);
}
Expand Down Expand Up @@ -676,15 +681,14 @@ export class DataSelection {
return async (tile: Tile) => {
const array = await functionToApply(tile);
await tile.populateManifest();
let matches = 0;
let matchCount = 0;
for (let i = 0; i < tile.manifest.nPoints; i++) {
if ((array['get'] && array['get'](i)) || array[i]) {
matches++;
matchCount++;
}
}
this.match_count.push(matches);
this.tiles.push(tile);
this.selectionSize += matches;
this.tiles.push({ tile, matchCount });
this.selectionSize += matchCount;
this.evaluationSetSize += tile.manifest.nPoints;
// DANGER! Possible race condition. Although the tile loaded
// dispatches here, it may take a millisecond or two
Expand Down Expand Up @@ -721,14 +725,12 @@ export class DataSelection {
}
let currentOffset = 0;
let relevantTile: Tile | undefined = undefined;
let current_tile_ix = 0;
for (const match_length of this.match_count) {
if (i < currentOffset + match_length) {
relevantTile = this.tiles[current_tile_ix];
for (const { tile, matchCount } of this.tiles) {
if (i < currentOffset + matchCount) {
relevantTile = tile;
break;
}
current_tile_ix += 1;
currentOffset += match_length;
currentOffset += matchCount;
}
if (relevantTile === undefined) {
return undefined;
Expand All @@ -751,7 +753,7 @@ export class DataSelection {

// Iterate over the points in raw order.
*[Symbol.iterator]() {
for (const tile of this.tiles) {
for (const { tile } of this.tiles) {
const column = tile.record_batch.getChild(this.name) as Vector<Bool>;
for (let i = 0; i < column.length; i++) {
if (column.get(i)) {
Expand Down

0 comments on commit d70b585

Please sign in to comment.