@osmix/core 0.1.10 → 0.3.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 (97) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENSE +21 -0
  3. package/README.md +136 -72
  4. package/dist/contracts.d.ts +27 -0
  5. package/dist/contracts.d.ts.map +1 -0
  6. package/dist/contracts.js +1 -0
  7. package/dist/contracts.js.map +1 -0
  8. package/dist/entities.d.ts +22 -2
  9. package/dist/entities.d.ts.map +1 -1
  10. package/dist/entities.js +54 -10
  11. package/dist/entities.js.map +1 -1
  12. package/dist/ids.d.ts +20 -5
  13. package/dist/ids.d.ts.map +1 -1
  14. package/dist/ids.js +87 -29
  15. package/dist/ids.js.map +1 -1
  16. package/dist/index.d.ts +7 -4
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +6 -4
  19. package/dist/index.js.map +1 -1
  20. package/dist/indirect-kd-index.d.ts +28 -0
  21. package/dist/indirect-kd-index.d.ts.map +1 -0
  22. package/dist/indirect-kd-index.js +163 -0
  23. package/dist/indirect-kd-index.js.map +1 -0
  24. package/dist/limits.d.ts +30 -0
  25. package/dist/limits.d.ts.map +1 -0
  26. package/dist/limits.js +51 -0
  27. package/dist/limits.js.map +1 -0
  28. package/dist/mocks.d.ts.map +1 -1
  29. package/dist/mocks.js.map +1 -1
  30. package/dist/nodes.d.ts +36 -15
  31. package/dist/nodes.d.ts.map +1 -1
  32. package/dist/nodes.js +185 -62
  33. package/dist/nodes.js.map +1 -1
  34. package/dist/osm.d.ts +60 -4
  35. package/dist/osm.d.ts.map +1 -1
  36. package/dist/osm.js +32 -6
  37. package/dist/osm.js.map +1 -1
  38. package/dist/relations.d.ts +11 -4
  39. package/dist/relations.d.ts.map +1 -1
  40. package/dist/relations.js +73 -29
  41. package/dist/relations.js.map +1 -1
  42. package/dist/renumber.d.ts +23 -0
  43. package/dist/renumber.d.ts.map +1 -0
  44. package/dist/renumber.js +64 -0
  45. package/dist/renumber.js.map +1 -0
  46. package/dist/stringtable.d.ts +2 -1
  47. package/dist/stringtable.d.ts.map +1 -1
  48. package/dist/stringtable.js +9 -14
  49. package/dist/stringtable.js.map +1 -1
  50. package/dist/tags.d.ts +45 -12
  51. package/dist/tags.d.ts.map +1 -1
  52. package/dist/tags.js +153 -27
  53. package/dist/tags.js.map +1 -1
  54. package/dist/typed-arrays.d.ts +63 -48
  55. package/dist/typed-arrays.d.ts.map +1 -1
  56. package/dist/typed-arrays.js +184 -107
  57. package/dist/typed-arrays.js.map +1 -1
  58. package/dist/ways.d.ts +52 -3
  59. package/dist/ways.d.ts.map +1 -1
  60. package/dist/ways.js +223 -46
  61. package/dist/ways.js.map +1 -1
  62. package/package.json +45 -31
  63. package/src/contracts.ts +29 -0
  64. package/src/entities.ts +242 -194
  65. package/src/ids.ts +278 -235
  66. package/src/index.ts +22 -13
  67. package/src/indirect-kd-index.ts +212 -0
  68. package/src/limits.ts +73 -0
  69. package/src/mocks.ts +114 -113
  70. package/src/nodes.ts +538 -397
  71. package/src/osm.ts +282 -207
  72. package/src/relations.ts +580 -558
  73. package/src/renumber.ts +80 -0
  74. package/src/stringtable.ts +189 -184
  75. package/src/tags.ts +406 -272
  76. package/src/typed-arrays.ts +307 -205
  77. package/src/types/geoflatbush.d.ts +28 -33
  78. package/src/ways.ts +577 -406
  79. package/test/entity-index-errors.test.ts +41 -0
  80. package/test/ids.bench.ts +33 -0
  81. package/test/ids.test.ts +122 -0
  82. package/test/limits.test.ts +83 -0
  83. package/test/memory.test.ts +29 -30
  84. package/test/no-shared-array-buffer.test.ts +41 -0
  85. package/test/nodes-spatial-index.test.ts +261 -0
  86. package/test/osm-bbox.test.ts +30 -0
  87. package/test/relations.bench.ts +32 -0
  88. package/test/relations.test.ts +124 -0
  89. package/test/renumber.test.ts +54 -0
  90. package/test/spatial-index-rebuild.test.ts +33 -0
  91. package/test/storage-compaction.test.ts +269 -0
  92. package/test/tags-search.test.ts +89 -56
  93. package/test/typed-arrays.test.ts +252 -132
  94. package/tsconfig.build.json +6 -6
  95. package/tsconfig.json +7 -7
  96. package/src/types/geokdbush.d.ts +0 -37
  97. package/src/types/kdbush.d.ts +0 -47
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @module
8
8
  */
