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