From b91c253638966d944fa458b9755b32ba13f2bfbe Mon Sep 17 00:00:00 2001 From: Benjamin Schmidt Date: Thu, 24 Oct 2024 11:45:50 -0400 Subject: [PATCH] add flatTree method (#164) * add flatTree method * Update tile.ts --- src/Deeptable.ts | 4 +++- src/tile.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Deeptable.ts b/src/Deeptable.ts index 23cf11f6c..eaabeb483 100644 --- a/src/Deeptable.ts +++ b/src/Deeptable.ts @@ -93,7 +93,9 @@ export class Deeptable { resolve?: () => void; }> = new Set(); public selection_history: DS.SelectionRecord[] = []; - + // The flatTree is a representation of known tiles in the quadtree in a flat format + // indexed by tile index (`tix` -- see `tixRixQid`). + public flatTree: (Tile | undefined | null)[] = []; public promise: Promise; public root_tile: Tile; public manifest?: DS.TileManifest; diff --git a/src/tile.ts b/src/tile.ts index 95e4c572d..036cd2c0e 100644 --- a/src/tile.ts +++ b/src/tile.ts @@ -24,6 +24,7 @@ export type Rectangle = { import type { ArrowBuildable, LazyTileManifest, TileManifest } from './types'; import { isCompleteManifest } from './typing'; +import { tileKey_to_tix, zxyToTix } from './tixrixqid'; export type RecordBatchCache = | { @@ -56,6 +57,7 @@ export class Tile { protected _batch?: RecordBatch; parent: Tile | null; private _children: Array = []; + private readonly _tix: number; public _highest_known_ix?: number; public deeptable: Deeptable; public _transformations: Record> = {}; @@ -100,6 +102,13 @@ export class Tile { manifest = key; } this.key = manifest.key; + const coords = this.key.split('/').map((value) => parseInt(value, 10)); + while (coords.length < 3) { + coords.push(0); + } + const tix = zxyToTix(coords[0], coords[1], coords[2]); + this._tix = tix; + deeptable.flatTree[tix] = this; // if (manifest.min_ix === undefined) { // manifest.min_ix = parent ? parent.max_ix + 1 : 0; // } @@ -171,6 +180,9 @@ export class Tile { return existing; } + get tix() { + return this._tix; + } /** * * @param fields A list of keys to be created if they don't exist.