balloc 1.3.1 → 2.0.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 (42) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.MD +171 -318
  3. package/docs/API /342/200/224 balloc.en.md" +472 -1156
  4. package/docs/MIGRATION /342/200/224 balloc.en.md" +208 -0
  5. package/package.json +2 -44
  6. package/src/README.MD +0 -0
  7. package/src/en/balloc.cjs +515 -933
  8. package/src/en/balloc.js +1 -1
  9. package/src/en/balloc.mjs +561 -1064
  10. package/types/README.MD +0 -0
  11. package/types/en/balloc.d.mts +279 -554
  12. package/README.ar.md +0 -409
  13. package/README.en.md +0 -437
  14. package/README.es.md +0 -409
  15. package/README.jp.md +0 -408
  16. package/README.pt.md +0 -433
  17. package/README.zh.md +0 -408
  18. package/docs/API /342/200/224 balloc.ar.md" +0 -1453
  19. package/docs/API /342/200/224 balloc.es.md" +0 -1269
  20. package/docs/API /342/200/224 balloc.jp.md" +0 -1208
  21. package/docs/API /342/200/224 balloc.pt.md" +0 -1339
  22. package/docs/API /342/200/224 balloc.zh.md" +0 -1268
  23. package/src/ar/balloc.cjs +0 -1273
  24. package/src/ar/balloc.js +0 -2
  25. package/src/ar/balloc.mjs +0 -1548
  26. package/src/es/balloc.cjs +0 -1288
  27. package/src/es/balloc.js +0 -2
  28. package/src/es/balloc.mjs +0 -1563
  29. package/src/jp/balloc.cjs +0 -1228
  30. package/src/jp/balloc.js +0 -2
  31. package/src/jp/balloc.mjs +0 -1503
  32. package/src/pt/balloc.cjs +0 -1293
  33. package/src/pt/balloc.js +0 -2
  34. package/src/pt/balloc.mjs +0 -1568
  35. package/src/zh/balloc.cjs +0 -1175
  36. package/src/zh/balloc.js +0 -2
  37. package/src/zh/balloc.mjs +0 -1450
  38. package/types/ar/balloc.d.mts +0 -762
  39. package/types/es/balloc.d.mts +0 -777
  40. package/types/jp/balloc.d.mts +0 -717
  41. package/types/pt/balloc.d.mts +0 -781
  42. package/types/zh/balloc.d.mts +0 -664
@@ -1,389 +1,225 @@
1
1
  export type BucketType = '8u' | '16u' | '32u' | '64u' | '8i' | '16i' | '32i' | '64i' | '16f' | '32f' | '64f';
