spliterator 6.0.1 → 6.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 (195) hide show
  1. package/README.md +70 -0
  2. package/out/index.d.ts +26 -23
  3. package/out/index.d.ts.map +1 -1
  4. package/out/index.js +26 -23
  5. package/out/index.js.map +1 -1
  6. package/out/lib/AsyncSpliterator.d.ts.map +1 -1
  7. package/out/lib/AsyncSpliterator.js +28 -0
  8. package/out/lib/AsyncSpliterator.js.map +1 -1
  9. package/out/lib/CSVSpliterator.d.ts +8 -18
  10. package/out/lib/CSVSpliterator.d.ts.map +1 -1
  11. package/out/lib/CSVSpliterator.js +4 -47
  12. package/out/lib/CSVSpliterator.js.map +1 -1
  13. package/out/lib/CharacterSequence.d.ts +16 -1
  14. package/out/lib/CharacterSequence.d.ts.map +1 -1
  15. package/out/lib/CharacterSequence.js +37 -0
  16. package/out/lib/CharacterSequence.js.map +1 -1
  17. package/out/lib/XLSXSpliterator.d.ts +143 -0
  18. package/out/lib/XLSXSpliterator.d.ts.map +1 -0
  19. package/out/lib/XLSXSpliterator.js +161 -0
  20. package/out/lib/XLSXSpliterator.js.map +1 -0
  21. package/out/lib/core/AsyncSpliterator.d.ts +227 -0
  22. package/out/lib/core/AsyncSpliterator.d.ts.map +1 -0
  23. package/out/lib/core/AsyncSpliterator.js +510 -0
  24. package/out/lib/core/AsyncSpliterator.js.map +1 -0
  25. package/out/lib/core/BufferController.d.ts +77 -0
  26. package/out/lib/core/BufferController.d.ts.map +1 -0
  27. package/out/lib/core/BufferController.js +118 -0
  28. package/out/lib/core/BufferController.js.map +1 -0
  29. package/out/lib/core/CharacterSequence.d.ts +72 -0
  30. package/out/lib/core/CharacterSequence.d.ts.map +1 -0
  31. package/out/lib/core/CharacterSequence.js +347 -0
  32. package/out/lib/core/CharacterSequence.js.map +1 -0
  33. package/out/lib/core/CompositeDataView.d.ts +111 -0
  34. package/out/lib/core/CompositeDataView.d.ts.map +1 -0
  35. package/out/lib/core/CompositeDataView.js +241 -0
  36. package/out/lib/core/CompositeDataView.js.map +1 -0
  37. package/out/lib/core/IndexQueue.d.ts +48 -0
  38. package/out/lib/core/IndexQueue.d.ts.map +1 -0
  39. package/out/lib/core/IndexQueue.js +111 -0
  40. package/out/lib/core/IndexQueue.js.map +1 -0
  41. package/out/lib/core/SlidingWindow.d.ts +47 -0
  42. package/out/lib/core/SlidingWindow.d.ts.map +1 -0
  43. package/out/lib/core/SlidingWindow.js +63 -0
  44. package/out/lib/core/SlidingWindow.js.map +1 -0
  45. package/out/lib/core/Spliterator.d.ts +96 -0
  46. package/out/lib/core/Spliterator.d.ts.map +1 -0
  47. package/out/lib/core/Spliterator.js +330 -0
  48. package/out/lib/core/Spliterator.js.map +1 -0
  49. package/out/lib/core/wasm_base64.d.ts +19 -0
  50. package/out/lib/core/wasm_base64.d.ts.map +1 -0
  51. package/out/lib/core/wasm_base64.js +19 -0
  52. package/out/lib/core/wasm_base64.js.map +1 -0
  53. package/out/lib/core/wasm_module.d.ts +57 -0
  54. package/out/lib/core/wasm_module.d.ts.map +1 -0
  55. package/out/lib/core/wasm_module.js +34 -0
  56. package/out/lib/core/wasm_module.js.map +1 -0
  57. package/out/lib/formats/CSVSpliterator.d.ts +131 -0
  58. package/out/lib/formats/CSVSpliterator.d.ts.map +1 -0
  59. package/out/lib/formats/CSVSpliterator.js +172 -0
  60. package/out/lib/formats/CSVSpliterator.js.map +1 -0
  61. package/out/lib/formats/JSONSpliterator.d.ts +44 -0
  62. package/out/lib/formats/JSONSpliterator.d.ts.map +1 -0
  63. package/out/lib/formats/JSONSpliterator.js +77 -0
  64. package/out/lib/formats/JSONSpliterator.js.map +1 -0
  65. package/out/lib/formats/PSVSpliterator.d.ts +21 -0
  66. package/out/lib/formats/PSVSpliterator.d.ts.map +1 -0
  67. package/out/lib/formats/PSVSpliterator.js +22 -0
  68. package/out/lib/formats/PSVSpliterator.js.map +1 -0
  69. package/out/lib/formats/TSVSpliterator.d.ts +21 -0
  70. package/out/lib/formats/TSVSpliterator.d.ts.map +1 -0
  71. package/out/lib/formats/TSVSpliterator.js +22 -0
  72. package/out/lib/formats/TSVSpliterator.js.map +1 -0
  73. package/out/lib/formats/TextSpliterator.d.ts +53 -0
  74. package/out/lib/formats/TextSpliterator.d.ts.map +1 -0
  75. package/out/lib/formats/TextSpliterator.js +67 -0
  76. package/out/lib/formats/TextSpliterator.js.map +1 -0
  77. package/out/lib/formats/XLSXSpliterator.d.ts +143 -0
  78. package/out/lib/formats/XLSXSpliterator.d.ts.map +1 -0
  79. package/out/lib/formats/XLSXSpliterator.js +161 -0
  80. package/out/lib/formats/XLSXSpliterator.js.map +1 -0
  81. package/out/lib/formats/casing.d.ts +27 -0
  82. package/out/lib/formats/casing.d.ts.map +1 -0
  83. package/out/lib/formats/casing.js +68 -0
  84. package/out/lib/formats/casing.js.map +1 -0
  85. package/out/lib/formats/row-emitters.d.ts +35 -0
  86. package/out/lib/formats/row-emitters.d.ts.map +1 -0
  87. package/out/lib/formats/row-emitters.js +50 -0
  88. package/out/lib/formats/row-emitters.js.map +1 -0
  89. package/out/lib/internal/shared.d.ts +155 -0
  90. package/out/lib/internal/shared.d.ts.map +1 -0
  91. package/out/lib/internal/shared.js +41 -0
  92. package/out/lib/internal/shared.js.map +1 -0
  93. package/out/lib/internal/utils.d.ts +37 -0
  94. package/out/lib/internal/utils.d.ts.map +1 -0
  95. package/out/lib/internal/utils.js +39 -0
  96. package/out/lib/internal/utils.js.map +1 -0
  97. package/out/lib/io/adaptive-source.d.ts +39 -0
  98. package/out/lib/io/adaptive-source.d.ts.map +1 -0
  99. package/out/lib/io/adaptive-source.js +95 -0
  100. package/out/lib/io/adaptive-source.js.map +1 -0
  101. package/out/lib/io/writer.d.ts +45 -0
  102. package/out/lib/io/writer.d.ts.map +1 -0
  103. package/out/lib/io/writer.js +57 -0
  104. package/out/lib/io/writer.js.map +1 -0
  105. package/out/lib/iterators/AsyncSequence.d.ts +180 -0
  106. package/out/lib/iterators/AsyncSequence.d.ts.map +1 -0
  107. package/out/lib/iterators/AsyncSequence.js +432 -0
  108. package/out/lib/iterators/AsyncSequence.js.map +1 -0
  109. package/out/lib/iterators/chunks.d.ts +20 -0
  110. package/out/lib/iterators/chunks.d.ts.map +1 -0
  111. package/out/lib/iterators/chunks.js +36 -0
  112. package/out/lib/iterators/chunks.js.map +1 -0
  113. package/out/lib/iterators/pivot.d.ts +30 -0
  114. package/out/lib/iterators/pivot.d.ts.map +1 -0
  115. package/out/lib/iterators/pivot.js +47 -0
  116. package/out/lib/iterators/pivot.js.map +1 -0
  117. package/out/lib/iterators/zip.d.ts +33 -0
  118. package/out/lib/iterators/zip.d.ts.map +1 -0
  119. package/out/lib/iterators/zip.js +59 -0
  120. package/out/lib/iterators/zip.js.map +1 -0
  121. package/out/lib/parallel/merge-async-iterators.d.ts +12 -0
  122. package/out/lib/parallel/merge-async-iterators.d.ts.map +1 -0
  123. package/out/lib/parallel/merge-async-iterators.js +39 -0
  124. package/out/lib/parallel/merge-async-iterators.js.map +1 -0
  125. package/out/lib/parallel/parallel-map-runtime.d.ts +22 -0
  126. package/out/lib/parallel/parallel-map-runtime.d.ts.map +1 -0
  127. package/out/lib/parallel/parallel-map-runtime.js +60 -0
  128. package/out/lib/parallel/parallel-map-runtime.js.map +1 -0
  129. package/out/lib/parallel/parallel-map-worker-entry.d.ts +11 -0
  130. package/out/lib/parallel/parallel-map-worker-entry.d.ts.map +1 -0
  131. package/out/lib/parallel/parallel-map-worker-entry.js +41 -0
  132. package/out/lib/parallel/parallel-map-worker-entry.js.map +1 -0
  133. package/out/lib/parallel/parallel-map-workers.d.ts +57 -0
  134. package/out/lib/parallel/parallel-map-workers.d.ts.map +1 -0
  135. package/out/lib/parallel/parallel-map-workers.js +82 -0
  136. package/out/lib/parallel/parallel-map-workers.js.map +1 -0
  137. package/out/lib/parallel/parallel-map.d.ts +28 -0
  138. package/out/lib/parallel/parallel-map.d.ts.map +1 -0
  139. package/out/lib/parallel/parallel-map.js +30 -0
  140. package/out/lib/parallel/parallel-map.js.map +1 -0
  141. package/out/lib/parallel/segment-runtime.d.ts +27 -0
  142. package/out/lib/parallel/segment-runtime.d.ts.map +1 -0
  143. package/out/lib/parallel/segment-runtime.js +41 -0
  144. package/out/lib/parallel/segment-runtime.js.map +1 -0
  145. package/out/lib/parallel/segment-worker-entry.d.ts +10 -0
  146. package/out/lib/parallel/segment-worker-entry.d.ts.map +1 -0
  147. package/out/lib/parallel/segment-worker-entry.js +59 -0
  148. package/out/lib/parallel/segment-worker-entry.js.map +1 -0
  149. package/out/lib/parallel/segment-workers.d.ts +56 -0
  150. package/out/lib/parallel/segment-workers.d.ts.map +1 -0
  151. package/out/lib/parallel/segment-workers.js +110 -0
  152. package/out/lib/parallel/segment-workers.js.map +1 -0
  153. package/out/lib/parallel/segments.d.ts +31 -0
  154. package/out/lib/parallel/segments.d.ts.map +1 -0
  155. package/out/lib/parallel/segments.js +52 -0
  156. package/out/lib/parallel/segments.js.map +1 -0
  157. package/out/lib/row-emitters.d.ts +35 -0
  158. package/out/lib/row-emitters.d.ts.map +1 -0
  159. package/out/lib/row-emitters.js +50 -0
  160. package/out/lib/row-emitters.js.map +1 -0
  161. package/out/lib/wasm_base64.d.ts +4 -1
  162. package/out/lib/wasm_base64.d.ts.map +1 -1
  163. package/out/lib/wasm_base64.js +4 -1
  164. package/out/lib/wasm_base64.js.map +1 -1
  165. package/out/lib/wasm_module.d.ts +15 -0
  166. package/out/lib/wasm_module.d.ts.map +1 -1
  167. package/out/lib/wasm_module.js +2 -1
  168. package/out/lib/wasm_module.js.map +1 -1
  169. package/out/node/cli/commands/csv.d.ts +113 -0
  170. package/out/node/cli/commands/csv.d.ts.map +1 -1
  171. package/out/node/cli/commands/csv.js +34 -36
  172. package/out/node/cli/commands/csv.js.map +1 -1
  173. package/out/node/cli/commands/iterate.d.ts +92 -0
  174. package/out/node/cli/commands/iterate.d.ts.map +1 -1
  175. package/out/node/cli/commands/iterate.js +26 -28
  176. package/out/node/cli/commands/iterate.js.map +1 -1
  177. package/out/node/cli/commands/parallel.d.ts +102 -0
  178. package/out/node/cli/commands/parallel.d.ts.map +1 -0
  179. package/out/node/cli/commands/parallel.js +426 -0
  180. package/out/node/cli/commands/parallel.js.map +1 -0
  181. package/out/node/cli/index.js +5 -0
  182. package/out/node/cli/index.js.map +1 -1
  183. package/out/node/cli/spec.d.ts +51 -0
  184. package/out/node/cli/spec.d.ts.map +1 -0
  185. package/out/node/cli/spec.js +78 -0
  186. package/out/node/cli/spec.js.map +1 -0
  187. package/out/node/cli/utils.d.ts +36 -18
  188. package/out/node/cli/utils.d.ts.map +1 -1
  189. package/out/node/cli/utils.js +48 -39
  190. package/out/node/cli/utils.js.map +1 -1
  191. package/out/node/fs/index.d.ts +1 -1
  192. package/out/node/fs/index.d.ts.map +1 -1
  193. package/out/node/fs/index.js +1 -1
  194. package/out/node/fs/index.js.map +1 -1
  195. package/package.json +18 -8
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ import type { TypedArray } from "../internal/shared.js";
7
+ /**
8
+ * A generic mutable typed array.
9
+ */
10
+ export interface MutableTypedArray<T extends number | bigint = number | bigint> {
11
+ readonly length: number;
12
+ readonly [n: number]: T;
13
+ set(array: ArrayLike<T>, offset?: number): void;
14
+ }
15
+ /**
16
+ * A constructor for a mutable typed array.
17
+ */
18
+ export type MutableTypedArrayConstructor<T extends number | bigint = number | bigint> = new (length: number) => MutableTypedArray<T>;
19
+ /**
20
+ * Locally-defined mirror of the TC39 `RelativeIndexable` interface, which is no longer surfaced by the `ESNext` lib
21
+ * used here.
22
+ */
23
+ interface RelativeIndexable<T> {
24
+ at(index: number): T | undefined;
25
+ }
26
+ /**
27
+ * Given several contiguous byte arrays, wraps them as if they were flattened into a single buffer.
28
+ */
29
+ export declare class CompositeDataView<Chunk extends TypedArray = TypedArray> implements Iterable<Chunk[0]>, RelativeIndexable<Chunk[0]> {
30
+ #private;
31
+ constructor(chunks?: Chunk[]);
32
+ /**
33
+ * The combined length of all chunks.
34
+ *
35
+ * @see {@linkcode size} for the number of chunks in the composite buffer.
36
+ */
37
+ get byteLength(): number;
38
+ /**
39
+ * The number of chunks in the composite buffer.
40
+ *
41
+ * @see {@linkcode byteLength} for the total length of the composite buffer.
42
+ */
43
+ get size(): number;
44
+ get chunks(): readonly Chunk[];
45
+ /**
46
+ * The underlying buffer of the composite buffer.
47
+ *
48
+ * Note that this is not memoized and will create a new buffer each time it is accessed.
49
+ */
50
+ get buffer(): Chunk;
51
+ get [Symbol.toStringTag](): string;
52
+ [Symbol.iterator](): Iterator<Chunk[0]>;
53
+ /**
54
+ * Returns the value at the given index, as if the chunks were flattened into a single buffer.
55
+ */
56
+ at(index: number): Chunk[0];
57
+ /**
58
+ * Push a chunk onto the composite buffer.
59
+ */
60
+ append(chunk: Chunk): number;
61
+ /**
62
+ * Prepend a chunk before the first chunk in the composite buffer.
63
+ *
64
+ * @returns The new length of the composite buffer.
65
+ */
66
+ prepend(chunk: Chunk): number;
67
+ /**
68
+ * Remove the most recent chunk from the composite buffer.
69
+ */
70
+ removeLast(): Chunk | undefined;
71
+ /**
72
+ * Remove the first chunk from the composite buffer.
73
+ */
74
+ removeFirst(): Chunk | undefined;
75
+ /**
76
+ * Returns a view into the underlying chunks without copying data.
77
+ */
78
+ subarray(
79
+ /**
80
+ * Element to begin at. The offset is inclusive.
81
+ */
82
+ begin?: number,
83
+ /**
84
+ * Element to end at. The offset is exclusive. If not provided, the view extends to the end of the buffer.
85
+ */
86
+ end?: number): Chunk;
87
+ /**
88
+ * Flattens the composite buffer into a single buffer.
89
+ */
90
+ flat(): Chunk;
91
+ /**
92
+ * Returns a shallow copy of the composite buffer.
93
+ *
94
+ * @see {@linkcode subarray} for a view into the underlying chunks.
95
+ */
96
+ slice(
97
+ /**
98
+ * Zero-based index at which to begin extraction.
99
+ *
100
+ * If this value is negative, it is treated as `byteLength + begin`.
101
+ */
102
+ start?: number,
103
+ /**
104
+ * Zero-based index before which to end extraction.
105
+ *
106
+ * If this value is negative, it is treated as `byteLength + end`.
107
+ */
108
+ end?: number): Chunk;
109
+ }
110
+ export {};
111
+ //# sourceMappingURL=CompositeDataView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompositeDataView.d.ts","sourceRoot":"","sources":["../../../lib/core/CompositeDataView.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM;IAC7E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,CAAA;IACvB,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/C;AAED;;GAEG;AACH,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,KACvF,MAAM,EAAE,MAAM,KACV,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAUzB;;;GAGG;AACH,UAAU,iBAAiB,CAAC,CAAC;IAC5B,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAA;CAChC;AAED;;GAEG;AACH,qBAAa,iBAAiB,CAAC,KAAK,SAAS,UAAU,GAAG,UAAU,CACnE,YAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;;IAsE1D,YAAY,MAAM,CAAC,EAAE,KAAK,EAAE,EAM3B;IAED;;;;OAIG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED;;;;OAIG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,MAAM,IAAI,SAAS,KAAK,EAAE,CAEpC;IAED;;;;OAIG;IACH,IAAW,MAAM,IAAI,KAAK,CAEzB;IAED,IAAW,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAExC;IAEO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAI9C;IAED;;OAEG;IACI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAUjC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAQlC;IAED;;;;OAIG;IACI,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAMnC;IAED;;OAEG;IACI,UAAU,IAAI,KAAK,GAAG,SAAS,CAUrC;IAED;;OAEG;IACI,WAAW,IAAI,KAAK,GAAG,SAAS,CAStC;IAED;;OAEG;IACI,QAAQ;IACd;;OAEG;IACH,KAAK,SAAI;IACT;;OAEG;IACH,GAAG,SAA2B,GAC5B,KAAK,CAiDP;IAED;;OAEG;IACI,IAAI,IAAI,KAAK,CAEnB;IAED;;;;OAIG;IACI,KAAK;IACX;;;;OAIG;IACH,KAAK,SAAI;IACT;;;;OAIG;IACH,GAAG,SAA2B,GAC5B,KAAK,CAUP;CACD"}
@@ -0,0 +1,241 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ /**
7
+ * Given several contiguous byte arrays, wraps them as if they were flattened into a single buffer.
8
+ */
9
+ export class CompositeDataView {
10
+ /**
11
+ * The chunks that make up the composite buffer.
12
+ */
13
+ #chunks = [];
14
+ /**
15
+ * Cached length of the composite buffer.
16
+ */
17
+ #memoizedByteLength = 0;
18
+ /**
19
+ * Cached chunk offset information for binary search.
20
+ */
21
+ #chunkOffsets = [];
22
+ /**
23
+ * Helper method to infer the constructor of the chunks.
24
+ */
25
+ #inferChunkConstructor() {
26
+ const first = this.#chunks[0];
27
+ if (!first) {
28
+ throw new TypeError("No chunks in composite buffer, cannot infer constructor");
29
+ }
30
+ return first.constructor;
31
+ }
32
+ /**
33
+ * Binary search to find the chunk containing the given index.
34
+ */
35
+ #findChunkForIndex(index) {
36
+ let left = 0;
37
+ let right = this.#chunkOffsets.length - 1;
38
+ while (left <= right) {
39
+ const mid = Math.floor((left + right) / 2);
40
+ const chunkInfo = this.#chunkOffsets[mid];
41
+ if (index >= chunkInfo.offset && index < chunkInfo.offset + chunkInfo.length) {
42
+ return { chunk: this.#chunks[mid], chunkInfo };
43
+ }
44
+ if (index < chunkInfo.offset) {
45
+ right = mid - 1;
46
+ }
47
+ else {
48
+ left = mid + 1;
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ /**
54
+ * Update chunk offset information after modification.
55
+ */
56
+ #updateChunkOffsets() {
57
+ let currentOffset = 0;
58
+ this.#chunkOffsets = this.#chunks.map((chunk) => {
59
+ const info = { offset: currentOffset, length: chunk.length };
60
+ currentOffset += chunk.length;
61
+ return info;
62
+ });
63
+ }
64
+ constructor(chunks) {
65
+ if (chunks) {
66
+ this.#chunks = chunks;
67
+ this.#memoizedByteLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
68
+ this.#updateChunkOffsets();
69
+ }
70
+ }
71
+ /**
72
+ * The combined length of all chunks.
73
+ *
74
+ * @see {@linkcode size} for the number of chunks in the composite buffer.
75
+ */
76
+ get byteLength() {
77
+ return this.#memoizedByteLength;
78
+ }
79
+ /**
80
+ * The number of chunks in the composite buffer.
81
+ *
82
+ * @see {@linkcode byteLength} for the total length of the composite buffer.
83
+ */
84
+ get size() {
85
+ return this.#chunks.length;
86
+ }
87
+ get chunks() {
88
+ return this.#chunks;
89
+ }
90
+ /**
91
+ * The underlying buffer of the composite buffer.
92
+ *
93
+ * Note that this is not memoized and will create a new buffer each time it is accessed.
94
+ */
95
+ get buffer() {
96
+ return this.flat();
97
+ }
98
+ get [Symbol.toStringTag]() {
99
+ return "CompositeDataView";
100
+ }
101
+ *[Symbol.iterator]() {
102
+ for (const chunk of this.#chunks) {
103
+ yield* chunk;
104
+ }
105
+ }
106
+ /**
107
+ * Returns the value at the given index, as if the chunks were flattened into a single buffer.
108
+ */
109
+ at(index) {
110
+ const result = this.#findChunkForIndex(index);
111
+ if (!result) {
112
+ throw new RangeError("Index out of range");
113
+ }
114
+ const { chunk, chunkInfo } = result;
115
+ return chunk[index - chunkInfo.offset];
116
+ }
117
+ /**
118
+ * Push a chunk onto the composite buffer.
119
+ */
120
+ append(chunk) {
121
+ this.#chunks.push(chunk);
122
+ this.#memoizedByteLength += chunk.length;
123
+ this.#updateChunkOffsets();
124
+ return this.#memoizedByteLength;
125
+ }
126
+ /**
127
+ * Prepend a chunk before the first chunk in the composite buffer.
128
+ *
129
+ * @returns The new length of the composite buffer.
130
+ */
131
+ prepend(chunk) {
132
+ this.#chunks.unshift(chunk);
133
+ this.#memoizedByteLength += chunk.length;
134
+ this.#updateChunkOffsets();
135
+ return this.#memoizedByteLength;
136
+ }
137
+ /**
138
+ * Remove the most recent chunk from the composite buffer.
139
+ */
140
+ removeLast() {
141
+ const chunk = this.#chunks.pop();
142
+ if (chunk) {
143
+ this.#memoizedByteLength -= chunk.length;
144
+ this.#updateChunkOffsets();
145
+ }
146
+ return chunk;
147
+ }
148
+ /**
149
+ * Remove the first chunk from the composite buffer.
150
+ */
151
+ removeFirst() {
152
+ const chunk = this.#chunks.shift();
153
+ if (chunk) {
154
+ this.#memoizedByteLength -= chunk.length;
155
+ this.#updateChunkOffsets();
156
+ }
157
+ return chunk;
158
+ }
159
+ /**
160
+ * Returns a view into the underlying chunks without copying data.
161
+ */
162
+ subarray(
163
+ /**
164
+ * Element to begin at. The offset is inclusive.
165
+ */
166
+ begin = 0,
167
+ /**
168
+ * Element to end at. The offset is exclusive. If not provided, the view extends to the end of the buffer.
169
+ */
170
+ end = this.#memoizedByteLength) {
171
+ if (begin < 0) {
172
+ throw new RangeError("Invalid subarray range: begin is negative");
173
+ }
174
+ if (end < 0) {
175
+ throw new RangeError("Invalid subarray range: end is negative");
176
+ }
177
+ // const actualEnd = end === undefined ? this.#memoizedByteLength : end
178
+ const startChunk = this.#findChunkForIndex(begin);
179
+ const endChunk = this.#findChunkForIndex(end - 1);
180
+ if (!startChunk || !endChunk) {
181
+ throw new RangeError("Invalid subarray range: Start: " + begin + ", End: " + end);
182
+ }
183
+ // If the range is within a single chunk, return a view into that chunk
184
+ if (startChunk.chunk === endChunk.chunk) {
185
+ const relativeStart = begin - startChunk.chunkInfo.offset;
186
+ const relativeEnd = end - startChunk.chunkInfo.offset;
187
+ return startChunk.chunk.subarray(relativeStart, relativeEnd);
188
+ }
189
+ // Otherwise, we need to create a new buffer and copy the data
190
+ const Constructor = this.#inferChunkConstructor();
191
+ const length = end - begin;
192
+ const result = new Constructor(length);
193
+ let writeOffset = 0;
194
+ let currentChunkIndex = this.#chunks.indexOf(startChunk.chunk);
195
+ while (currentChunkIndex < this.#chunks.length) {
196
+ const currentChunk = this.#chunks[currentChunkIndex];
197
+ const chunkInfo = this.#chunkOffsets[currentChunkIndex];
198
+ const readStart = currentChunk === startChunk.chunk ? begin - chunkInfo.offset : 0;
199
+ const readEnd = currentChunk === endChunk.chunk ? end - chunkInfo.offset : currentChunk.length;
200
+ result.set(currentChunk.subarray(readStart, readEnd), writeOffset);
201
+ writeOffset += readEnd - readStart;
202
+ if (currentChunk === endChunk.chunk)
203
+ break;
204
+ currentChunkIndex++;
205
+ }
206
+ return result;
207
+ }
208
+ /**
209
+ * Flattens the composite buffer into a single buffer.
210
+ */
211
+ flat() {
212
+ return this.subarray();
213
+ }
214
+ /**
215
+ * Returns a shallow copy of the composite buffer.
216
+ *
217
+ * @see {@linkcode subarray} for a view into the underlying chunks.
218
+ */
219
+ slice(
220
+ /**
221
+ * Zero-based index at which to begin extraction.
222
+ *
223
+ * If this value is negative, it is treated as `byteLength + begin`.
224
+ */
225
+ start = 0,
226
+ /**
227
+ * Zero-based index before which to end extraction.
228
+ *
229
+ * If this value is negative, it is treated as `byteLength + end`.
230
+ */
231
+ end = this.#memoizedByteLength) {
232
+ if (start < 0) {
233
+ start = Math.max(0, this.#memoizedByteLength + start);
234
+ }
235
+ if (end < 0) {
236
+ end = Math.max(0, this.#memoizedByteLength + end);
237
+ }
238
+ return this.subarray(start, end);
239
+ }
240
+ }
241
+ //# sourceMappingURL=CompositeDataView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompositeDataView.js","sourceRoot":"","sources":["../../../lib/core/CompositeDataView.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoCH;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAG7B;;OAEG;IACH,OAAO,GAAY,EAAE,CAAA;IAErB;;OAEG;IACH,mBAAmB,GAAG,CAAC,CAAA;IAEvB;;OAEG;IACH,aAAa,GAAgB,EAAE,CAAA;IAE/B;;OAEG;IACH,sBAAsB;QACrB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QAE7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM,IAAI,SAAS,CAAC,yDAAyD,CAAC,CAAA;QAC/E,CAAC;QAED,OAAO,KAAK,CAAC,WAAqD,CAAA;IACnE,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,KAAa;QAC/B,IAAI,IAAI,GAAG,CAAC,CAAA;QACZ,IAAI,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAA;QAEzC,OAAO,IAAI,IAAI,KAAK,EAAE,CAAC;YACtB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;YAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAE,CAAA;YAE1C,IAAI,KAAK,IAAI,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AK;gBAAE,MAAK;YAE1C,iBAAiB,EAAE,CAAA;QACpB,CAAC;QAED,OAAO,MAAe,CAAA;IACvB,CAAC;IAED;;OAEG;IACI,IAAI;QACV,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;IACvB,CAAC;IAED;;;;OAIG;IACI,KAAK;IACX;;;;OAIG;IACH,KAAK,GAAG,CAAC;IACT;;;;OAIG;IACH,GAAG,GAAG,IAAI,CAAC,mBAAmB;QAE9B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,CAAA;QACtD,CAAC;QAED,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;YACb,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,GAAG,CAAC,CAAA;QAClD,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IACjC,CAAC;CACD"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ import type { ByteRange } from "../internal/shared.js";
7
+ /**
8
+ * A first-in, first-out queue for marking and dequeuing index tuples.
9
+ */
10
+ export declare class IndexQueue implements IterableIterator<ByteRange> {
11
+ #private;
12
+ /**
13
+ * The number of tuples in the queue.
14
+ */
15
+ get size(): number;
16
+ /**
17
+ * The total byte length spanned by the tuples in the queue.
18
+ *
19
+ * This is a cached value and may not be accurate if the queue is modified externally.
20
+ */
21
+ get byteLength(): number;
22
+ /**
23
+ * Append a new tuple to the queue.
24
+ */
25
+ enqueue(tuple: ByteRange): void;
26
+ /**
27
+ * Get the next tuple in the queue, removing it.
28
+ */
29
+ dequeue(): ByteRange | undefined;
30
+ /**
31
+ * Peek at the next tuple in the queue without removing it.
32
+ */
33
+ peek(): ByteRange | undefined;
34
+ /**
35
+ * Peek at the last tuple in the queue without removing it.
36
+ */
37
+ peekLast(): ByteRange | undefined;
38
+ /**
39
+ * Clear the queue.
40
+ */
41
+ clear(): void;
42
+ /**
43
+ * Alias for `dequeue`, conforming to the iterator protocol.
44
+ */
45
+ next(): IteratorResult<ByteRange>;
46
+ [Symbol.iterator](): IndexQueue;
47
+ }
48
+ //# sourceMappingURL=IndexQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexQueue.d.ts","sourceRoot":"","sources":["../../../lib/core/IndexQueue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAStD;;GAEG;AACH,qBAAa,UAAW,YAAW,gBAAgB,CAAC,SAAS,CAAC;;IAa7D;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAID;;;;OAIG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED;;OAEG;IACI,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAKrC;IAED;;OAEG;IACI,OAAO,IAAI,SAAS,GAAG,SAAS,CAqBtC;IAED;;OAEG;IACI,IAAI,IAAI,SAAS,GAAG,SAAS,CAInC;IAED;;OAEG;IACI,QAAQ,IAAI,SAAS,GAAG,SAAS,CAMvC;IAED;;OAEG;IACI,KAAK,IAAI,IAAI,CAInB;IAED;;OAEG;IACI,IAAI,IAAI,cAAc,CAAC,SAAS,CAAC,CAQvC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU,CAErC;CACD"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ /**
7
+ * Number of consumed slots (`start`/`end` values, i.e. 2 per dequeued tuple) the head pointer may advance before the
8
+ * backing array is compacted. Bounds wasted space under partial draining while keeping compaction rare enough that
9
+ * `dequeue` stays amortized O(1).
10
+ */
11
+ const COMPACT_THRESHOLD = 1024;
12
+ /**
13
+ * A first-in, first-out queue for marking and dequeuing index tuples.
14
+ */
15
+ export class IndexQueue {
16
+ /**
17
+ * Flat backing store of `[start, end]` pairs. Consumed entries before `#head` are kept until the queue drains or
18
+ * `#head` crosses {@link COMPACT_THRESHOLD}, so `dequeue` stays O(1) instead of shifting the whole array on every
19
+ * yield.
20
+ */
21
+ #tuples = [];
22
+ /**
23
+ * Index of the next tuple's `start` in {@link #tuples}; advances by 2 per dequeue.
24
+ */
25
+ #head = 0;
26
+ /**
27
+ * The number of tuples in the queue.
28
+ */
29
+ get size() {
30
+ return (this.#tuples.length - this.#head) / 2;
31
+ }
32
+ #byteLength = 0;
33
+ /**
34
+ * The total byte length spanned by the tuples in the queue.
35
+ *
36
+ * This is a cached value and may not be accurate if the queue is modified externally.
37
+ */
38
+ get byteLength() {
39
+ return this.#byteLength;
40
+ }
41
+ /**
42
+ * Append a new tuple to the queue.
43
+ */
44
+ enqueue(tuple) {
45
+ this.#tuples.push(tuple[0]);
46
+ this.#tuples.push(tuple[1]);
47
+ this.#byteLength += tuple[1] - tuple[0];
48
+ }
49
+ /**
50
+ * Get the next tuple in the queue, removing it.
51
+ */
52
+ dequeue() {
53
+ if (this.#head >= this.#tuples.length)
54
+ return;
55
+ const start = this.#tuples[this.#head];
56
+ const end = this.#tuples[this.#head + 1];
57
+ this.#head += 2;
58
+ this.#byteLength -= end - start;
59
+ // Reclaim consumed space: reset outright once fully drained (the common per-fill pattern
60
+ // in both engines), otherwise compact periodically so the backing array can't grow
61
+ // unbounded when the queue is only partially drained between enqueues.
62
+ if (this.#head >= this.#tuples.length) {
63
+ this.#tuples.length = 0;
64
+ this.#head = 0;
65
+ }
66
+ else if (this.#head >= COMPACT_THRESHOLD) {
67
+ this.#tuples.splice(0, this.#head);
68
+ this.#head = 0;
69
+ }
70
+ return [start, end];
71
+ }
72
+ /**
73
+ * Peek at the next tuple in the queue without removing it.
74
+ */
75
+ peek() {
76
+ if (this.#head >= this.#tuples.length)
77
+ return;
78
+ return [this.#tuples[this.#head], this.#tuples[this.#head + 1]];
79
+ }
80
+ /**
81
+ * Peek at the last tuple in the queue without removing it.
82
+ */
83
+ peekLast() {
84
+ if (this.#tuples.length - this.#head < 2)
85
+ return;
86
+ const end = this.#tuples.length;
87
+ return [this.#tuples[end - 2], this.#tuples[end - 1]];
88
+ }
89
+ /**
90
+ * Clear the queue.
91
+ */
92
+ clear() {
93
+ this.#tuples.length = 0;
94
+ this.#head = 0;
95
+ this.#byteLength = 0;
96
+ }
97
+ /**
98
+ * Alias for `dequeue`, conforming to the iterator protocol.
99
+ */
100
+ next() {
101
+ const tuple = this.dequeue();
102
+ if (tuple) {
103
+ return { done: false, value: tuple };
104
+ }
105
+ return { done: true, value: undefined };
106
+ }
107
+ [Symbol.iterator]() {
108
+ return this;
109
+ }
110
+ }
111
+ //# sourceMappingURL=IndexQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexQueue.js","sourceRoot":"","sources":["../../../lib/core/IndexQueue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAA;AAE9B;;GAEG;AACH,MAAM,OAAO,UAAU;IACtB;;;;OAIG;IACH,OAAO,GAAa,EAAE,CAAA;IAEtB;;OAEG;IACH,KAAK,GAAG,CAAC,CAAA;IAET;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC9C,CAAC;IAED,WAAW,GAAG,CAAC,CAAA;IAEf;;;;OAIG;IACH,IAAW,UAAU;QACpB,OAAO,IAAI,CAAC,WAAW,CAAA;IACxB,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,KAAgB;QAC9B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QA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,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC,CAAA;IAClE,CAAC;IAED;;OAEG;IACI,QAAQ;QACd,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC;YAAE,OAAM;QAEhD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;QAE/B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAE,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAE,CAAC,CAAA;IACxD,CAAC;IAED;;OAEG;IACI,KAAK;QACX,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAA;QACvB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;QACd,IAAI,CAAC,WAAW,GAAG,CAAC,CAAA;IACrB,CAAC;IAED;;OAEG;IACI,IAAI;QACV,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAE5B,IAAI,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;QACrC,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;IACxC,CAAC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvB,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ import { type CharacterSequenceInput } from "./CharacterSequence.js";
7
+ import type { ByteRange, TypedArray } from "../internal/shared.js";
8
+ export interface SlidingWindowInit {
9
+ /**
10
+ * The delimiter to use. Defaults to a line feed.
11
+ */
12
+ delimiter?: CharacterSequenceInput;
13
+ /**
14
+ * The byte index to start searching from.
15
+ */
16
+ position?: number;
17
+ /**
18
+ * The byte index to stop searching at.
19
+ */
20
+ byteLength?: number;
21
+ }
22
+ /**
23
+ * A sliding window that iterates over an in-memory buffer, yielding byte ranges.
24
+ *
25
+ * @see {@link AsyncSlidingWindow} for an asynchronous version.
26
+ */
27
+ export declare class SlidingWindow<T extends TypedArray> implements IterableIterator<ByteRange> {
28
+ #private;
29
+ buffer: T;
30
+ /**
31
+ * The current byte index of the sliding window.
32
+ */
33
+ cursor: number;
34
+ /**
35
+ * Given a byte array containing delimited data, yield a sliding window of indexes.
36
+ *
37
+ * This a low-level utility function that can be used to implement more complex parsing logic.
38
+ */
39
+ constructor(
40
+ /**
41
+ * The buffer containing delimited data.
42
+ */
43
+ buffer: T, init?: SlidingWindowInit);
44
+ next(): IteratorResult<ByteRange>;
45
+ [Symbol.iterator](): IterableIterator<ByteRange>;
46
+ }
47
+ //# sourceMappingURL=SlidingWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SlidingWindow.d.ts","sourceRoot":"","sources":["../../../lib/core/SlidingWindow.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAqB,KAAK,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AACvF,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElE,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAElC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,qBAAa,aAAa,CAAC,CAAC,SAAS,UAAU,CAAE,YAAW,gBAAgB,CAAC,SAAS,CAAC;;IACtF,MAAM,EAAE,CAAC,CAAA;IAKT;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;;OAIG;IACH;IACC;;OAEG;IACH,MAAM,EAAE,CAAC,EACT,IAAI,GAAE,iBAAsB,EAM5B;IAEM,IAAI,IAAI,cAAc,CAAC,SAAS,CAAC,CA6BvC;IAEM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAEtD;CACD"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ import { CharacterSequence } from "./CharacterSequence.js";
7
+ /**
8
+ * A sliding window that iterates over an in-memory buffer, yielding byte ranges.
9
+ *
10
+ * @see {@link AsyncSlidingWindow} for an asynchronous version.
11
+ */
12
+ export class SlidingWindow {
13
+ buffer;
14
+ #delimiter;
15
+ #byteLength;
16
+ #done = false;
17
+ /**
18
+ * The current byte index of the sliding window.
19
+ */
20
+ cursor;
21
+ /**
22
+ * Given a byte array containing delimited data, yield a sliding window of indexes.
23
+ *
24
+ * This a low-level utility function that can be used to implement more complex parsing logic.
25
+ */
26
+ constructor(
27
+ /**
28
+ * The buffer containing delimited data.
29
+ */
30
+ buffer, init = {}) {
31
+ this.buffer = buffer;
32
+ this.#delimiter = new CharacterSequence(init.delimiter);
33
+ this.cursor = init.position ?? 0;
34
+ this.#byteLength = Math.min(init.byteLength ?? buffer.byteLength, buffer.byteLength);
35
+ }
36
+ next() {
37
+ if (this.cursor < this.#byteLength) {
38
+ // Delegate scanning to CharacterSequence.search, which uses native indexOf for
39
+ // single-byte delimiters and the SIMD/BMH paths otherwise — far faster than a
40
+ // per-byte `.every` callback across the buffer.
41
+ const delimiterIndex = this.#delimiter.search(this.buffer, this.cursor, this.#byteLength);
42
+ if (delimiterIndex !== -1) {
43
+ const range = [this.cursor, delimiterIndex];
44
+ this.cursor = delimiterIndex + this.#delimiter.length;
45
+ return { value: range, done: false };
46
+ }
47
+ }
48
+ if (this.cursor <= this.#byteLength && !this.#done) {
49
+ const range = [this.cursor, this.#byteLength];
50
+ this.cursor = this.#byteLength;
51
+ this.#done = true;
52
+ return { value: range, done: false };
53
+ }
54
+ return {
55
+ value: undefined,
56
+ done: true,
57
+ };
58
+ }
59
+ [Symbol.iterator]() {
60
+ return this;
61
+ }
62
+ }
63
+ //# sourceMappingURL=SlidingWindow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SlidingWindow.js","sourceRoot":"","sources":["../../../lib/core/SlidingWindow.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAA+B,MAAM,wBAAwB,CAAA;AAoBvF;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACzB,MAAM,CAAG;IACT,UAAU,CAAmB;IAC7B,WAAW,CAAQ;IACnB,KAAK,GAAG,KAAK,CAAA;IAEb;;OAEG;IACH,MAAM,CAAQ;IAEd;;;;OAIG;IACH;IACC;;OAEG;IACH,MAAS,EACT,IAAI,GAAsB,EAAE;QAE5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACvD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAA;QAChC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IACrF,CAAC;IAEM,IAAI;QACV,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YACpC,+EAA+E;YAC/E,8EAA8E;YAC9E,gDAAgD;YAChD,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAA+B,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YAElH,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC3B,MAAM,KAAK,GAAc,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;gBAEtD,IAAI,CA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