9
+ import { isSharedArrayBuffer } from "@osmix/shared/backing-buffers";
9
10
  /**
10
11
  * Use SharedArrayBuffer if the runtime supports it, otherwise fall back to ArrayBuffer.
11
12
  * SharedArrayBuffer enables zero-copy transfer between workers.
@@ -13,6 +14,32 @@
13
14
  export const BufferConstructor = typeof SharedArrayBuffer !== "undefined"
14
15
  ? SharedArrayBuffer
15
16
  : ArrayBuffer;
17
+ /** Structured allocation failure suitable for transport across worker boundaries. */
18
+ export class TypedBufferAllocationError extends Error {
19
+ code = "TYPED_BUFFER_ALLOCATION_FAILED";
20
+ stage = "typed-buffer-allocation";
21
+ operation;
22
+ typedArray;
23
+ bufferType;
24
+ elementCount;
25
+ bytesPerElement;
26
+ requiredBytes;
27
+ constructor(args, cause) {
28
+ super(`${args.typedArray} ${args.operation} requires ${args.requiredBytes.toLocaleString()} bytes in a single ${args.bufferType === "shared-array-buffer" ? "SharedArrayBuffer" : "ArrayBuffer"}.`, { cause });
29
+ this.name = "TypedBufferAllocationError";
30
+ this.operation = args.operation;
31
+ this.typedArray = args.typedArray;
32
+ this.bufferType = args.bufferType;
33
+ this.elementCount = args.elementCount;
34
+ this.bytesPerElement = args.bytesPerElement;
35
+ this.requiredBytes = args.requiredBytes;
36
+ }
37
+ }
38
+ function getBufferType(BC) {
39
+ return typeof SharedArrayBuffer !== "undefined" && BC === SharedArrayBuffer
40
+ ? "shared-array-buffer"
41
+ : "array-buffer";
42
+ }
16
43
  /**
17
44
  * Float64Array for storing OSM IDs.
18
45
  *
@@ -21,55 +48,54 @@ export const BufferConstructor = typeof SharedArrayBuffer !== "undefined"
21
48
  * Float64Array allows typed array operations while maintaining precision.
22
49
  */
23
50
  export const IdArrayType = Float64Array;
51
+ const MiB = 2 ** 20;
52
+ /** Starting capacity of a new column. Growth is in place, so small columns stay small. */
53
+ const INITIAL_BYTES = 64 * 1024;
24
54
  /**
25
- * Uint32Array for storing array indices.
26
- *
27
- * Internal indices into typed arrays never exceed 2^32 elements,
28
- * so Uint32Array provides the best balance of range and memory efficiency.
55
+ * Address space a growing column reserves so that it grows in place, without copying.
56
+ * Reserved pages hold no memory until written. Chromium's V8 sandbox has room for about 250
57
+ * reservations of this size, and a load builds about 35 columns at once. A reservation that
58
+ * fails falls back to growing by reallocation.
29
59
  */
