@carto/api-client 0.5.7-alpha.2 → 0.5.7-alpha.5
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.
- package/build/api-client.cjs +64 -10
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +19 -10
- package/build/api-client.d.ts +19 -10
- package/build/api-client.js +62 -8
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +3467 -2278
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +59 -1
- package/build/worker.js.map +1 -1
- package/package.json +2 -2
- package/src/filters/tileFeaturesRaster.ts +2 -1
- package/src/index.ts +1 -0
- package/src/utils/CellSet.ts +90 -0
- package/src/widget-sources/index.ts +0 -1
- package/src/widget-sources/types.ts +0 -2
- package/src/widget-sources/widget-remote-source.ts +1 -3
- package/src/widget-sources/constants.ts +0 -6
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"homepage": "https://github.com/CartoDB/carto-api-client#readme",
|
|
9
9
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
10
10
|
"packageManager": "yarn@4.3.1",
|
|
11
|
-
"version": "0.5.7-alpha.
|
|
11
|
+
"version": "0.5.7-alpha.5",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"typescript": "~5.8.2",
|
|
127
127
|
"typescript-eslint": "^8.26.1",
|
|
128
128
|
"vite": "^6.2.2",
|
|
129
|
-
"vitest": "3.1.
|
|
129
|
+
"vitest": "3.1.4"
|
|
130
130
|
},
|
|
131
131
|
"resolutions": {
|
|
132
132
|
"@carto/api-client": "portal:./",
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
RasterMetadataBand,
|
|
12
12
|
SpatialDataType,
|
|
13
13
|
} from '../sources/types.js';
|
|
14
|
+
import {CellSet} from '../utils/CellSet.js';
|
|
14
15
|
|
|
15
16
|
export type TileFeaturesRasterOptions = {
|
|
16
17
|
tiles: RasterTile[];
|
|
@@ -45,7 +46,7 @@ export function tileFeaturesRaster({
|
|
|
45
46
|
|
|
46
47
|
// Compute covering cells for the spatial filter, at same resolution as the
|
|
47
48
|
// raster pixels, to be used as a mask.
|
|
48
|
-
const spatialFilterCells = new
|
|
49
|
+
const spatialFilterCells = new CellSet(
|
|
49
50
|
geometryToCells(options.spatialFilter, cellResolution)
|
|
50
51
|
);
|
|
51
52
|
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** Flags 'empty' values in a Uint32Array index. */
|
|
2
|
+
const EMPTY_U32 = 2 ** 32 - 1;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom Set-like interface optimized for BigUint64 cell IDs. Unlike Set,
|
|
6
|
+
* limited in most JavaScript runtimes to ~16M entries, this implementation
|
|
7
|
+
* can support up to `n = 2^32 - 1` (4 billion) entries, with lookups in
|
|
8
|
+
* amortized O(1) time.
|
|
9
|
+
*/
|
|
10
|
+
export class CellSet {
|
|
11
|
+
/** List of cells stored by the set. Stored by reference, without copying. */
|
|
12
|
+
private cells: bigint[];
|
|
13
|
+
|
|
14
|
+
/** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
|
|
15
|
+
private cellView = new DataView(new ArrayBuffer(8));
|
|
16
|
+
|
|
17
|
+
/** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
|
|
18
|
+
private hashTable: Uint32Array;
|
|
19
|
+
|
|
20
|
+
constructor(cells: bigint[]) {
|
|
21
|
+
this.cells = cells;
|
|
22
|
+
|
|
23
|
+
// Pre-allocate hash table for queries.
|
|
24
|
+
this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
|
|
25
|
+
for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
|
|
26
|
+
this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
has(cell: bigint): boolean {
|
|
31
|
+
const hashIndex = this.hashLookup(cell);
|
|
32
|
+
return this.hashTable[hashIndex] !== EMPTY_U32;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private hashLookup(cell: bigint): number {
|
|
36
|
+
// Hash implementation operates on 32-bit chunks, so write the cell ID
|
|
37
|
+
// into a pre-allocated DataView for easier iteration.
|
|
38
|
+
this.cellView.setBigUint64(0, cell);
|
|
39
|
+
const hashval = hash(this.cellView);
|
|
40
|
+
const hashmod = this.hashTable.length - 1;
|
|
41
|
+
let bucket = hashval & hashmod;
|
|
42
|
+
|
|
43
|
+
// Find the first bucket in the hash table where either (a) no cell
|
|
44
|
+
// is yet stored, or (b) the stored cell and the query cell are equal.
|
|
45
|
+
for (let probe = 0; probe <= hashmod; probe++) {
|
|
46
|
+
const cellIndex = this.hashTable[bucket];
|
|
47
|
+
|
|
48
|
+
if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
|
|
49
|
+
return bucket;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
bucket = (bucket + probe + 1) & hashmod; // Hash collision; quadratic probing.
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error('Hash table full.'); // Unreachable.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* MurmurHash2
|
|
61
|
+
*
|
|
62
|
+
* References:
|
|
63
|
+
* - https://github.com/mikolalysenko/murmurhash-js/blob/f19136e9f9c17f8cddc216ca3d44ec7c5c502f60/murmurhash2_gc.js#L14
|
|
64
|
+
* - https://github.com/zeux/meshoptimizer/blob/e47e1be6d3d9513153188216455bdbed40a206ef/src/indexgenerator.cpp#L12
|
|
65
|
+
*/
|
|
66
|
+
function hash(view: DataView, h = 0): number {
|
|
67
|
+
const m = 0x5bd1e995;
|
|
68
|
+
const r = 24;
|
|
69
|
+
|
|
70
|
+
for (let i = 0, il = view.byteLength / 4; i < il; i++) {
|
|
71
|
+
let k = view.getUint32(i * 4);
|
|
72
|
+
|
|
73
|
+
k = Math.imul(k, m) >>> 0;
|
|
74
|
+
k = (k ^ (k >> r)) >>> 0;
|
|
75
|
+
k = Math.imul(k, m) >>> 0;
|
|
76
|
+
|
|
77
|
+
h = Math.imul(h, m) >>> 0;
|
|
78
|
+
h = (h ^ k) >>> 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return h;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function hashBuckets(initialCount: number) {
|
|
85
|
+
let buckets = 1;
|
|
86
|
+
while (buckets < initialCount + initialCount / 4) {
|
|
87
|
+
buckets *= 2;
|
|
88
|
+
}
|
|
89
|
+
return buckets;
|
|
90
|
+
}
|
|
@@ -59,8 +59,6 @@ export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
|
59
59
|
operationColumn?: string;
|
|
60
60
|
/** Local only. */
|
|
61
61
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
62
|
-
/** Calculate `_carto_others` category for all categories after first N (N is threshold). Remote only. */
|
|
63
|
-
othersThreshold?: boolean;
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
/**
|
|
@@ -74,8 +74,7 @@ export abstract class WidgetRemoteSource<
|
|
|
74
74
|
spatialFiltersMode,
|
|
75
75
|
...params
|
|
76
76
|
} = options;
|
|
77
|
-
const {column, operation, operationColumn, operationExp
|
|
78
|
-
params;
|
|
77
|
+
const {column, operation, operationColumn, operationExp} = params;
|
|
79
78
|
|
|
80
79
|
if (operation === AggregationTypes.Custom) {
|
|
81
80
|
assert(operationExp, 'operationExp is required for custom operation');
|
|
@@ -95,7 +94,6 @@ export abstract class WidgetRemoteSource<
|
|
|
95
94
|
operation,
|
|
96
95
|
operationExp,
|
|
97
96
|
operationColumn: operationColumn || column,
|
|
98
|
-
othersThreshold,
|
|
99
97
|
},
|
|
100
98
|
opts: {signal, headers: this.props.headers},
|
|
101
99
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|