vastgrid-js 0.0.0-stage → 0.2.0

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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -2
  3. package/dist/aggregate.d.ts +45 -0
  4. package/dist/aggregate.d.ts.map +1 -0
  5. package/dist/aggregate.js +305 -0
  6. package/dist/aggregate.js.map +1 -0
  7. package/dist/arrow.d.ts +7 -0
  8. package/dist/arrow.d.ts.map +1 -0
  9. package/dist/arrow.js +25 -0
  10. package/dist/arrow.js.map +1 -0
  11. package/dist/engine.d.ts +40 -0
  12. package/dist/engine.d.ts.map +1 -0
  13. package/dist/engine.js +1022 -0
  14. package/dist/engine.js.map +1 -0
  15. package/dist/evaluate.d.ts +37 -0
  16. package/dist/evaluate.d.ts.map +1 -0
  17. package/dist/evaluate.js +774 -0
  18. package/dist/evaluate.js.map +1 -0
  19. package/dist/export.d.ts +23 -0
  20. package/dist/export.d.ts.map +1 -0
  21. package/dist/export.js +48 -0
  22. package/dist/export.js.map +1 -0
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +2 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/lazy.d.ts +65 -0
  28. package/dist/lazy.d.ts.map +1 -0
  29. package/dist/lazy.js +177 -0
  30. package/dist/lazy.js.map +1 -0
  31. package/dist/numbers.d.ts +20 -0
  32. package/dist/numbers.d.ts.map +1 -0
  33. package/dist/numbers.js +129 -0
  34. package/dist/numbers.js.map +1 -0
  35. package/dist/order.d.ts +67 -0
  36. package/dist/order.d.ts.map +1 -0
  37. package/dist/order.js +561 -0
  38. package/dist/order.js.map +1 -0
  39. package/dist/parquet.d.ts +38 -0
  40. package/dist/parquet.d.ts.map +1 -0
  41. package/dist/parquet.js +673 -0
  42. package/dist/parquet.js.map +1 -0
  43. package/dist/plan.d.ts +37 -0
  44. package/dist/plan.d.ts.map +1 -0
  45. package/dist/plan.js +51 -0
  46. package/dist/plan.js.map +1 -0
  47. package/dist/summary.d.ts +37 -0
  48. package/dist/summary.d.ts.map +1 -0
  49. package/dist/summary.js +175 -0
  50. package/dist/summary.js.map +1 -0
  51. package/dist/table.d.ts +172 -0
  52. package/dist/table.d.ts.map +1 -0
  53. package/dist/table.js +154 -0
  54. package/dist/table.js.map +1 -0
  55. package/dist/text.d.ts +18 -0
  56. package/dist/text.d.ts.map +1 -0
  57. package/dist/text.js +1204 -0
  58. package/dist/text.js.map +1 -0
  59. package/dist/workbook.d.ts +6 -0
  60. package/dist/workbook.d.ts.map +1 -0
  61. package/dist/workbook.js +35 -0
  62. package/dist/workbook.js.map +1 -0
  63. package/package.json +46 -4
  64. package/src/aggregate.ts +358 -0
  65. package/src/arrow.ts +24 -0
  66. package/src/engine.ts +1163 -0
  67. package/src/evaluate.ts +764 -0
  68. package/src/export.ts +73 -0
  69. package/src/index.ts +2 -0
  70. package/src/lazy.ts +185 -0
  71. package/src/numbers.ts +128 -0
  72. package/src/order.ts +594 -0
  73. package/src/parquet.ts +801 -0
  74. package/src/plan.ts +99 -0
  75. package/src/summary.ts +180 -0
  76. package/src/table.ts +297 -0
  77. package/src/text.ts +1285 -0
  78. package/src/workbook.ts +48 -0
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The order of values and views (docs/spec.md §3.1, §3.3).
3
+ *
4
+ * Each column's values are ranked once: its distinct values that are not blank are numbered from 0 in
5
+ * ascending order, the empty string of a string column ranks `distinct` and null `distinct + 1`. A view is
6
+ * sorted by the ranks of its sort keys, with one stable counting sort per key from the last key to the first,
7
+ * starting from row ID order: blanks come last in both directions and tie with each other, ties go to the
8
+ * next key, and rows equal for every key stay in row ID order.
9
+ *
10
+ * Values of fixed width are ranked through 32-bit words compared as unsigned integers, most significant
11
+ * first, with a radix sort; strings and bytes are ranked with a comparison sort of runs, which are then merged.
12
+ */
13
+ import { type Column, type JsonValue } from "vastgrid-spec";
14
+ import type { Vector } from "./table.js";
15
+ /** The ranks of one column's values. */
16
+ export interface ColumnRanks {
17
+ /** The rank of each row's value. */
18
+ ranks: Uint32Array;
19
+ /** The number of distinct values that are not blank; blanks rank from here. */
20
+ distinct: number;
21
+ /**
22
+ * The rank of a value written as §2.2 writes the column's values, or −1 when no row holds a value equal to
23
+ * it (§3.1). Exact numbers are equal whatever their scales, so the decimal `"1.5"` finds `"1.50"`.
24
+ */
25
+ rankOf(value: JsonValue): number;
26
+ }
27
+ /** The values of a column by row ID. */
28
+ type Values = Vector;
29
+ export declare const TWO_32 = 4294967296;
30
+ export declare const SIGN = 2147483648;
31
+ /** A signed 32-bit integer as a word whose unsigned order is the integer's order. */
32
+ export declare function int32Word(value: number): number;
33
+ /** Writes a safe integer as a signed 64-bit integer, in two words. */
34
+ export declare function writeInt64(value: number, high: Uint32Array, low: Uint32Array, at: number): void;
35
+ export declare const HIGH: number;
36
+ export declare const LOW: number;
37
+ /**
38
+ * Writes a float in two words: the bits of a positive number with the sign bit set, and those of a negative
39
+ * number inverted, so that the words order as the numbers do. −0.0 is written as 0.0, and every NaN as the
40
+ * greatest words, above Infinity (§3.1).
41
+ */
42
+ export declare function writeFloat(value: number, high: Uint32Array, low: Uint32Array, at: number): void;
43
+ /** Writes the words of the value at a row of a column's numbers (`Vector.numbers`) at a row of `words`. */
44
+ export type NumberWriter = (row: number, words: readonly Uint32Array[], at: number) => void;
45
+ /**
46
+ * Ranks the values of a column by row ID in the order of §3.1; blanks rank after the other values (§3.2). A column
47
+ * of fixed width that has numbers (`Vector.numbers`) is ranked from them by `write`, when it is given.
48
+ */
49
+ export declare function rankColumn(column: Column, values: Values, write?: NumberWriter | null): ColumnRanks;
50
+ /**
51
+ * `rankColumn`, which calls `pause` between the steps of ranking text, where a million rows take about half a
52
+ * second: a request that ranks lets other messages in, and stops where `pause` throws.
53
+ */
54
+ export declare function rankColumnPausing(column: Column, values: Values, write: NumberWriter | null, pause: () => Promise<void>): Promise<ColumnRanks>;
55
+ /** A sort key of a view: the ranks of its column and its direction. */
56
+ export interface RankedKey {
57
+ ranks: ColumnRanks;
58
+ descending: boolean;
59
+ }
60
+ /**
61
+ * The row IDs of `count` rows in the order of the keys (§3.3): by the first key, ties by the next, and rows
62
+ * equal for every key in row ID order. The rows are the row IDs from 0, or those of `rows` (in row ID order)
63
+ * when it is given. Without keys, the rows as they are: null for the row IDs from 0.
64
+ */
65
+ export declare function sortRows(count: number, keys: readonly RankedKey[], rows?: Uint32Array | null): Uint32Array | null;
66
+ export {};
67
+ //# sourceMappingURL=order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,KAAK,MAAM,EAKX,KAAK,SAAS,EAEf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,wCAAwC;AACxC,MAAM,WAAW,WAAW;IAC1B,oCAAoC;IACpC,KAAK,EAAE,WAAW,CAAC;IACnB,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC;CAClC;AAED,wCAAwC;AACxC,KAAK,MAAM,GAAG,MAAM,CAAC;AAWrB,eAAO,MAAM,MAAM,aAAgB,CAAC;AAEpC,eAAO,MAAM,IAAI,aAAc,CAAC;AAIhC,qFAAqF;AACrF,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,QAIxF;AAqBD,eAAO,MAAM,IAAI,QAAuB,CAAC;AACzC,eAAO,MAAM,GAAG,QAAuB,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,QAgBxF;AAwKD,2GAA2G;AAC3G,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,WAAW,EAAE,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;AAgP5F;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,YAAY,GAAG,IAAW,GAAG,WAAW,CAOzG;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY,GAAG,IAAI,EAC1B,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GACzB,OAAO,CAAC,WAAW,CAAC,CAQtB;AAED,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;CACrB;AAyBD;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,SAAS,SAAS,EAAE,EAC1B,IAAI,GAAE,WAAW,GAAG,IAAW,GAC9B,WAAW,GAAG,IAAI,CAKpB"}
package/dist/order.js ADDED
@@ -0,0 +1,561 @@
1
+ /**
2
+ * The order of values and views (docs/spec.md §3.1, §3.3).
3
+ *
4
+ * Each column's values are ranked once: its distinct values that are not blank are numbered from 0 in
5
+ * ascending order, the empty string of a string column ranks `distinct` and null `distinct + 1`. A view is
6
+ * sorted by the ranks of its sort keys, with one stable counting sort per key from the last key to the first,
7
+ * starting from row ID order: blanks come last in both directions and tie with each other, ties go to the
8
+ * next key, and rows equal for every key stay in row ID order.
9
+ *
10
+ * Values of fixed width are ranked through 32-bit words compared as unsigned integers, most significant
11
+ * first, with a radix sort; strings and bytes are ranked with a comparison sort of runs, which are then merged.
12
+ */
13
+ import { daysFromCivil, floatOf, fromBase64, isValueOf, normalizeInterval, } from "vastgrid-spec";
14
+ export const TWO_32 = 4_294_967_296;
15
+ const MASK_32 = 0xffffffffn;
16
+ export const SIGN = 0x8000_0000;
17
+ const INT64_MIN = -(2n ** 63n);
18
+ const INT64_MAX = 2n ** 63n - 1n;
19
+ /** A signed 32-bit integer as a word whose unsigned order is the integer's order. */
20
+ export function int32Word(value) {
21
+ return (value ^ SIGN) >>> 0;
22
+ }
23
+ /** Writes a safe integer as a signed 64-bit integer, in two words. */
24
+ export function writeInt64(value, high, low, at) {
25
+ const upper = Math.floor(value / TWO_32);
26
+ high[at] = int32Word(upper);
27
+ low[at] = value - upper * TWO_32;
28
+ }
29
+ /** Writes a signed 64-bit integer in two words. */
30
+ function writeBigInt64(value, high, low, at) {
31
+ const bits = BigInt.asUintN(64, value);
32
+ high[at] = int32Word(Number(bits >> 32n));
33
+ low[at] = Number(bits & MASK_32);
34
+ }
35
+ /** Writes a signed 128-bit integer in four words. */
36
+ function writeBigInt128(value, words, at) {
37
+ const bits = BigInt.asUintN(128, value);
38
+ words[0][at] = int32Word(Number(bits >> 96n));
39
+ words[1][at] = Number((bits >> 64n) & MASK_32);
40
+ words[2][at] = Number((bits >> 32n) & MASK_32);
41
+ words[3][at] = Number(bits & MASK_32);
42
+ }
43
+ const floatBits = new Float64Array(1);
44
+ const floatWords = new Uint32Array(floatBits.buffer);
45
+ const littleEndian = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
46
+ export const HIGH = littleEndian ? 1 : 0;
47
+ export const LOW = littleEndian ? 0 : 1;
48
+ /**
49
+ * Writes a float in two words: the bits of a positive number with the sign bit set, and those of a negative
50
+ * number inverted, so that the words order as the numbers do. −0.0 is written as 0.0, and every NaN as the
51
+ * greatest words, above Infinity (§3.1).
52
+ */
53
+ export function writeFloat(value, high, low, at) {
54
+ if (Number.isNaN(value)) {
55
+ high[at] = 0xffff_ffff;
56
+ low[at] = 0xffff_ffff;
57
+ return;
58
+ }
59
+ floatBits[0] = value === 0 ? 0 : value;
60
+ const upper = floatWords[HIGH];
61
+ const lower = floatWords[LOW];
62
+ if (upper >= SIGN) {
63
+ high[at] = ~upper >>> 0;
64
+ low[at] = ~lower >>> 0;
65
+ }
66
+ else {
67
+ high[at] = (upper | SIGN) >>> 0;
68
+ low[at] = lower;
69
+ }
70
+ }
71
+ /** The number of the decimal digits of `text` from `start`, `length` of them. */
72
+ function digitsAt(text, start, length) {
73
+ let number = 0;
74
+ for (let index = start; index < start + length; index++)
75
+ number = number * 10 + text.charCodeAt(index) - 48;
76
+ return number;
77
+ }
78
+ /**
79
+ * The fraction of a second whose point is at `start`, as a count of 10^−`places` seconds: 0 without a point.
80
+ * The digits end at the end of the text or at its time zone.
81
+ */
82
+ function fractionAt(text, start, places) {
83
+ if (text.charCodeAt(start) !== 46)
84
+ return 0;
85
+ let number = 0;
86
+ let place = 0;
87
+ for (let index = start + 1; place < places; index++, place++) {
88
+ const digit = text.charCodeAt(index) - 48;
89
+ if (!(digit >= 0 && digit <= 9))
90
+ break;
91
+ number = number * 10 + digit;
92
+ }
93
+ for (; place < places; place++)
94
+ number *= 10;
95
+ return number;
96
+ }
97
+ /** Days since 1970-01-01 of `YYYY-MM-DD` at `start` (§2.2). */
98
+ function daysAt(text, start) {
99
+ return daysFromCivil(digitsAt(text, start, 4), digitsAt(text, start + 5, 2), digitsAt(text, start + 8, 2));
100
+ }
101
+ /** Seconds since midnight of `HH:MM:SS` at `start` (§2.2). */
102
+ function secondsAt(text, start) {
103
+ return digitsAt(text, start, 2) * 3600 + digitsAt(text, start + 3, 2) * 60 + digitsAt(text, start + 6, 2);
104
+ }
105
+ /**
106
+ * The digits of a decimal's unscaled integer at a scale, with its sign: `"-12.5"` at scale 2 is `"-1250"`.
107
+ * Null when the text is not a decimal, or has digits other than 0 beyond the scale.
108
+ */
109
+ function unscaledDigits(text, scale) {
110
+ const match = /^(-?)([0-9]+)(?:\.([0-9]+))?$/.exec(text);
111
+ if (!match)
112
+ return null;
113
+ const fraction = match[3] ?? "";
114
+ if (fraction.length > scale && !/^0*$/.test(fraction.slice(scale)))
115
+ return null;
116
+ return `${match[1]}${match[2]}${fraction.slice(0, scale).padEnd(scale, "0")}`;
117
+ }
118
+ function codecOf(column) {
119
+ const accept = (value) => (isValueOf(value, column) ? value : null);
120
+ switch (column.type) {
121
+ case "boolean":
122
+ return {
123
+ width: 1,
124
+ write: (value, words, at) => {
125
+ words[0][at] = value === true ? 1 : 0;
126
+ },
127
+ accept,
128
+ };
129
+ case "integer":
130
+ return {
131
+ width: 1,
132
+ write: (value, words, at) => {
133
+ words[0][at] = int32Word(value);
134
+ },
135
+ accept,
136
+ };
137
+ case "bigint":
138
+ return {
139
+ width: 2,
140
+ write: (value, words, at) => {
141
+ if (typeof value === "number")
142
+ writeInt64(value, words[0], words[1], at);
143
+ else
144
+ writeBigInt64(BigInt(value), words[0], words[1], at);
145
+ },
146
+ accept,
147
+ };
148
+ case "decimal": {
149
+ const scale = column.scale ?? 0;
150
+ const precision = column.precision ?? 38;
151
+ // Unscaled integers of up to 18 digits fit 64 bits; those of up to 15 digits are safe integers.
152
+ const wide = precision > 18;
153
+ return {
154
+ width: wide ? 4 : 2,
155
+ write: (value, words, at) => {
156
+ const digits = value.replace(".", "");
157
+ if (wide)
158
+ writeBigInt128(BigInt(digits), words, at);
159
+ else if (digits.length <= 15)
160
+ writeInt64(Number(digits), words[0], words[1], at);
161
+ else
162
+ writeBigInt64(BigInt(digits), words[0], words[1], at);
163
+ },
164
+ // A key is looked up by its unscaled digits at the column's scale.
165
+ accept: (value) => {
166
+ const digits = typeof value === "string" ? unscaledDigits(value, scale) : null;
167
+ return digits !== null && digits.replace(/^-?0*/, "").length <= precision ? digits : null;
168
+ },
169
+ };
170
+ }
171
+ case "float": {
172
+ // The values of 32-bit columns are the 32-bit floats that blocks carry (§8.4).
173
+ const single = column.bits === 32;
174
+ return {
175
+ width: 2,
176
+ write: (value, words, at) => {
177
+ const number = floatOf(value);
178
+ writeFloat(single ? Math.fround(number) : number, words[0], words[1], at);
179
+ },
180
+ accept,
181
+ };
182
+ }
183
+ case "date":
184
+ return {
185
+ width: 1,
186
+ write: (value, words, at) => {
187
+ words[0][at] = int32Word(daysAt(value, 0));
188
+ },
189
+ accept,
190
+ };
191
+ case "time":
192
+ return {
193
+ width: 2,
194
+ write: (value, words, at) => {
195
+ const text = value;
196
+ writeInt64(secondsAt(text, 0) * 1_000_000 + fractionAt(text, 8, 6), words[0], words[1], at);
197
+ },
198
+ accept,
199
+ };
200
+ case "timestamp":
201
+ case "timestamptz":
202
+ // Seconds since 1970-01-01 in two words, then the nanoseconds of the second, whatever the unit.
203
+ return {
204
+ width: 3,
205
+ write: (value, words, at) => {
206
+ const text = value;
207
+ writeInt64(daysAt(text, 0) * 86_400 + secondsAt(text, 11), words[0], words[1], at);
208
+ words[2][at] = fractionAt(text, 19, 9);
209
+ },
210
+ accept,
211
+ };
212
+ case "interval":
213
+ // The months (64 bits), the days (0 to 29) and the nanoseconds (64 bits) of normalizeInterval.
214
+ return {
215
+ width: 5,
216
+ write: (value, words, at) => {
217
+ const [months, days, nanos] = normalizeInterval(value);
218
+ writeBigInt64(months, words[0], words[1], at);
219
+ words[2][at] = int32Word(Number(days));
220
+ writeBigInt64(nanos, words[3], words[4], at);
221
+ },
222
+ accept: (value) => {
223
+ const parts = typeof value === "string" ? normalizeInterval(value) : null;
224
+ return parts && parts[0] >= INT64_MIN && parts[0] <= INT64_MAX ? value : null;
225
+ },
226
+ };
227
+ case "uuid":
228
+ return {
229
+ width: 4,
230
+ write: (value, words, at) => {
231
+ const hex = value.replaceAll("-", "");
232
+ for (let word = 0; word < 4; word++) {
233
+ words[word][at] = Number.parseInt(hex.slice(word * 8, word * 8 + 8), 16);
234
+ }
235
+ },
236
+ accept,
237
+ };
238
+ default:
239
+ throw new TypeError(`${column.type} values are not written as words.`);
240
+ }
241
+ }
242
+ /**
243
+ * Sorts rows by their words, most significant first, compared as unsigned integers: a least significant digit
244
+ * radix sort with 16-bit digits, which keeps the order of `rows` among rows with the same words.
245
+ */
246
+ function radixSort(rows, words) {
247
+ const length = rows.length;
248
+ let order = rows.slice();
249
+ if (length < 2)
250
+ return order;
251
+ let spare = new Uint32Array(length);
252
+ const counts = new Uint32Array(65_536);
253
+ for (let index = words.length - 1; index >= 0; index--) {
254
+ const word = words[index];
255
+ for (let shift = 0; shift < 32; shift += 16) {
256
+ counts.fill(0);
257
+ for (let at = 0; at < length; at++)
258
+ counts[(word[order[at]] >>> shift) & 0xffff]++;
259
+ // A digit that every row shares changes nothing.
260
+ if (counts[(word[order[0]] >>> shift) & 0xffff] === length)
261
+ continue;
262
+ let total = 0;
263
+ for (let digit = 0; digit < 65_536; digit++) {
264
+ const count = counts[digit];
265
+ counts[digit] = total;
266
+ total += count;
267
+ }
268
+ for (let at = 0; at < length; at++) {
269
+ const row = order[at];
270
+ spare[counts[(word[row] >>> shift) & 0xffff]++] = row;
271
+ }
272
+ [order, spare] = [spare, order];
273
+ }
274
+ }
275
+ return order;
276
+ }
277
+ /**
278
+ * Ranks a column of fixed width through its words: written by `write` from the numbers that hold its values
279
+ * when it is given (for an Arrow table's column), otherwise from their JSON.
280
+ */
281
+ function rankWords(column, values, write) {
282
+ const codec = codecOf(column);
283
+ const count = values.length;
284
+ const words = Array.from({ length: codec.width }, () => new Uint32Array(count));
285
+ const filled = new Uint32Array(count);
286
+ let present = 0;
287
+ // No closure here reads `values`, which `rankOf` would keep with the scope it shares.
288
+ const validity = values.validity ?? null;
289
+ if (write) {
290
+ for (let row = 0; row < count; row++) {
291
+ if (validity !== null && ((validity[row >> 3] >> (row & 7)) & 1) === 0)
292
+ continue;
293
+ write(row, words, row);
294
+ filled[present++] = row;
295
+ }
296
+ }
297
+ else {
298
+ for (let row = 0; row < count; row++) {
299
+ const value = values.at(row);
300
+ if (value === null)
301
+ continue;
302
+ codec.write(value, words, row);
303
+ filled[present++] = row;
304
+ }
305
+ }
306
+ const order = radixSort(filled.subarray(0, present), words);
307
+ const ranks = new Uint32Array(count);
308
+ // The words of each distinct value, in ascending order, for rankOf.
309
+ const distinctWords = words.map(() => new Uint32Array(present));
310
+ let distinct = 0;
311
+ for (let at = 0; at < present; at++) {
312
+ const row = order[at];
313
+ const previous = at > 0 ? order[at - 1] : -1;
314
+ if (previous < 0 || words.some((word) => word[row] !== word[previous])) {
315
+ for (let which = 0; which < words.length; which++)
316
+ distinctWords[which][distinct] = words[which][row];
317
+ distinct++;
318
+ }
319
+ ranks[row] = distinct - 1;
320
+ }
321
+ if (present < count) {
322
+ for (let row = 0; row < count; row++) {
323
+ const blank = write
324
+ ? validity !== null && ((validity[row >> 3] >> (row & 7)) & 1) === 0
325
+ : values.at(row) === null;
326
+ if (blank)
327
+ ranks[row] = distinct + 1;
328
+ }
329
+ }
330
+ const key = words.map(() => new Uint32Array(1));
331
+ return {
332
+ ranks,
333
+ distinct,
334
+ rankOf(value) {
335
+ const accepted = value === null ? null : codec.accept(value);
336
+ if (accepted === null)
337
+ return -1;
338
+ codec.write(accepted, key, 0);
339
+ let low = 0;
340
+ let high = distinct - 1;
341
+ while (low <= high) {
342
+ const middle = (low + high) >>> 1;
343
+ let difference = 0;
344
+ for (let which = 0; which < key.length && difference === 0; which++) {
345
+ difference = distinctWords[which][middle] - key[which][0];
346
+ }
347
+ if (difference === 0)
348
+ return middle;
349
+ if (difference < 0)
350
+ low = middle + 1;
351
+ else
352
+ high = middle - 1;
353
+ }
354
+ return -1;
355
+ },
356
+ };
357
+ }
358
+ const SURROGATE = /[\uD800-\uDFFF]/;
359
+ const HIGH_UNITS = /[\uD800-￿]/g;
360
+ /**
361
+ * The string with its UTF-16 units from U+D800 moved so that comparing units compares code points (§3.1):
362
+ * units from U+E000 go down by 0x800 and surrogates up by 0x2000, after every other unit. For Unicode text
363
+ * (surrogates in pairs), the first unit that differs then decides as the code points do.
364
+ */
365
+ function codePointKey(text) {
366
+ return text.replace(HIGH_UNITS, (unit) => {
367
+ const code = unit.charCodeAt(0);
368
+ return String.fromCharCode(code >= 0xe000 ? code - 0x800 : code + 0x2000);
369
+ });
370
+ }
371
+ /** Bytes as a string of one unit per byte, which compares as the bytes do. */
372
+ function byteString(bytes) {
373
+ let text = "";
374
+ for (let start = 0; start < bytes.length; start += 0x8000) {
375
+ text += String.fromCharCode(...bytes.subarray(start, start + 0x8000));
376
+ }
377
+ return text;
378
+ }
379
+ /** Text is ranked in steps of this many rows (a power of two), between which `rankColumnPausing` pauses. */
380
+ const STEP_ROWS = 32_768;
381
+ /**
382
+ * Rows sorted by their keys. A function of its own, so that the comparison's closure does not keep the keys of every
383
+ * row with `rankOf`, which shares the scope of the function that ranks.
384
+ */
385
+ function sortRun(rows, keys) {
386
+ rows.sort((a, b) => {
387
+ const x = keys[a];
388
+ const y = keys[b];
389
+ return x < y ? -1 : x > y ? 1 : 0;
390
+ });
391
+ }
392
+ /** Rows sorted by their keys in steps: runs of `STEP_ROWS` rows sorted, then merged. */
393
+ function* sortByText(rows, keys) {
394
+ const count = rows.length;
395
+ for (let start = 0; start < count; start += STEP_ROWS) {
396
+ sortRun(rows.subarray(start, start + STEP_ROWS), keys);
397
+ yield;
398
+ }
399
+ let from = rows;
400
+ let to = new Uint32Array(count);
401
+ for (let width = STEP_ROWS; width < count; width *= 2) {
402
+ for (let start = 0; start < count; start += 2 * width) {
403
+ const middle = Math.min(start + width, count);
404
+ const end = Math.min(middle + width, count);
405
+ let left = start;
406
+ let right = middle;
407
+ let at = start;
408
+ while (left < middle && right < end) {
409
+ to[at++] = keys[from[right]] < keys[from[left]] ? from[right++] : from[left++];
410
+ if ((at & (STEP_ROWS - 1)) === 0)
411
+ yield;
412
+ }
413
+ to.set(from.subarray(left, middle), at);
414
+ to.set(from.subarray(right, end), at + middle - left);
415
+ }
416
+ [from, to] = [to, from];
417
+ }
418
+ return from;
419
+ }
420
+ /** Ranks a column of strings by their code points, or of binary values by their bytes, in steps. */
421
+ function* rankTexts(column, values) {
422
+ const strings = column.type === "string";
423
+ const count = values.length;
424
+ // Each value is read once: the rows that have no key are null, or empty strings marked in `blank`.
425
+ const keys = new Array(count);
426
+ const blank = new Uint8Array(count);
427
+ const filled = new Uint32Array(count);
428
+ let present = 0;
429
+ let empty = false;
430
+ let surrogates = false;
431
+ for (let row = 0; row < count; row++) {
432
+ if ((row & (STEP_ROWS - 1)) === STEP_ROWS - 1)
433
+ yield;
434
+ const value = values.at(row);
435
+ if (value === null)
436
+ continue;
437
+ if (strings && value === "") {
438
+ empty = true;
439
+ blank[row] = 1;
440
+ continue;
441
+ }
442
+ const text = value;
443
+ if (strings && !surrogates)
444
+ surrogates = SURROGATE.test(text);
445
+ keys[row] = strings ? text : byteString(fromBase64(text));
446
+ filled[present++] = row;
447
+ }
448
+ // Without surrogates, comparing UTF-16 units already compares code points.
449
+ if (surrogates) {
450
+ for (let at = 0; at < present; at++)
451
+ keys[filled[at]] = codePointKey(keys[filled[at]]);
452
+ }
453
+ const order = yield* sortByText(filled.subarray(0, present), keys);
454
+ const ranks = new Uint32Array(count);
455
+ const distinctKeys = [];
456
+ for (let at = 0; at < present; at++) {
457
+ if ((at & (STEP_ROWS - 1)) === STEP_ROWS - 1)
458
+ yield;
459
+ const key = keys[order[at]];
460
+ if (at === 0 || key !== distinctKeys[distinctKeys.length - 1])
461
+ distinctKeys.push(key);
462
+ ranks[order[at]] = distinctKeys.length - 1;
463
+ }
464
+ const distinct = distinctKeys.length;
465
+ if (present < count) {
466
+ for (let row = 0; row < count; row++)
467
+ if (keys[row] === undefined)
468
+ ranks[row] = blank[row] ? distinct : distinct + 1;
469
+ }
470
+ return {
471
+ ranks,
472
+ distinct,
473
+ rankOf(value) {
474
+ if (typeof value !== "string" || !isValueOf(value, column))
475
+ return -1;
476
+ if (strings && value === "")
477
+ return empty ? distinct : -1;
478
+ let key = strings ? value : byteString(fromBase64(value));
479
+ if (surrogates)
480
+ key = codePointKey(key);
481
+ let low = 0;
482
+ let high = distinct - 1;
483
+ while (low <= high) {
484
+ const middle = (low + high) >>> 1;
485
+ const other = distinctKeys[middle];
486
+ if (other === key)
487
+ return middle;
488
+ if (other < key)
489
+ low = middle + 1;
490
+ else
491
+ high = middle - 1;
492
+ }
493
+ return -1;
494
+ },
495
+ };
496
+ }
497
+ /**
498
+ * Ranks the values of a column by row ID in the order of §3.1; blanks rank after the other values (§3.2). A column
499
+ * of fixed width that has numbers (`Vector.numbers`) is ranked from them by `write`, when it is given.
500
+ */
501
+ export function rankColumn(column, values, write = null) {
502
+ if (column.type !== "string" && column.type !== "binary")
503
+ return rankWords(column, values, write);
504
+ const steps = rankTexts(column, values);
505
+ for (;;) {
506
+ const step = steps.next();
507
+ if (step.done)
508
+ return step.value;
509
+ }
510
+ }
511
+ /**
512
+ * `rankColumn`, which calls `pause` between the steps of ranking text, where a million rows take about half a
513
+ * second: a request that ranks lets other messages in, and stops where `pause` throws.
514
+ */
515
+ export async function rankColumnPausing(column, values, write, pause) {
516
+ if (column.type !== "string" && column.type !== "binary")
517
+ return rankWords(column, values, write);
518
+ const steps = rankTexts(column, values);
519
+ for (;;) {
520
+ const step = steps.next();
521
+ if (step.done)
522
+ return step.value;
523
+ await pause();
524
+ }
525
+ }
526
+ /**
527
+ * Sorts rows by one key, keeping the order of `order` (row ID order when null) among rows that are equal for
528
+ * it: a counting sort whose buckets hold the values in the key's direction, then the blanks (§3.3).
529
+ */
530
+ function sortByKey(order, count, key) {
531
+ const { ranks, distinct } = key.ranks;
532
+ const last = distinct - 1;
533
+ const descending = key.descending;
534
+ const starts = new Uint32Array(distinct + 2);
535
+ for (let at = 0; at < count; at++) {
536
+ const rank = ranks[order ? order[at] : at];
537
+ starts[(rank > last ? distinct : descending ? last - rank : rank) + 1]++;
538
+ }
539
+ for (let bucket = 1; bucket <= distinct + 1; bucket++)
540
+ starts[bucket] += starts[bucket - 1];
541
+ const sorted = new Uint32Array(count);
542
+ for (let at = 0; at < count; at++) {
543
+ const row = order ? order[at] : at;
544
+ const rank = ranks[row];
545
+ sorted[starts[rank > last ? distinct : descending ? last - rank : rank]++] = row;
546
+ }
547
+ return sorted;
548
+ }
549
+ /**
550
+ * The row IDs of `count` rows in the order of the keys (§3.3): by the first key, ties by the next, and rows
551
+ * equal for every key in row ID order. The rows are the row IDs from 0, or those of `rows` (in row ID order)
552
+ * when it is given. Without keys, the rows as they are: null for the row IDs from 0.
553
+ */
554
+ export function sortRows(count, keys, rows = null) {
555
+ let order = rows;
556
+ const length = rows ? rows.length : count;
557
+ for (let index = keys.length - 1; index >= 0; index--)
558
+ order = sortByKey(order, length, keys[index]);
559
+ return order;
560
+ }
561
+ //# sourceMappingURL=order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order.js","sourceRoot":"","sources":["../src/order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAEL,aAAa,EACb,OAAO,EACP,UAAU,EACV,SAAS,EAET,iBAAiB,GAClB,MAAM,eAAe,CAAC;AA4BvB,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAC;AACpC,MAAM,OAAO,GAAG,WAAY,CAAC;AAC7B,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAC;AAChC,MAAM,SAAS,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC;AAC/B,MAAM,SAAS,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC;AAEjC,qFAAqF;AACrF,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,IAAiB,EAAE,GAAgB,EAAE,EAAU;IACvF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;I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