2
- export type Metadata = {
2
+ export type FormatAdapter = {
3
3
  /**
4
- * - The byte capacity of the memory block.
4
+ * - Loads the data into the allocator
5
+ * and returns the operation result. Balloc passes this value through without validating it.
5
6
  */
6
- byteCapacity: number;
7
- /**
8
- * - The capacity of the memory block expressed as a base-two exponent.
9
- */
10
- capacityExponent: number;
11
- /**
12
- * - Address of the memory block within the dataBus.
13
- */
14
- dataAddress: number;
15
- /**
16
- * - Generation to which the handle belongs.
17
- */
18
- generation: number;
19
- /**
20
- * - Address of the header within the controlBus.
21
- */
22
- headerAddress: number;
23
- /**
24
- * - Number of occupied elements in the block.
25
- */
26
- occupied: number;
27
- /**
28
- * - Flag indicating whether the block has been borrowed by withView().
29
- */
30
- borrowed: number;
7
+ load: (allocator: Balloc) => any;
31
8
  };
32
9
  /**
33
- * Echo Stack Dual Bus Bump Allocator with ReBump GC.
10
+ * Contract for a synchronous data-ingestion adapter.
11
+ *
12
+ * The adapter receives the Balloc instance and uses its public API to
13
+ * store the data, returning the handler identifying the main block.
14
+ *
15
+ * @typedef {Object} FormatAdapter
16
+ * @property {(allocator: Balloc) => *} load - Loads the data into the allocator
17
+ * and returns the operation result. Balloc passes this value through without validating it.
18
+ */
19
+ /**
20
+ * Memory block allocator with monotonic handles and typed views.
21
+ *
22
+ * Each allocation has its own ArrayBuffer; the instance keeps the blocks
23
+ * in a handler-indexed registry and tracks each block's occupancy.
34
24
  */
35
25
  export default class Balloc {
36
- wordType: BucketType;
37
- bucketType: string;
38
- bucketSize: number;
39
- bucketArray: any;
40
- wordSize: number;
41
- wordShift: number;
42
- size: number;
43
- headerSize: number;
44
- dataPointer: number;
45
- controlPointer: number;
46
- echoPointer: number;
47
- generation: number;
48
- dataBus: Uint8Array<ArrayBuffer>;
49
- controlBus: Uint8Array<ArrayBuffer>;
50
- dataAdapter: DataView<ArrayBuffer>;
51
- controlAdapter: DataView<ArrayBuffer>;
52
- auxiliary: any;
53
- writer: any;
54
- reader: any;
55
- recycle: Map<any, any>;
56
- /** @type {Metadata} */
57
- metadata: Metadata;
58
- /**
59
- * Creates an instance of the `Balloc` memory allocator.
60
- *
61
- * The allocator maintains two independent buffers:
62
- * - `dataBus`: stores the data of allocated blocks;
63
- * - `controlBus`: stores headers and other control metadata.
64
- *
65
- * Each block has a fixed-size header (`HEADER_SIZE`) and is
66
- * identified externally by a 43-bit logical handle, composed
67
- * of an 11-bit generation and its 32-bit header address.
68
- *
69
- * The capacity of each block is rounded up to the next power of
70
- * two in elements, respecting the width of the configured bucket.
71
- *
72
- * @param {number} [size=65535] - Initial capacity of the `dataBus`, in bytes.
73
- * Must be a safe integer in the range [2, 0x80000000].
74
- * @param {BucketType} [bucketSize="32u"] - Identifier for the bucket type and size
75
- * (e.g., '32u' for Uint32, '64f' for Float64, '8i' for Int8).
76
- * @param {number} [metadataSize=1024] - Initial capacity of the `controlBus`,
77
- * in bytes. Must be a safe integer in the range
78
- * [HEADER_SIZE, 0x80000000].
79
- *
80
- * @throws {RangeError} If `size` is outside the allowed range.
81
- * @throws {RangeError} If `bucketSize` is not a valid bucket identifier.
82
- * @throws {RangeError} If `metadataSize` is outside the allowed range.
83
- */
84
- constructor(size?: number, bucketSize?: BucketType, metadataSize?: number);
26
+ maxByteSize: number;
27
+ bucketSize: BucketType | null;
28
+ bus: any;
29
+ lastHandler: number;
85
30
  /**
86
- * Allocates a new memory block.
87
- *
88
- * The requested capacity is converted to the smallest power of two that
89
- * can accommodate `size` elements. The block is obtained preferentially from the list
90
- * of recyclable regions with the corresponding capacity; if a compatible
91
- * region does not exist, the block is reserved at the top of the `dataBus`.
31
+ * Creates an allocator instance.
92
32
  *
93
- * Next, a header is obtained from the control space. Previously freed headers
94
- * can be reused via the internal recycling stack;
95
- * otherwise, the `controlBus` is expanded when necessary.
33
+ * Initializes the limit used to validate allocation requests,
34
+ * the optional default bucket type, and the structures that associate
35
+ * handles with blocks. Each block receives its own ArrayBuffer
36
+ * when alloc() is called.
96
37
  *
97
- * The header receives the address, capacity, initial occupancy (zero), and
98
- * a validation cookie. The returned value encodes the allocation generation
99
- * and the header address:
100
- *
101
- * [11 generation bits][32 header address bits]
102
- *
103
- * @param {number} [size=16] - Minimum number of elements the block must
104
- * accommodate. Must be a safe integer in the range [2, 0x80000000].
105
- * @returns {number} Handle identifying the allocated block.
106
- * @throws {RangeError} If `size` is outside the allowed range.
107
- * @throws {Error} If it is necessary to expand the `dataBus` while any
108
- * block is borrowed via withView().
38
+ * @param {number|null} [size=0x80000000] Limit used to validate
39
+ * the size requested by alloc(). Must be a safe integer
40
+ * between 2 and 0x80000000.
41
+ * @param {BucketType|null} [bucketSize=null] Default bucket type.
42
+ * When set, it takes precedence over bucketType in alloc().
43
+ * @throws {RangeError} If size or bucketSize is invalid.
109
44
  */
110
- alloc(size?: number): number;
45
+ constructor(size?: number | null, bucketSize?: BucketType | null);
111
46
  /**
112
- * Expands a block's capacity to the next power of two.
47
+ * Allocates a memory block and returns its handle.
113
48
  *
114
- * When the block is located at the current top of the `dataBus`, expansion
115
- * occurs in-place: only its capacity and `dataPointer` are
116
- * updated.
49
+ * size specifies the ArrayBuffer size in bytes. The typed view is
50
+ * selected by bucketType and contains the number of elements
51
+ * that fit this buffer size. If the instance has
52
+ * bucketSize set, it takes precedence over bucketType.
117
53
  *
118
- * If another region exists after the block, a new region with double the
119
- * capacity is obtained from the recyclable space or allocated at the top of the `dataBus`.
120
- * The currently occupied elements are then copied to the new region,
121
- * and the previous region is returned to the recycling list.
54
+ * Each allocation receives a monotonic handle that is never reused. The identifier
55
+ * space is limited to 32 unsigned bits.
122
56
  *
123
- * The handle remains valid because its header is preserved and only the
124
- * address and capacity recorded in it are updated.
125
- *
126
- * @param {number} handler - Handle of the block to be expanded.
127
- * @returns {void}
128
- * @throws {Error} If the handle is invalid, corrupted, or the block
129
- * is borrowed via withView(). Also occurs if expansion requires
130
- * dataBus remapping while another block is borrowed.
131
- * @throws {AggregateError} If the capacity has reached the maximum
132
- * supported limit.
57
+ * @param {number} [size=16] ArrayBuffer size in bytes. Must be
58
+ * a safe integer greater than or equal to 2 and less than maxByteSize.
59
+ * @param {BucketType} [bucketType="32u"] Typed view type.
60
+ * @returns {number} Handle of the allocated block.
61
+ * @throws {RangeError} If the bucket type or size is invalid.
133
62
  */
134
- realloc(handler: number): void;
63
+ alloc(size?: number, bucketType?: BucketType): number;
135
64
  /**
136
- * Reduces a block to the smallest power-of-two capacity that can contain
137
- * its occupied elements, while preserving its address and handler.
65
+ * Replaces a block's storage with a buffer of greater capacity.
138
66
  *
139
- * If the block is at the top of the dataBus, dataPointer is moved backward.
140
- * Otherwise, the released tail is split into power-of-two regions and each
141
- * region is returned to the recycling list.
67
+ * newSize is expressed in elements. If omitted or null, the capacity
68
+ * doubles; the result is capped by maxByteSize converted to
69
+ * elements according to BYTES_PER_ELEMENT. The occupied elements are
70
+ * copied to the new buffer.
142
71
  *
143
- * @param {number} handler - Handler of the block to shrink.
72
+ * @param {number} handler Block handle.
73
+ * @param {number|null} [newSize=null] New capacity in elements.
144
74
  * @returns {void}
145
- * @throws {Error} If the handler is invalid, corrupted, or borrowed by withView().
75
+ * @throws {Error} If the handle does not exist or the block is borrowed.
76
+ * @throws {RangeError} If the new capacity is not a safe integer
77
+ * greater than the current capacity.
146
78
  */
147
- shrink(handler: number): void;
79
+ realloc(handler: number, newSize?: number | null): void;
148
80
  /**
149
- * Frees a memory block.
150
- *
151
- * The block's header is invalidated by zeroing its cookie, and its
152
- * address is registered for later reuse. The data region
153
- * is also returned to the recycling system, except when the block is
154
- * exactly at the top of the `dataBus`; in that case, the `dataPointer` is simply
155
- * rolled back, eliminating the region without creating an entry in the recycling
156
- * list.
157
- *
158
- * @param {number} handler - Handle of the block to be freed.
159
- * @returns {void}
160
- * @throws {Error} If the handle is invalid, corrupted, or the block
161
- * is borrowed via withView().
162
- */
163
- free(handler: number): void;
164
- /**
165
- * [INTERNAL USE]
166
- * Inserts a free region into the recycling list.
167
- *
168
- * The list is organized by capacity in bytes. For each capacity, the
169
- * stored value is a `Uint32Array` whose zero position contains the quantity
170
- * of registered addresses and subsequent positions contain the addresses of
171
- * the free regions:
172
- *
173
- * [count, address1, address2, ...]
81
+ * Reduces the block capacity to an amount calculated from
82
+ * its occupancy.
174
83
  *
175
- * When the page becomes full, its buffer is expanded to double its current
176
- * capacity.
84
+ * The new capacity is the smallest power of two that can hold the occupied
85
+ * elements, with a minimum of two elements. The method creates a new ArrayBuffer
86
+ * and copies the occupied elements. If the calculated capacity is not smaller
87
+ * than the current capacity, a RangeError is thrown. No region recycling or
88
+ * heap compaction is performed.
177
89
  *
178
- * @param {number} capacity - Capacity of the free region, in bytes.
179
- * @param {number} address - Initial address of the region in the `dataBus`.
90
+ * @param {number} handler Block handle.
180
91
  * @returns {void}
181
- * @private
92
+ * @throws {Error} If the handle does not exist or the block is borrowed.
93
+ * @throws {RangeError} If the calculated capacity is not smaller than the current capacity.
182
94
  */
183
- private recyclePush;
184
- /**
185
- * [INTERNAL USE]
186
- * Removes a free region from the recycling list.
187
- *
188
- * The search is performed by the exact requested capacity. When a corresponding
189
- * page exists, the last registered address is removed from the page and returned,
190
- * implementing recycling as a LIFO stack.
191
- *
192
- * @param {number} capacity - Desired capacity, in bytes.
193
- * @returns {number} Initial address of a recyclable region or `UNKNOWN`
194
- * when a region with the requested capacity does not exist.
195
- * @private
196
- */
197
- private recyclePop;
198
- /**
199
- * Compacts the `dataBus` using the ReBump algorithm.
200
- *
201
- * Sequentially traverses the headers registered in the `controlBus` and copies
202
- * still-valid regions to a new `dataBus`, eliminating free spaces
203
- * between them. Each surviving block's address is updated in its
204
- * respective header.
205
- *
206
- * The order of blocks in the `controlBus` is preserved. The internal data of
207
- * each block is also fully preserved, including its reserved capacity
208
- * and current occupancy.
209
- *
210
- * Upon completion of compaction:
211
- * - all recyclable regions are eliminated;
212
- * - `dataPointer` points to the first byte after the last live block;
213
- * - the `dataBus` represents a contiguous heap for active blocks.
214
- *
215
- * Control complexity is O(n), where `n` is the number of traversed
216
- * headers. The effective memory movement cost also depends on the volume
217
- * of bytes belonging to live blocks.
218
- *
219
- * @returns {void}
220
- * @throws {Error} If any block is borrowed via withView().
221
- */
222
- gc(): void;
223
- /**
224
- * [!!! INTERNAL USE, DO NOT USE IN YOUR CODE !!!]
225
- * Expands the `dataBus` to double its current capacity.
226
- *
227
- * The underlying buffer is transferred to a larger `ArrayBuffer`, preserving
228
- * existing data. All views associated with the buffer are recreated
229
- * to reference the new storage.
230
- *
231
- * @returns {void}
232
- * @throws {Error} If any block is borrowed via withView().
233
- * @throws {RangeError} If the `dataBus` capacity has already exceeded the
234
- * maximum supported limit.
235
- * @private
236
- */
237
- private grow;
95
+ shrink(handler: number): void;
238
96
  /**
239
- * [!!! INTERNAL USE, DO NOT USE IN YOUR CODE !!!]
240
- * Expands the `controlBus` to double its current capacity.
241
- *
242
- * The underlying buffer is transferred to a larger `ArrayBuffer`, preserving
243
- * existing headers. The `controlAdapter` is recreated to reference
244
- * the new storage.
245
- *
246
- * @returns {void}
247
- * @throws {RangeError} If the current `controlBus` capacity has already
248
- * exceeded the maximum supported limit.
249
- * @private
250
- */
251
- private headerGrow;
97
+ * Frees a block and permanently invalidates its handle.
98
+ *
99
+ * Removes the entry from bus. Handles are not reused. There is no
100
+ * coalescing or recycling of regions in a shared heap.
101
+ *
102
+ * @param {number} handler Handle of the block to free.
103
+ * @returns {void}
104
+ * @throws {Error} If the handle does not exist or the block is borrowed.
105
+ */
106
+ free(handler: number): void;
252
107
  /**
253
- * Appends an element to the end of the sequence occupied by the block.
108
+ * Adds an element to the end of the block's occupied sequence.
254
109
  *
255
- * The element is written at the first free position after the last occupied
256
- * element. Block occupancy is incremented only when space is available
110
+ * The element is written to the first free position after the last occupied
111
+ * element. The block's occupancy is incremented only when space is available
257
112
  * within its capacity.
258
113
  *
259
- * @param {number} value - Value to be inserted.
114
+ * @param {number} handler - Block handle.
115
+ * @param {number} value - Value to insert.
260
116
  * @returns {boolean} `true` if the value was inserted; `false` if the block
261
- * is already out of available space.
262
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
117
+ * has no available space.
118
+ * @throws {Error} If the handle is invalid or corrupted, or the block is borrowed by withView().
263
119
  *
264
120
  */
265
- push(handler: any, value: number): boolean;
121
+ push(handler: number, value: number): boolean;
266
122
  /**
267
- * Removes the last occupied element from the block and returns it.
123
+ * Removes and returns the last occupied element. If the block is empty,
124
+ * returns undefined without changing its occupancy.
268
125
  *
269
- * Occupancy is decremented before reading the removed element. The corresponding
270
- * bytes are not cleared and remain in the allocated region, but cease to be
271
- * part of the occupied sequence.
272
- *
273
- * @param {number} handler - Block handle.
274
- * @returns {number|undefined} Removed value or `undefined` if the block
275
- * is empty.
276
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
126
+ * @param {number} handler Block handle.
127
+ * @returns {number|bigint|undefined} Value at the index immediately before
128
+ * the occupancy is decremented.
129
+ * @throws {Error} If the handle does not exist or the block is borrowed.
277
130
  */
278
- pop(handler: number): number | undefined;
131
+ pop(handler: number): number | bigint | undefined;
279
132
  /**
280
133
  * Returns the last occupied element without removing it.
281
134
  *
282
135
  * @param {number} handler - Block handle.
283
- * @returns {number|undefined} Last occupied value or `undefined` if the
136
+ * @returns {number|undefined} Last occupied value, or `undefined` if the
284
137
  * block is empty.
285
- * @throws {Error} If the handle is invalid or corrupted.
138
+ * @throws {Error} If the handle does not exist or the block is borrowed.
286
139
  */
287
140
  peek(handler: number): number | undefined;
288
141
  /**
289
- * Inserts an element at the beginning of the occupied sequence.
290
- *
291
- * Currently occupied elements are shifted forward by one position and
292
- * `value` is written at the first position. The operation requires a free
293
- * position within the block's capacity.
142
+ * Shifts the occupied elements one position toward the end of the block.
294
143
  *
295
- * The operation cost is proportional to the number of occupied elements,
296
- * as data needs to be shifted.
144
+ * Runs copyWithin(1, 0, occupied) on the typed view. The
145
+ * value argument is not used, occupancy is not changed, and the method returns
146
+ * the typed view itself.
297
147
  *
298
- * @param {number} handler - Block handle.
299
- * @param {number} value - Value to be inserted.
300
- * @returns {boolean} `true` if the value was inserted; `false` if the block
301
- * is full.
302
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
148
+ * @param {number} handler Block handle.
149
+ * @param {number} value Currently unused parameter.
150
+ * @returns {TypedArray} Typed view of the block.
151
+ * @throws {Error} If the handle does not exist or the block is borrowed.
303
152
  */
304
- nudge(handler: number, value: number): boolean;
153
+ nudge(handler: number, value: number): TypedArray;
305
154
  /**
306
- * Removes the first occupied element from the block and returns it.
155
+ * Returns the value in the first slot and shifts the remaining occupied
156
+ * elements one position toward the beginning of the block.
307
157
  *
308
- * Remaining elements are shifted one position toward the beginning
309
- * of the occupied region. The physical capacity of the block remains unchanged.
158
+ * The implementation does not decrement occupancy after shifting.
310
159
  *
311
- * The operation cost is proportional to the number of shifted elements.
312
- *
313
- * @param {number} handler - Block handle.
314
- * @returns {number|undefined} First removed value or `undefined` if the
315
- * block is empty.
316
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
160
+ * @param {number} handler Block handle.
161
+ * @returns {number|bigint|undefined} Value stored in the first slot.
162
+ * @throws {Error} If the handle does not exist or the block is borrowed.
317
163
  */
318
- pull(handler: number): number | undefined;
164
+ pull(handler: number): number | bigint | undefined;
319
165
  /**
320
- * Returns the first occupied element without removing it.
166
+ * Returns the value stored in the block's first slot.
321
167
  *
322
- * @param {number} handler - Block handle.
323
- * @returns {number|undefined} First occupied value or `undefined` if the
324
- * block is empty.
325
- * @throws {Error} If the handle is invalid or corrupted.
168
+ * Reading does not change occupancy. The method does not check the borrowed flag.
169
+ *
170
+ * @param {number} handler Block handle.
171
+ * @returns {number|bigint|undefined} Value in the first slot.
172
+ * @throws {Error} If the handle does not exist.
326
173
  */
327
- head(handler: number): number | undefined;
174
+ head(handler: number): number | bigint | undefined;
328
175
  /**
329
- * Checks if a value is present among the occupied elements of the block.
176
+ * Checks whether a value is present among the block's occupied elements.
330
177
  *
331
178
  * The search is performed directly on the auxiliary `TypedArray` and considers
332
- * only the currently occupied range, not the entire reserved physical capacity.
179
+ * only the currently occupied range, not the entire physical capacity
180
+ * reserved.
333
181
  *
334
182
  * @param {number} handler - Block handle.
335
183
  * @param {number} value - Value to search for.
336
- * @returns {boolean} `true` if `value` is present among the occupied
337
- * elements; otherwise, `false`.
184
+ * @returns {boolean} `true` if `value` is present among the
185
+ * occupied elements; otherwise, `false`.
338
186
  * @throws {Error} If the handle is invalid or corrupted.
339
187
  */
340
188
  has(handler: number, value: number): boolean;
341
189
  /**
342
- * Locates the first occurrence of an element in the block's occupied sequence.
190
+ * Finds the first occurrence of an element in the block's occupied sequence.
343
191
  *
344
- * The search is performed in ascending order of indices, using the `indexOf`
345
- * operation of the underlying TypedArray. The search exclusively considers
346
- * occupied elements, ignoring the block's unused capacity.
347
- *
348
- * The starting search position can be specified by `fromIndex`,
349
- * following TypedArray indexing rules.
350
192
  *
351
193
  * @param {number} handler - Block handle.
352
- * @param {number|bigint} searchElement - Element to locate.
353
- * @param {number} [fromIndex=0] - Index from which to start the search.
354
- * @returns {number} Index of the first occurrence or `-1` if the
355
- * element is not found or if the block is empty.
194
+ * @param {number|bigint} searchElement - Element to find.
195
+ * @param {number} [fromIndex=0] - Index from which the search starts.
196
+ * @returns {number} Index of the first occurrence, or `-1` if the
197
+ * element is not found or the block is empty.
356
198
  * @throws {Error} If the handle is invalid or corrupted.
357
199
  */
358
200
  indexOf(handler: number, searchElement: number | bigint, fromIndex?: number): number;
359
201
  /**
360
- * Locates the last occurrence of an element in the block's occupied sequence.
361
- *
362
- * The search is performed in descending order of indices, using the `lastIndexOf`
363
- * operation of the underlying TypedArray. The search exclusively considers
364
- * occupied elements, ignoring the block's unused capacity.
202
+ * Finds the last occurrence of an element in the block's occupied sequence.
365
203
  *
366
- * The starting search position can be specified by `fromIndex`,
367
- * following TypedArray indexing rules. By default, the search starts
368
- * at the last occupied element.
204
+ * By default, the search starts at the last occupied element.
369
205
  *
370
206
  * @param {number} handler - Block handle.
371
- * @param {number|bigint} searchElement - Element to locate.
372
- * @param {number} [fromIndex=-1] - Index from which to start the search.
373
- * @returns {number} Index of the last occurrence or `-1` if the
374
- * element is not found or if the block is empty.
207
+ * @param {number|bigint} searchElement - Element to find.
208
+ * @param {number} [fromIndex=-1] - Index from which the search starts.
209
+ * @returns {number} Index of the last occurrence, or `-1` if the
210
+ * element is not found or the block is empty.
375
211
  * @throws {Error} If the handle is invalid or corrupted.
376
212
  */
377
213
  lastIndexOf(handler: number, searchElement: number | bigint, fromIndex?: number): number;
378
214
  /**
379
215
  * Returns the occupied element at a zero-based index.
380
216
  *
381
- * Indices outside the range `[0, occupied)` are not considered an error and
217
+ * Indices outside the `[0, occupied)` range are not considered errors and
382
218
  * result in `undefined`.
383
219
  *
384
220
  * @param {number} handler - Block handle.
385
221
  * @param {number} index - Zero-based index of the element.
386
- * @returns {number|undefined} Value stored at the index or `undefined` if
222
+ * @returns {number|undefined} Value stored at the index, or `undefined` if
387
223
  * the index is outside the occupied region.
388
224
  * @throws {Error} If the handle is invalid or corrupted.
389
225
  */
@@ -391,80 +227,77 @@ export default class Balloc {
391
227
  /**
392
228
  * Replaces the value stored at an occupied index.
393
229
  *
394
- * The operation does not alter block occupancy. Indices outside the range
395
- * `[0, occupied)` are ignored and result in `false`.
230
+ * The operation does not change block occupancy. Indices outside the
231
+ * `[0, occupied)` range are ignored and result in `false`.
396
232
  *
397
233
  * @param {number} handler - Block handle.
398
234
  * @param {number} index - Zero-based index of the element.
399
235
  * @param {number} value - New value.
400
236
  * @returns {boolean} `true` if the value was written; `false` if the index
401
237
  * is outside the occupied region.
402
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
238
+ * @throws {Error} If the handle is invalid or corrupted, or the block is borrowed by withView().
403
239
  */
404
240
  set(handler: number, index: number, value: number): boolean;
405
241
  /**
406
- * Zeroes block occupancy and fills its entire physical capacity with
407
- * a single value.
242
+ * Resets the block's occupancy and fills its entire physical capacity with
243
+ * the same value.
408
244
  *
409
- * The fill covers all available slots, not just currently
410
- * occupied elements. After the operation, the block is considered
411
- * empty regardless of the value used for filling.
245
+ * Filling covers all available slots, not just the
246
+ * currently occupied elements. After the operation, the block is considered
247
+ * empty regardless of the value used to fill it.
412
248
  *
413
249
  * @param {number} handler - Block handle.
414
250
  * @param {number} [value=0] - Value used to fill all slots.
415
251
  * @returns {void}
416
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
252
+ * @throws {Error} If the handle is invalid or corrupted, or the block is borrowed by withView().
417
253
  */
418
254
  clear(handler: number, value?: number): void;
419
255
  /**
420
- * Fills a range of block slots with a value.
256
+ * Fills the typed view using the supplied bounds.
421
257
  *
422
- * The range uses zero-based indices and follows the convention
423
- * `[start, end)`, therefore `start` is inclusive and `end` is exclusive.
424
- * When `end` is not provided, filling extends to the end of the block's
425
- * physical capacity.
258
+ * The operation delegates filling to TypedArray.prototype.fill().
259
+ * Because end defaults to null and is passed explicitly, it is
260
+ * converted to zero by the native API; therefore, the default call
261
+ * normally fills no elements. Regardless of the range,
262
+ * the implementation sets occupancy to the view's total length.
426
263
  *
427
- * Block occupancy becomes `end`, including when the filled range
428
- * extends beyond previous occupancy.
429
- *
430
- * @param {number} handler - Block handle.
431
- * @param {number} value - Value used for filling.
432
- * @param {number} [start=0] - Initial index, inclusive.
433
- * @param {number|null} [end=null] - Final index, exclusive. When
434
- * omitted or `null`, uses the block's total capacity.
264
+ * @param {number} handler Block handle.
265
+ * @param {number|bigint} value Value used to fill the view.
266
+ * @param {number} [start=0] Starting index.
267
+ * @param {number} [end=pack.dataBus.length] Exclusive end index.
435
268
  * @returns {void}
436
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
437
- * @throws {RangeError} If `start` or `end` is outside capacity limits,
438
- * or if `start > end`.
269
+ * @throws {Error} If the handle does not exist or the block is borrowed.
439
270
  */
440
- fill(handler: number, value: number, start?: number, end?: number | null): void;
271
+ fill(handler: number, value: number | bigint, start?: number, end?: number): void;
441
272
  /**
442
- * Fills all physical slots of the block with a value and marks the entire
273
+ * Fills all physical slots in the block with a value and marks the entire
443
274
  * capacity as occupied.
444
275
  *
445
- * Unlike `clear()`, this operation results in a fully occupied block.
276
+ * Unlike `clear()`, this operation results in a fully
277
+ * occupied block.
446
278
  *
447
279
  * @param {number} handler - Block handle.
448
- * @param {number} value - Value used for filling.
280
+ * @param {number} value - Value used to fill the block.
449
281
  * @returns {void}
450
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
282
+ * @throws {Error} If the handle is invalid or corrupted, or the block is borrowed by withView().
451
283
  */
452
284
  fillAll(handler: number, value: number): void;
453
285
  /**
454
286
  * Copies elements from an `Array` or `TypedArray` to the beginning of the block.
455
287
  *
456
- * The copied quantity is limited by the block's capacity. Occupancy is
457
- * updated to the greater value between previous occupancy and the quantity
458
- * effectively copied; therefore, a call to `put()` does not reduce existing
459
- * occupancy when receiving a smaller sequence.
288
+ * The copied amount is limited by the block's capacity. Occupancy is
289
+ * updated to the greater of the previous occupancy and the amount
290
+ * actually copied; therefore, a call to `put()` does not reduce
291
+ * existing occupancy when given a shorter sequence.
460
292
  *
461
- * For `Array`, only the first elements that fit are copied.
462
- * For `TypedArray`, a source subarray is used without intermediate copying.
293
+ * For an `Array`, only the first elements that fit are copied.
294
+ * For a `TypedArray`, a subarray of the source is used without an
295
+ * intermediate copy.
463
296
  *
464
297
  * @param {number} handler - Block handle.
465
298
  * @param {Array|TypedArray} data - Sequence of values to copy.
466
299
  * @returns {void}
467
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
300
+ * @throws {Error} If the handle is invalid or corrupted, or the block is borrowed by withView().
468
301
  * @throws {TypeError} If `data` is neither an `Array` nor a `TypedArray`.
469
302
  */
470
303
  put(handler: number, data: any[] | TypedArray): void;
@@ -474,38 +307,41 @@ export default class Balloc {
474
307
  * The result is a `TypedArray` of the same type configured by
475
308
  * `bucketSize`. Unoccupied physical capacity is not included in the result.
476
309
  *
477
- * The operation does not directly expose internal storage: the method
478
- * uses `TypedArray.prototype.slice()`, producing a new view with
479
- * independent storage.
310
+ * The operation does not expose the internal storage directly:
311
+ * `TypedArray.prototype.slice()` produces a copy with independent
312
+ * storage.
480
313
  *
481
314
  * @param {number} handler - Block handle.
482
- * @returns {TypedArray} Copy of elements occupied by the block. When
315
+ * @returns {TypedArray} Copy of the elements occupied by the block. When
483
316
  * the block is empty, returns an empty `TypedArray` of the configured type.
484
317
  * @throws {Error} If the handle is invalid or corrupted.
485
318
  */
486
319
  pick(handler: number): TypedArray;
487
320
  /**
488
- * Executes a callback over a direct view of the block's occupied region.
489
- *
490
- * The view shares Balloc's internal storage and performs no copying.
491
- * The block is protected against incompatible operations during the callback.
492
- *
493
- * The callback must be synchronous. The received view must not be stored,
494
- * returned, or used after the callback terminates. This restriction
495
- * also applies to subviews derived from the original view.
496
- *
497
- * @param {number} handler - Block handle.
498
- * @param {...(number|Function)} args - One or more block handles followed by the callback.
499
- * @returns {*} Return value produced by the callback.
500
- * @throws {TypeError} If no handle is provided or the callback is not a function.
501
- * @throws {Error} If a handle is invalid, duplicated, or already borrowed.
502
- */
321
+ * Executes a synchronous callback with direct subviews of one or more blocks.
322
+ *
323
+ * The arguments contain one or more handles, followed by a function.
324
+ * Each view covers only the occupied elements and shares the block's
325
+ * storage. The blocks are marked as borrowed during
326
+ * execution and released in finally, even if the callback throws
327
+ * an exception. Duplicate handles are not allowed.
328
+ *
329
+ * The views must not be retained or used after the callback returns.
330
+ *
331
+ * @param {...(number|Function)} args Handles followed by the callback.
332
+ * @returns {*} Value returned by the callback.
333
+ * @throws {TypeError} If a handle or callback is missing, or if the last
334
+ * argument is not a function.
335
+ * @throws {Error} If any handle does not exist, is duplicated,
336
+ * or is already borrowed.
337
+ */
503
338
  withView(...args: (number | Function)[]): any;
504
339
  /**
505
- * Returns the physical capacity of the block in bytes.
340
+ * Returns the block's physical capacity in bytes.
506
341
  *
507
- * Capacity corresponds to the space reserved for all slots in the
508
- * block, regardless of how many elements are currently occupied.
342
+ * Capacity is the space reserved for all slots in the
343
+ * block, regardless of how many elements are currently
344
+ * occupied.
509
345
  *
510
346
  * @param {number} handler - Block handle.
511
347
  * @returns {number} Physical capacity of the block, in bytes.
@@ -521,10 +357,10 @@ export default class Balloc {
521
357
  */
522
358
  occupied(handler: number): number;
523
359
  /**
524
- * Returns the block's capacity in number of elements.
360
+ * Returns the block capacity as a number of elements.
525
361
  *
526
362
  * The value corresponds to the total number of physically reserved slots,
527
- * not the currently occupied quantity.
363
+ * not the number currently occupied.
528
364
  *
529
365
  * @param {number} handler - Block handle.
530
366
  * @returns {number} Total number of slots available in the block.
@@ -532,10 +368,10 @@ export default class Balloc {
532
368
  */
533
369
  length(handler: number): number;
534
370
  /**
535
- * Checks if the memory block has reached its allocation capacity.
371
+ * Checks whether the memory block has reached its allocation capacity.
536
372
  *
537
373
  * A block is considered full when the number of occupied elements
538
- * equals its total allocated capacity, leaving no positions available
374
+ * equals its total allocated capacity, leaving no available positions
539
375
  * to store new elements.
540
376
  *
541
377
  * @param {number} handler - Block handle.
@@ -544,245 +380,134 @@ export default class Balloc {
544
380
  */
545
381
  isFull(handler: number): boolean;
546
382
  /**
547
- * Copies occupied elements from one block to another.
548
- *
549
- * Copying starts at the first element of `source` and the first slot of
550
- * `destination`. The quantity effectively copied is limited by the number of
551
- * occupied elements in the source, the physical capacity of the destination, and the
552
- * limit specified in `slots`.
553
- *
554
- * Destination occupancy is increased, when necessary, to cover the
555
- * copied elements. Destination capacity is unchanged.
556
- *
557
- * The operation uses `Uint8Array.prototype.copyWithin()` on the `dataBus`,
558
- * therefore the return value is the `Uint8Array` representing the data bus.
559
- *
560
- * @param {number} source - Source block handle.
561
- * @param {number} destination - Destination block handle.
562
- * @param {number} [slots=UNKNOWN] - Maximum number of elements to copy.
563
- * `UNKNOWN` represents the sentinel value used not to impose an
564
- * additional limit.
565
- * @returns {Uint8Array} The `dataBus` after the operation.
566
- * @throws {Error} If handles are invalid, corrupted,
567
- * or the destination block is borrowed via withView().
568
- */
569
- copy(source: number, destination: number, slots?: number): Uint8Array;
383
+ * Copies occupied elements from one block to the beginning of another.
384
+ *
385
+ * The copied amount is the minimum of the source occupancy, destination
386
+ * capacity, and slots. The copy uses TypedArray.prototype.set(), converting
387
+ * values according to the destination view type. Destination occupancy
388
+ * becomes the greater of the previous occupancy and the number of
389
+ * copied elements.
390
+ *
391
+ * @param {number} source Handle of the source block.
392
+ * @param {number} destination Handle of the destination block.
393
+ * @param {number} [slots=UNKNOWN] Maximum number of elements to copy.
394
+ * @returns {TypedArray} Typed view of the destination block.
395
+ * @throws {Error} If either handle does not exist or the destination is borrowed.
396
+ */
397
+ copy(source: number, destination: number, slots?: number): TypedArray;
570
398
  /**
571
399
  * Copies a region of elements within the same block.
572
400
  *
573
401
  * Indices are zero-based and follow the semantics of
574
402
  * `Array.prototype.copyWithin()`: `target` identifies the destination position,
575
- * `start` the starting source position, and `length` the maximum quantity of
403
+ * `start` the source starting position, and `length` the maximum number of
576
404
  * elements to copy.
577
405
  *
578
- * Negative indices are interpreted from the end of the block's capacity.
579
- * After this normalization, indices are clamped to physical capacity.
580
- * The copied quantity is also limited by effectively occupied elements
581
- * and available space starting from `target`.
406
+ * Negative indices are interpreted relative to the end of the block's
407
+ * capacity. After normalization, the indices are clamped to the physical
408
+ * capacity. The copied amount is also limited by the elements
409
+ * actually occupied and by the space available from `target`.
582
410
  *
583
- * The operation supports overlapping regions and can increase block occupancy
584
- * when the destination range exceeds previous occupancy.
411
+ * The operation supports overlapping regions and can increase the block's
412
+ * occupancy when the destination range extends beyond the current occupancy.
585
413
  *
586
414
  * @param {number} handler - Block handle.
587
- * @param {number} target - Initial destination index.
588
- * @param {number} start - Initial source index.
415
+ * @param {number} target - Starting destination index.
416
+ * @param {number} start - Starting source index.
589
417
  * @param {number} length - Maximum number of elements to copy.
590
418
  * @returns {Uint8Array} The `dataBus` after the operation.
591
- * @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
419
+ * @throws {Error} If the handle is invalid or corrupted, or the block is borrowed by withView().
592
420
  */
593
421
  copyWithin(handler: number, target: number, start: number, length: number): Uint8Array;
594
422
  /**
595
- * Appends occupied elements of `source` to the end of `target`.
423
+ * Appends the occupied elements of `source` to the end of `target`.
596
424
  *
597
- * The copied quantity is limited by the number of occupied elements in the
598
- * source and remaining free space in the destination's capacity.
425
+ * The copied amount is limited by the number of occupied elements in the
426
+ * source and by the remaining free space in the destination capacity.
599
427
  *
600
- * The operation supports `target` and `source` referencing the same block.
601
- * In this case, copying is performed over the block's own region and
602
- * preserves `copyWithin()` overlap semantics.
428
+ * The operation supports `target` and `source` referring to the same block.
429
+ * In this case, the copy is performed within the block itself and
430
+ * preserves the overlapping-region semantics of `copyWithin()`.
603
431
  *
604
- * @param {number} target - Handle of the block that will receive elements.
432
+ * @param {number} target - Handle of the block that will receive the elements.
605
433
  * @param {number} source - Handle of the block whose elements will be
606
434
  * appended.
607
- * @returns {number} Number of elements effectively appended.
608
- * @throws {Error} If handles are invalid, corrupted,
609
- * or the destination block is borrowed via withView().
435
+ * @returns {number} Number of elements actually appended.
436
+ * @throws {Error} If the handles are invalid or corrupted
437
+ * or the destination block is borrowed by withView().
610
438
  */
611
439
  append(target: number, source: number): number;
612
440
  /**
613
441
  * Creates an independent copy of a block.
614
442
  *
615
- * The new block has the same physical capacity and occupancy as the
616
- * original block. All bytes in the reserved region, including currently
617
- * unoccupied positions, are copied.
443
+ * The original view size is passed to alloc() as a size in bytes.
444
+ * For types with more than one byte per element, the resulting capacity
445
+ * may be smaller than the original; in that case, set() may throw a RangeError
446
+ * when attempting to copy the entire view. The view's elements are copied,
447
+ * including those outside the occupied region.
618
448
  *
619
- * The new block receives a new handle and remains subject to normal
620
- * allocation and recycling rules.
449
+ * The new block receives its own handle.
621
450
  *
622
- * @param {number} handler - Handle of the block to be cloned.
451
+ * @param {number} handler - Handle of the block to clone.
623
452
  * @returns {number} Handle of the new block.
624
453
  * @throws {Error} If the handle is invalid or corrupted.
625
454
  */
626
455
  clone(handler: number): number;
627
456
  /**
628
- * Swaps the data regions associated with two blocks.
457
+ * Swaps the block objects associated with two handles.
629
458
  *
630
- * The operation swaps region addresses, capacities, and occupancies
631
- * between headers. Handles remain unchanged:
632
- * after the operation, each handle continues identifying its own
633
- * header, but that header now describes the region previously
634
- * belonging to the other block.
459
+ * The operation swaps the references stored in bus; it does not copy data
460
+ * or change the numeric handles. After the swap, each handle points
461
+ * to the block object previously associated with the other handle.
635
462
  *
636
- * No data is copied in the `dataBus`; only the metadata of the two
637
- * headers is modified.
638
- *
639
- * @param {number} source - Handle of the first block.
640
- * @param {number} target - Handle of the second block.
463
+ * @param {number} source First handle.
464
+ * @param {number} target Second handle.
641
465
  * @returns {void}
642
- * @throws {Error} If handles are invalid, corrupted,
643
- * or either block is borrowed via withView().
466
+ * @throws {Error} If either handle does not exist or either block is
467
+ * borrowed.
644
468
  */
645
469
  swap(source: number, target: number): void;
646
470
  /**
647
- * Serializes the content and metadata of a memory block.
471
+ * Serializes a block into a CBOR version 2 envelope.
648
472
  *
649
- * The method extracts occupied block data via `pick()`,
650
- * groups it alongside capacity and word type information
651
- * into a data envelope, and encodes it using the CBOR format.
473
+ * The envelope contains the bucket type, capacity in elements,
474
+ * occupancy, and a copy of the occupied elements (payload). Encoding
475
+ * is performed by cbor-x's encode().
652
476
  *
653
- * @param {number} handler - Handle of the block to be serialized.
654
- * @returns {Uint8Array} A buffer containing the serialized block data.
655
- * @throws {Error} If the handle is invalid or corrupted.
477
+ * @param {number} handler Block handle.
478
+ * @returns {Uint8Array} Serialized CBOR data.
479
+ * @throws {Error} If the handle does not exist or the capacity
480
+ * or occupancy metadata is inconsistent.
656
481
  */
657
482
  dump(handler: number): Uint8Array;
658
483
  /**
659
- * Restores a memory block from serialized data.
484
+ * Decodes a CBOR envelope and recreates the serialized block.
660
485
  *
661
- * Decodes the CBOR envelope, validates whether the word type of the serialized
662
- * data is compatible with the current allocator instance, and allocates
663
- * a new block with the capacity required to accommodate the content.
664
- * Then, original data and occupancy are restored in the new block.
486
+ * Accepts only ArrayBuffer or Uint8Array. Validates the envelope structure,
487
+ * version 2, bucket type, capacity, occupancy, and the type and
488
+ * length of the payload. If the instance has bucketSize fixed in the
489
+ * constructor, the serialized type must match it. The capacity
490
+ * recorded in elements is converted to bytes before allocation.
665
491
  *
666
- * @param {Uint8Array|ArrayBuffer} serialized - Buffer containing serialized data.
667
- * @returns {number} Handle of the newly recreated block.
668
- * @throws {Error} If the decoded data's word type differs from the allocator's configuration.
492
+ * @param {Uint8Array|ArrayBuffer} serialized Buffer containing the CBOR envelope.
493
+ * @returns {number} Handle of the restored block.
494
+ * @throws {TypeError} If the input, envelope, or payload have
495
+ * invalid types or structures.
496
+ * @throws {Error} If the version is not 2 or the bucket type differs
497
+ * from bucketSize when the instance has a fixed default type.
498
+ * @throws {RangeError} If the capacity or occupancy is invalid.
669
499
  */
670
500
  load(serialized: Uint8Array | ArrayBuffer): number;
671
501
  /**
672
- * Prevents modification operations on a borrowed block.
673
- *
674
- * Checks the VIEW_LOCK flag in the header associated with the provided address.
675
- *
676
- * @param {number} headerAddress - Address of the header in controlBus.
677
- * @returns {void}
678
- * @throws {Error} If the block is borrowed via withView().
679
- * @private
680
- */
681
- private assertNotBorrowed;
682
- /**
683
- * Prevents operations that replace or remap the dataBus
684
- * while any segment is borrowed.
685
- *
686
- * @returns {void}
687
- * @throws {Error} If any block is borrowed via withView().
688
- * @private
689
- */
690
- private assertNoActiveViews;
691
- /**
692
- * [INTERNAL USE]
693
- * Decodes metadata associated with a handle.
694
- *
695
- * The handle is split into generation and header address. The cookie stored
696
- * in the header is then recalculated to validate the combination; only after
697
- * this validation are metadata read.
698
- *
699
- * Decoded fields are written to the `out` object, which is returned
700
- * by the function itself. The object can be reused between calls to avoid
701
- * new allocations.
702
- *
703
- * @param {number} handler - Handle to be decoded and validated.
704
- * @param {Metadata} out - Object that will receive decoded metadata.
705
- * @returns {Metadata} The same reference provided in `out`.
706
- * @throws {Error} If the header cookie does not match the handle or
707
- * if the handle does not identify a valid header.
708
- * @private
709
- */
710
- private extractMetadata;
711
- /**
712
- * [INTERNAL USE]
713
- * Calculates a header's validation cookie.
714
- *
715
- * The cookie is derived from the header address and the 11 generation bits via
716
- * fast hash.
717
- * The result is reduced to 8 bits.
718
- *
719
- * The value zero is reserved as an invalid header indicator; therefore,
720
- * when the calculation produces zero, the method returns `1`.
721
- *
722
- * The cookie does not constitute a cryptographic mechanism. Its purpose is
723
- * to detect invalid, stale, or corrupted handles within the allocator's
724
- * memory management model.
725
- *
726
- * @param {number} addr - Header address.
727
- * @param {number} gen - Generation associated with the handle. Only the 11
728
- * least significant bits are considered.
729
- * @returns {number} 8-bit cookie in the range [1, 255].
730
- * @private
731
- */
732
- private bakeCookie;
733
- /**
734
- * Returns the number of regions currently stored in the recycling list.
735
- *
736
- * Each region corresponds to a freed block that could not be returned
737
- * directly to the top of the `dataBus` and, therefore, remains available for
738
- * reuse by a future allocation of identical capacity.
739
- *
740
- * @returns {number} Number of free regions kept in `recycle`.
741
- */
742
- recycleCount(): number;
743
- /**
744
- * Returns the total bytes belonging to regions currently stored in the
745
- * recycling list.
746
- *
747
- * The value is calculated by summing each free region's capacity multiplied
748
- * by the number of regions registered for that capacity.
749
- *
750
- * @returns {number} Number of bytes occupied by recyclable regions.
751
- */
752
- get recycleBytes(): number;
753
- /**
754
- * Returns the quantity of allocated bytes that do not belong to currently
755
- * recyclable regions.
756
- *
757
- * The value is obtained by subtracting the bytes belonging to free regions
758
- * kept in `recycle` from the total advance of `dataPointer`.
759
- *
760
- * @returns {number} Number of bytes associated with non-recyclable regions
761
- * within the area already used by `dataBus`.
762
- */
763
- get allocatedBytes(): number;
764
- /**
765
- * Returns the quantity of bytes not yet used at the top of the `dataBus`.
766
- *
767
- * This space corresponds to the region between `dataPointer` and the end of the
768
- * capacity currently reserved for the buffer.
769
- *
770
- * @returns {number} Number of bytes available after `dataPointer`.
771
- */
772
- get unallocatedBytes(): number;
773
- /**
774
- * Returns the ratio between recyclable memory and the used heap area.
775
- *
776
- * The metric considers free regions kept in `recycle` as fragmentation
777
- * and uses `dataPointer` as the denominator. When no bytes have been used
778
- * by the heap, the result is zero.
502
+ * Loads data by delegating the operation to an adapter.
779
503
  *
780
- * The value does not represent the fraction of the entire `dataBus` capacity, but
781
- * specifically the proportion of recyclable bytes within the area already traversed
782
- * by the bump pointer.
504
+ * The adapter must expose a load(allocator) function. It is called
505
+ * synchronously with the current Balloc instance, and its return value
506
+ * is passed through unchanged.
783
507
  *
784
- * @returns {number} Fragmentation ratio in the range [0, 1] under normal
785
- * operating conditions.
508
+ * @param {FormatAdapter} adapter Adapter implementing load(allocator).
509
+ * @returns {*} Value returned by adapter.load(this).
510
+ * @throws {TypeError} If the adapter does not exist or load is not a function.
786
511
  */
787
- get fragmentationRatio(): number;
512
+ loadData(adapter: FormatAdapter): any;
788
513
  }