30
- export const IndexArrayType = Uint32Array;
31
- /**
32
- * Initial buffer size for ResizeableTypedArray.
33
- * 1 MiB provides reasonable initial capacity while avoiding excessive memory allocation.
34
- */
35
- export const DEFAULT_BUFFER_SIZE = 2 ** 20; // 1 MiB
60
+ const GROWTH_RESERVE_BYTES = 4 * 2 ** 30;
61
+ /** Above this size a column grows by 1.5× instead of 2×, so it overshoots less. */
62
+ const DOUBLING_LIMIT_BYTES = 256 * MiB;
36
63
  /**
37
64
  * Auto-expanding typed array wrapper.
38
65
  *
39
- * - `push()` appends elements, doubling buffer size as needed.
40
- * - `compact()` shrinks buffer to fit data.
41
- * - Supports growable SharedArrayBuffer and resizable ArrayBuffer.
66
+ * - `push()` / `pushMany()` append, growing the buffer in place when the runtime supports
67
+ * growable buffers, otherwise by reallocating.
68
+ * - `array` is a view of the stored items only; `compact()` shrinks the buffer to fit them.
69
+ * - `from()` wraps a finished (transferred) buffer, which can still grow.
42
70
  */
43
71
  export class ResizeableTypedArray {
44
72
  /** The typed array constructor for this instance */
45
73
  ArrayType;
46
- /** The current typed array view into the buffer */
47
- array;
48
- /** Number of items actually stored (may be less than array.length) */
49
- items = 0;
50
- /** The underlying ArrayBuffer or SharedArrayBuffer */
51
- buffer;
52
- /** Current buffer size in bytes */
53
- bufferSize;
54
- /** Maximum byte length for growable buffers */
55
- maxByteLength;
56
74
  /** Buffer constructor (SharedArrayBuffer or ArrayBuffer) */
57
75
  BC;
76
+ /** View of the whole buffer: stored items, then spare capacity. */
77
+ view;
78
+ /** Number of items actually stored (may be less than the capacity). */
79
+ items = 0;
58
80
  /**
59
- * Reconstruct a ResizeableTypedArray from an existing buffer.
60
- *
61
- * Used after transferring buffers between workers. The resulting array
62
- * is considered "compacted" with items = array.length.
63
- *
64
- * @param ArrayType - The typed array constructor.
65
- * @param buffer - The existing buffer to wrap.
66
- * @returns A new ResizeableTypedArray wrapping the buffer.
81
+ * The buffer size a new column reaches when it is filled one `push` at a time to
82
+ * `requiredBytes`, for projecting peak memory before a load.
83
+ */
84
+ static capacityBytesFor(requiredBytes, bytesPerElement) {
85
+ let bytes = INITIAL_BYTES;
86
+ while (bytes < requiredBytes) {
87
+ bytes = nextByteLength(bytes, bytes + bytesPerElement, bytesPerElement);
88
+ }
89
+ return bytes;
90
+ }
91
+ /**
92
+ * Wrap an existing buffer, as after transferring it between workers. Every element of the
93
+ * buffer is a stored item. Nothing is allocated until the array grows.
67
94
  */
68
95
  static from(ArrayType, buffer) {
69
- const rta = new ResizeableTypedArray(ArrayType, buffer instanceof SharedArrayBuffer ? SharedArrayBuffer : ArrayBuffer);
70
- rta.buffer = buffer;
71
- rta.array = new ArrayType(buffer);
72
- rta.items = rta.array.length;
96
+ const BC = isSharedArrayBuffer(buffer) ? SharedArrayBuffer : ArrayBuffer;
97
+ const rta = new ResizeableTypedArray(ArrayType, BC, new ArrayType(buffer));
98
+ rta.items = rta.view.length;
73
99
  return rta;
74
100
  }
75
101
  /**
@@ -78,83 +104,56 @@ export class ResizeableTypedArray {
78
104
  * @param ArrayType - The typed array constructor (e.g., Float64Array).
79
105
  * @param BC - Buffer constructor to use (defaults to SharedArrayBuffer if available).
80
106
  */
81
- constructor(ArrayType, BC = BufferConstructor) {
107
+ constructor(ArrayType, BC = BufferConstructor,
108
+ /** @internal A view to wrap instead of allocating; used by `from()`. */
109
+ view) {
82
110
  this.ArrayType = ArrayType;
83
- this.bufferSize = DEFAULT_BUFFER_SIZE;
84
- this.maxByteLength = DEFAULT_BUFFER_SIZE * 2;
85
111
  this.BC = BC;
86
- this.buffer = new BC(this.bufferSize, {
87
- maxByteLength: this.maxByteLength,
88
- });
89
- this.array = new this.ArrayType(this.buffer);
112
+ this.view = view ?? new ArrayType(this.allocate("create", INITIAL_BYTES, GROWTH_RESERVE_BYTES));
90
113
  }
91
- /**
92
- * Iterate over the array values.
93
- */
114
+ /** The stored items. Before `compact()`, a view that excludes the spare capacity. */
115
+ get array() {
116
+ return this.items === this.view.length ? this.view : this.view.subarray(0, this.items);
117
+ }
118
+ /** The underlying buffer, including any spare capacity. */
119
+ get buffer() {
120
+ return this.view.buffer;
121
+ }
122
+ get length() {
123
+ return this.items;
124
+ }
125
+ /** Number of items the current buffer can hold before it must grow. */
126
+ get capacity() {
127
+ return this.view.length;
128
+ }
129
+ /** Iterate over the stored values. */
94
130
  [Symbol.iterator]() {
95
131
  return this.array[Symbol.iterator]();
96
132
  }
97
- /**
98
- * Double the buffer capacity.
99
- * Uses in-place grow/resize if supported, otherwise allocates new buffer and copies.
100
- */
101
- expandArray() {
102
- this.bufferSize *= 2;
103
- if (this.bufferSize > this.buffer.maxByteLength) {
104
- // Need a completely new buffer with larger maxByteLength
105
- this.maxByteLength *= 2;
106
- const newBuffer = new this.BC(this.bufferSize, {
107
- maxByteLength: this.maxByteLength,
108
- });
109
- const newArray = new this.ArrayType(newBuffer);
110
- newArray.set(this.array);
111
- this.buffer = newBuffer;
112
- this.array = newArray;
113
- }
114
- else {
115
- // Can grow/resize the existing buffer in place
116
- if (this.buffer instanceof SharedArrayBuffer && this.buffer.growable) {
117
- this.buffer.grow(this.bufferSize);
118
- }
119
- else if (this.buffer instanceof ArrayBuffer && this.buffer.resizable) {
120
- this.buffer.resize(this.bufferSize);
121
- }
122
- else {
123
- throw Error("Buffer is not growable or resizable");
124
- }
125
- }
126
- }
127
133
  /**
128
134
  * Get the value at an index. Handles negative indices.
129
135
  */
130
136
  at(index) {
131
- if (index < -this.length || index >= this.length)
132
- throw Error(`Index out of bounds: ${index}. Length: ${this.length}`);
133
- if (index < 0)
134
- return this.at(this.length + index);
135
- const result = this.array[index];
136
- if (result === undefined)
137
- throw Error(`No value at index: ${index}`);
138
- return result;
137
+ if (index >= 0 && index < this.items)
138
+ return this.view[index];
139
+ if (index < 0 && index >= -this.items)
140
+ return this.view[this.items + index];
141
+ throw Error(`Index out of bounds: ${index}. Length: ${this.items}`);
139
142
  }
140
143
  /**
141
- * Get a slice of the array.
144
+ * Get a copy of a range of the stored items.
142
145
  */
143
146
  slice(start, end) {
144
147
  return this.array.slice(start, end);
145
148
  }
146
- get length() {
147
- return this.items;
148
- }
149
149
  /**
150
150
  * Push a value to the end of the array.
151
151
  */
152
152
  push(value) {
153
- if (this.length >= this.array.length) {
154
- this.expandArray();
155
- }
156
- this.array[this.items++] = value;
157
- return this.length - 1;
153
+ if (this.items === this.view.length)
154
+ this.ensureCapacity(this.items + 1);
155
+ this.view[this.items] = value;
156
+ return this.items++;
158
157
  }
159
158
  /**
160
159
  * Set a value at a specific index. Expands array if needed.
@@ -162,20 +161,18 @@ export class ResizeableTypedArray {
162
161
  set(index, value) {
163
162
  if (index < 0)
164
163
  throw Error("Index out of bounds");
165
- if (index >= this.length) {
166
- while (index >= this.array.length)
167
- this.expandArray();
164
+ if (index >= this.items) {
165
+ this.ensureCapacity(index + 1);
168
166
  this.items = index + 1;
169
167
  }
170
- this.array[index] = value;
168
+ this.view[index] = value;
171
169
  }
172
170
  /**
173
171
  * Push multiple values to the end of the array.
174
172
  */
175
173
  pushMany(values) {
176
- while (this.length + values.length > this.array.length)
177
- this.expandArray();
178
- this.array.set(values, this.length);
174
+ this.ensureCapacity(this.items + values.length);
175
+ this.view.set(values, this.items);
179
176
  this.items += values.length;
180
177
  }
181
178
  /**
@@ -183,16 +180,96 @@ export class ResizeableTypedArray {
183
180
  * Buffer becomes fixed-length after compacting.
184
181
  */
185
182
  compact() {
186
- if (this.buffer instanceof SharedArrayBuffer) {
187
- // SharedArrayBuffer uses slice() to create a new fixed-size buffer
188
- this.buffer = this.buffer.slice(0, this.length * this.ArrayType.BYTES_PER_ELEMENT);
183
+ const requiredBytes = this.items * this.ArrayType.BYTES_PER_ELEMENT;
184
+ const buffer = this.buffer;
185
+ let compacted;
186
+ try {
187
+ compacted = isSharedArrayBuffer(buffer)
188
+ ? // A SharedArrayBuffer cannot shrink: copy the items into a fixed-size buffer.
189
+ buffer.slice(0, requiredBytes)
190
+ : buffer.transferToFixedLength(requiredBytes);
191
+ }
192
+ catch (cause) {
193
+ throw this.allocationError("compact", requiredBytes, cause);
194
+ }
195
+ this.view = new this.ArrayType(compacted);
196
+ return this.view;
197
+ }
198
+ /** Make room for `count` items: grow in place if the buffer can, otherwise reallocate. */
199
+ ensureCapacity(count) {
200
+ if (count <= this.view.length)
201
+ return;
202
+ const bytesPerElement = this.ArrayType.BYTES_PER_ELEMENT;
203
+ const buffer = this.buffer;
204
+ const byteLength = nextByteLength(buffer.byteLength, count * bytesPerElement, bytesPerElement);
205
+ if (buffer.maxByteLength >= byteLength && growInPlace(buffer, byteLength)) {
206
+ // A resized buffer keeps a length-tracking view: take a fresh fixed-length one.
207
+ this.view = new this.ArrayType(buffer, 0, byteLength / bytesPerElement);
208
+ return;
209
+ }
210
+ const next = this.allocate("grow", byteLength, GROWTH_RESERVE_BYTES);
211
+ const view = new this.ArrayType(next, 0, byteLength / bytesPerElement);
212
+ view.set(this.array);
213
+ this.view = view;
214
+ }
215
+ /**
216
+ * Allocate `byteLength` bytes that can grow in place up to `reserveBytes` when the runtime
217
+ * allows. A failed reservation falls back to a buffer that doubles once, then to fixed size.
218
+ */
219
+ allocate(operation, byteLength, reserveBytes) {
220
+ for (const maxByteLength of [Math.max(reserveBytes, byteLength), byteLength * 2]) {
221
+ try {
222
+ return new this.BC(byteLength, { maxByteLength });
223
+ }
224
+ catch {
225
+ // The runtime refused the reservation: try a smaller one, then a fixed buffer.
226
+ }
189
227
  }
190
- else {
191
- // ArrayBuffer uses transferToFixedLength() to detach and resize
192
- this.buffer = this.buffer.transferToFixedLength(this.length * this.ArrayType.BYTES_PER_ELEMENT);
228
+ try {
229
+ return new this.BC(byteLength);
193
230
  }
194
- this.array = new this.ArrayType(this.buffer);
195
- return this.array;
231
+ catch (cause) {
232
+ throw this.allocationError(operation, byteLength, cause);
233
+ }
234
+ }
235
+ allocationError(operation, requiredBytes, cause) {
236
+ return new TypedBufferAllocationError({
237
+ operation,
238
+ typedArray: this.ArrayType.name,
239
+ bufferType: getBufferType(this.BC),
240
+ elementCount: Math.ceil(requiredBytes / this.ArrayType.BYTES_PER_ELEMENT),
241
+ bytesPerElement: this.ArrayType.BYTES_PER_ELEMENT,
242
+ requiredBytes,
243
+ }, cause);
244
+ }
245
+ }
246
+ /**
247
+ * The next buffer size for a column that needs `requiredBytes`: double while small, then grow
248
+ * by 1.5×, and never less than required. Rounded up to a multiple of 8 bytes so every element
249
+ * type divides it.
250
+ */
251
+ function nextByteLength(currentBytes, requiredBytes, bytesPerElement) {
252
+ const current = Math.max(currentBytes, bytesPerElement);
253
+ const grown = current < DOUBLING_LIMIT_BYTES ? current * 2 : Math.ceil(current * 1.5);
254
+ return Math.ceil(Math.max(grown, requiredBytes) / 8) * 8;
255
+ }
256
+ /** Grow a growable or resizable buffer to `byteLength`. False if it cannot grow in place. */
257
+ function growInPlace(buffer, byteLength) {
258
+ try {
259
+ if (isSharedArrayBuffer(buffer)) {
260
+ if (!buffer.growable)
261
+ return false;
262
+ buffer.grow(byteLength);
263
+ return true;
264
+ }
265
+ if (!buffer.resizable)
266
+ return false;
267
+ buffer.resize(byteLength);
268
+ return true;
269
+ }
270
+ catch {
271
+ // Committing the pages failed: fall back to reallocating, which reports its own error.
272
+ return false;
196
273
  }
197
274
  }
198
275
  //# sourceMappingURL=typed-arrays.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typed-arrays.js","sourceRoot":"","sources":["../src/typed-arrays.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA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CAAC,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC;YACzE,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB;YACjD,aAAa;SACd,EACD,KAAK,CACN,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,YAAoB,EAAE,aAAqB,EAAE,eAAuB;IAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IACxD,MAAM,KAAK,GAAG,OAAO,GAAG,oBAAoB,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,6FAA6F;AAC7F,SAAS,WAAW,CAAC,MAAkB,EAAE,UAAkB;IACzD,IAAI,CAAC;QACH,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,QAAQ;gBAAE,OAAO,KAAK,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,OAAO,KAAK,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,uFAAuF;QACvF,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
package/dist/ways.d.ts CHANGED
@@ -1,16 +1,26 @@
1
1
  import type { OsmPbfWay } from "@osmix/pbf";
2
2
  import type { ContentHasher } from "@osmix/shared/content-hasher";
3
- import type { GeoBbox2D, LonLat, OsmTags, OsmWay } from "@osmix/shared/types";
3
+ import type { GeoBbox2D, LonLat, OsmTags, OsmWay } from "@osmix/types";
4
4
  import Flatbush from "flatbush";
5
5
  import { Entities, type EntitiesTransferables } from "./entities.ts";
6
6
  import { type IdOrIndex } from "./ids.ts";
7
7
  import type { Nodes } from "./nodes.ts";
8
8
  import type StringTable from "./stringtable.ts";
9
9
  import { type BufferType } from "./typed-arrays.ts";
10
+ /**
11
+ * Node-index sentinel stored for way refs whose node is not present in the dataset.
12
+ * Returned by {@link Ways.getRefIndexes} in place of a node index.
13
+ */
14
+ export declare const MISSING_NODE_INDEX = 4294967295;
10
15
  export interface WaysTransferables<T extends BufferType = BufferType> extends EntitiesTransferables<T> {
11
16
  refStart: T;
12
17
  refCount: T;
18
+ /** Node indexes, with `0xffffffff` marking an unresolved reference. */
13
19
  refs: T;
20
+ /** Sorted positions in `refs` whose node ID could not be resolved. */
21
+ missingRefPositions: T;
22
+ /** OSM node IDs parallel to `missingRefPositions`. */
23
+ missingRefIds: T;
14
24
  bbox: T;
15
25
  /** Optional - can be rebuilt via buildSpatialIndex() */
16
26
  spatialIndex?: T;
@@ -21,8 +31,14 @@ export declare class Ways extends Entities<OsmWay> {
21
31
  private refStart;
22
32
  private refCount;
23
33
  private refs;
34
+ private missingRefPositions;
35
+ private missingRefIds;
36
+ private pendingRefIds;
24
37
  private bbox;
25
38
  private nodes;
39
+ private getNodeLonLat;
40
+ /** Resolve a reference position to coordinates, or null when the node is absent. */
41
+ private tryGetNodeLonLat;
26
42
  /**
27
43
  * Create a new Ways index.
28
44
  */
@@ -34,14 +50,20 @@ export declare class Ways extends Entities<OsmWay> {
34
50
  /**
35
51
  * Bulk add ways directly from a PBF PrimitiveBlock.
36
52
  */
37
- addWays(ways: OsmPbfWay[], blockStringIndexMap: Uint32Array, filter?: (way: OsmWay) => OsmWay | null): number;
53
+ addWays(ways: OsmPbfWay[], blockStringIndexMap: Uint32Array, filter?: (way: OsmWay) => OsmWay | null, nodeIdToIndex?: (nodeId: number) => number): number;
38
54
  /**
39
55
  * Compact the internal arrays to free up memory.
56
+ *
57
+ * Must run after the node ID index is built (`Osm.buildIndexes()` orders
58
+ * nodes before ways) so pending OSM node IDs resolve to compact `Uint32`
59
+ * node indexes. If the node index is not ready, every pending ref degrades
60
+ * to the larger missing-ref representation (sentinel + sorted ID lookup).
40
61
  */
41
62
  buildEntityIndex(): void;
42
63
  /**
43
64
  * Build the spatial index for ways.
44
65
  * If bbox data already exists (e.g., loaded from storage), reuses it.
66
+ * Returns the existing index when it is already built.
45
67
  */
46
68
  buildSpatialIndex(): Flatbush;
47
69
  /**
@@ -56,6 +78,13 @@ export declare class Ways extends Entities<OsmWay> {
56
78
  * Get the node IDs referenced by a way.
57
79
  */
58
80
  getRefIds(index: number): number[];
81
+ /**
82
+ * Get the node indexes referenced by a way without allocating.
83
+ *
84
+ * Returns a view into internal storage; do not mutate it or hold it across writes. Refs to
85
+ * nodes absent from the dataset are {@link MISSING_NODE_INDEX}. Requires `buildEntityIndex()`.
86
+ */
87
+ getRefIndexes(index: number): Uint32Array;
59
88
  /**
60
89
  * Get the bounding box of a way.
61
90
  */
@@ -66,8 +95,16 @@ export declare class Ways extends Entities<OsmWay> {
66
95
  getLine(index: number): Float64Array<ArrayBuffer>;
67
96
  /**
68
97
  * Get the coordinates of a way as an array of [lon, lat] pairs.
98
+ * Throws when a referenced node cannot be resolved; use
99
+ * `getResolvedCoordinates()` for tolerant consumers such as bbox building.
69
100
  */
70
101
  getCoordinates(index: number): LonLat[];
102
+ /**
103
+ * Get the resolvable coordinates of a way, skipping missing node refs.
104
+ * Preferred over `getCoordinates()` when partial geometry is acceptable,
105
+ * e.g. computing bounding boxes over referentially incomplete extracts.
106
+ */
107
+ getResolvedCoordinates(index: number): LonLat[];
71
108
  /**
72
109
  * Find way indexes that intersect a bounding box.
73
110
  */
@@ -97,10 +134,22 @@ export declare class Ways extends Entities<OsmWay> {
97
134
  /**
98
135
  * Get the approximate memory requirements for a given number of ways in bytes.
99
136
  */
100
- static getBytesRequired(count: number): number;
137
+ static getBytesRequired(count: number, refCount?: number, missingRefCount?: number, tagCount?: number): number;
101
138
  /**
102
139
  * Update a ContentHasher with way-specific data (node references).
103
140
  */
104
141
  updateHash(hasher: ContentHasher): ContentHasher;
142
+ /** Logical reference length during either pending-ID or indexed ingestion. */
143
+ /** Reject a way whose ref count would wrap `refCount` or the `refStart` offsets. */
144
+ private assertRefCapacity;
145
+ private get refLength();
146
+ /** Append OSM node IDs, optionally resolving them directly to node indexes. */
147
+ private appendRefIds;
148
+ /** Store one resolved or losslessly preserved missing reference. */
149
+ private setIndexedRef;
150
+ /** Reconstruct the public OSM node ID for one internal reference position. */
151
+ private getRefId;
152
+ /** Find the OSM node ID for a sentinel reference position. */
153
+ private getMissingRefId;
105
154
  }
106
155
  //# sourceMappingURL=ways.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ways.d.ts","sourceRoot":"","sources":["../src/ways.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC7E,OAAO,QAAQ,MAAM,UAAU,CAAA;AAE/B,OAAO,EAAE,QAAQ,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,KAAK,SAAS,EAAO,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAEN,KAAK,UAAU,EAGf,MAAM,mBAAmB,CAAA;AAE1B,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CACnE,SAAQ,qBAAqB,CAAC,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