balloc 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.MD +3 -18
- package/README.ar.md +2 -21
- package/README.en.md +2 -21
- package/README.es.md +2 -21
- package/README.jp.md +1 -20
- package/README.pt.md +2 -21
- package/README.zh.md +1 -20
- package/docs/API /342/200/224 balloc.ar.md" +89 -37
- package/docs/API /342/200/224 balloc.en.md" +131 -29
- package/docs/API /342/200/224 balloc.es.md" +76 -23
- package/docs/API /342/200/224 balloc.jp.md" +113 -28
- package/docs/API /342/200/224 balloc.pt.md" +65 -99
- package/docs/API /342/200/224 balloc.zh.md" +84 -20
- package/package.json +2 -2
- package/src/ar/balloc.cjs +56 -25
- package/src/ar/balloc.js +1 -1
- package/src/ar/balloc.mjs +89 -47
- package/src/en/balloc.cjs +57 -13
- package/src/en/balloc.js +1 -1
- package/src/en/balloc.mjs +104 -49
- package/src/es/balloc.cjs +57 -27
- package/src/es/balloc.js +1 -1
- package/src/es/balloc.mjs +90 -49
- package/src/jp/balloc.cjs +57 -26
- package/src/jp/balloc.js +1 -1
- package/src/jp/balloc.mjs +88 -46
- package/src/pt/balloc.cjs +57 -27
- package/src/pt/balloc.js +1 -1
- package/src/pt/balloc.mjs +91 -50
- package/src/zh/balloc.cjs +56 -23
- package/src/zh/balloc.js +1 -1
- package/src/zh/balloc.mjs +84 -40
- package/types/ar/balloc.d.mts +18 -19
- package/types/en/balloc.d.mts +18 -6
- package/types/es/balloc.d.mts +19 -21
- package/types/jp/balloc.d.mts +19 -20
- package/types/pt/balloc.d.mts +18 -20
- package/types/zh/balloc.d.mts +18 -17
- package/change.log.md +0 -7
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
You can also get this documentation translated into other languages:
|
|
2
2
|
| Language | Link |
|
|
3
3
|
|---|---|
|
|
4
|
-
| Arabic | [API — balloc.ar.md](./
|
|
5
|
-
| Chinese | [API — balloc.zh.md](./
|
|
6
|
-
| Spanish | [API — balloc.es.md](./
|
|
7
|
-
| English | [API — balloc.en.md](./
|
|
8
|
-
| Japanese | [API — balloc.jp.md](./
|
|
9
|
-
| Portuguese | [API — balloc.pt.md](./
|
|
4
|
+
| Arabic | [API — balloc.ar.md](./API%20—%20balloc.ar.md) |
|
|
5
|
+
| Chinese | [API — balloc.zh.md](./API%20—%20balloc.zh.md) |
|
|
6
|
+
| Spanish | [API — balloc.es.md](./API%20—%20balloc.es.md) |
|
|
7
|
+
| English | [API — balloc.en.md](./API%20—%20balloc.en.md) |
|
|
8
|
+
| Japanese | [API — balloc.jp.md](./API%20—%20balloc.jp.md) |
|
|
9
|
+
| Portuguese | [API — balloc.pt.md](./API%20—%20balloc.pt.md) |
|
|
10
10
|
|
|
11
11
|
# Balloc.js
|
|
12
12
|
|
|
@@ -27,6 +27,7 @@ Balloc
|
|
|
27
27
|
├── Block Lifecycle
|
|
28
28
|
│ ├── alloc()
|
|
29
29
|
│ ├── realloc()
|
|
30
|
+
│ ├── shrink()
|
|
30
31
|
│ ├── free()
|
|
31
32
|
│ └── gc()
|
|
32
33
|
│
|
|
@@ -49,12 +50,16 @@ Balloc
|
|
|
49
50
|
│ ├── fill()
|
|
50
51
|
│ ├── fillAll()
|
|
51
52
|
│ ├── put()
|
|
52
|
-
│
|
|
53
|
+
│ ├── pick()
|
|
54
|
+
│ ├── indexOf()
|
|
55
|
+
│ ├── lastIndexOf()
|
|
56
|
+
│ └── withView()
|
|
53
57
|
│
|
|
54
58
|
├── Capacity and Occupancy
|
|
55
59
|
│ ├── byteSize()
|
|
56
60
|
│ ├── occupied()
|
|
57
|
-
│
|
|
61
|
+
│ ├── length()
|
|
62
|
+
│ └── isFull()
|
|
58
63
|
│
|
|
59
64
|
├── Inter-block Operations
|
|
60
65
|
│ ├── copy()
|
|
@@ -126,28 +131,44 @@ byteSize(handler) → reserved physical bytes
|
|
|
126
131
|
|
|
127
132
|
---
|
|
128
133
|
|
|
129
|
-
## Memory
|
|
134
|
+
## Memory Borrowing
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
Balloc supports **scoped, zero-copy access** to the occupied data of one or more blocks. This is a borrowing mechanism: a callback receives typed-array views over Balloc's internal storage, allowing direct reads and writes without allocating a copy.
|
|
132
137
|
|
|
133
|
-
The borrow is synchronous.
|
|
138
|
+
The borrow is deliberately scoped to a synchronous callback. While the callback is running, Balloc locks each borrowed block against operations that could invalidate or structurally modify its view. The lock is released in a `finally` block, including when the callback throws.
|
|
139
|
+
|
|
140
|
+
### A single block
|
|
141
|
+
|
|
142
|
+
Pass a handler followed by a callback. The callback receives a typed-array view containing only the block's occupied elements; unused capacity is excluded.
|
|
134
143
|
|
|
135
144
|
```js
|
|
136
|
-
const
|
|
145
|
+
const count = memory.withView(handler, view => {
|
|
137
146
|
view[0] = 42;
|
|
138
147
|
return view.length;
|
|
139
148
|
});
|
|
140
149
|
```
|
|
141
150
|
|
|
142
|
-
|
|
151
|
+
Writes through the view immediately affect the block. No copy is made, and the callback's return value is returned by `withView()`.
|
|
152
|
+
|
|
153
|
+
### Multiple blocks
|
|
154
|
+
|
|
155
|
+
Pass two or more handlers before the callback. The callback receives one view per handler, in the same order:
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
memory.withView(source, target, (sourceView, targetView) => {
|
|
159
|
+
targetView.set(sourceView.subarray(0, targetView.length));
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Each handler must be valid, distinct, and not already borrowed. Balloc acquires the locks before invoking the callback and releases all acquired locks when it exits.
|
|
143
164
|
|
|
144
|
-
###
|
|
165
|
+
### Borrowing constraints
|
|
145
166
|
|
|
146
|
-
A
|
|
167
|
+
A borrowed view, or any subview derived from it, must not be retained, returned, or used after the callback finishes. If the callback returns a Promise, the borrow ends immediately when that Promise is returned; it is not held until the Promise settles. The callback must therefore complete all view access synchronously.
|
|
147
168
|
|
|
148
|
-
|
|
169
|
+
While a block is borrowed, operations that modify that block are rejected with `Error`. This includes `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `shrink()`, `free()`, and `copyWithin()`. `copy()` and `append()` are rejected when the borrowed block is the destination; a borrowed source is allowed. `swap()` is rejected if either block is borrowed. Read-only operations remain available.
|
|
149
170
|
|
|
150
|
-
Operations that replace or remap `dataBus` are
|
|
171
|
+
Operations that replace or remap `dataBus` are rejected while any view is active. This includes `gc()` and growth of `dataBus` triggered by `alloc()` or `realloc()`.
|
|
151
172
|
|
|
152
173
|
# 1. Instantiation
|
|
153
174
|
|
|
@@ -162,12 +183,12 @@ Storage is split between `dataBus`, intended for block data, and `controlBus`, i
|
|
|
162
183
|
| Parameter | Type | Default | Description |
|
|
163
184
|
| --- | --- | --- | --- |
|
|
164
185
|
| `size` | `number` | `65535` | Initial capacity of `dataBus`, in bytes. |
|
|
165
|
-
| `bucketSize` | `BucketType` |
|
|
186
|
+
| `bucketSize` | `BucketType` | `"32u"` | Element type and width. |
|
|
166
187
|
| `metadataSize` | `number` | `1024` | Initial capacity of `controlBus`, in bytes. |
|
|
167
188
|
|
|
168
189
|
`size` must be a safe integer within the range `[2, 0x80000000]`.
|
|
169
190
|
|
|
170
|
-
`bucketSize` accepts a `BucketType` value which is a string in the format `[
|
|
191
|
+
`bucketSize` accepts a `BucketType` value which is a string in the format `[Bit width][data type]`, accepting only values from the table:
|
|
171
192
|
|
|
172
193
|
| Signed Integer | Unsigned Integer | Float |
|
|
173
194
|
| --- | --- | --- |
|
|
@@ -305,6 +326,48 @@ The operation doubles physical capacity, moving to the next power of two.
|
|
|
305
326
|
|
|
306
327
|
---
|
|
307
328
|
|
|
329
|
+
## `shrink(handler)`
|
|
330
|
+
|
|
331
|
+
Reduces a block's physical capacity to the smallest supported power of two that can contain its current occupied elements. The minimum capacity is two elements. If the current capacity is already sufficient, the method does nothing.
|
|
332
|
+
|
|
333
|
+
The block's data remains at the same address, and its handler remains valid because the header is preserved. Only the capacity recorded in the header changes. The released tail is reclaimed according to the block's position:
|
|
334
|
+
|
|
335
|
+
* If the block is at the top of `dataBus`, `dataPointer` moves backward and the released space is returned directly to the heap.
|
|
336
|
+
* Otherwise, the released tail is split into power-of-two regions and each region is added to the recycling list for later reuse.
|
|
337
|
+
|
|
338
|
+
`shrink()` does not change occupancy or move the occupied elements.
|
|
339
|
+
|
|
340
|
+
### Parameters
|
|
341
|
+
|
|
342
|
+
| Parameter | Type | Description |
|
|
343
|
+
| --- | --- | --- |
|
|
344
|
+
| `handler` | `number` | Block handler. |
|
|
345
|
+
|
|
346
|
+
### Return
|
|
347
|
+
|
|
348
|
+
```text
|
|
349
|
+
void
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Exceptions
|
|
353
|
+
|
|
354
|
+
* `Error` — invalid or corrupted handler, or the block is currently borrowed through `withView()`.
|
|
355
|
+
|
|
356
|
+
### Example
|
|
357
|
+
|
|
358
|
+
```js
|
|
359
|
+
const handler = memory.alloc(128);
|
|
360
|
+
memory.put(handler, [10, 20, 30]);
|
|
361
|
+
memory.shrink(handler);
|
|
362
|
+
|
|
363
|
+
console.log(memory.length(handler)); // 4
|
|
364
|
+
console.log(memory.occupied(handler)); // 3
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
The resulting capacity is the smallest power of two that accommodates the occupied elements.
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
308
371
|
## `free(handler)`
|
|
309
372
|
|
|
310
373
|
Frees a block.
|
|
@@ -522,6 +585,29 @@ Finds the first occurrence of a value, searching in ascending index order. Only
|
|
|
522
585
|
|
|
523
586
|
Finds the last occurrence of a value, searching in descending index order. Only occupied elements are searched; unused block capacity is ignored.
|
|
524
587
|
|
|
588
|
+
Both search methods return the matching zero-based index, or `-1` when the value is not found. They throw `Error` if the handler is invalid or corrupted.
|
|
589
|
+
|
|
590
|
+
## `withView(...args)`
|
|
591
|
+
|
|
592
|
+
Borrows one or more blocks for the duration of a synchronous callback. Supply one or more block handlers followed by the callback; the callback receives the corresponding typed-array views in handler order. The full borrowing model, examples, and restrictions are described in [Memory Borrowing](#memory-borrowing).
|
|
593
|
+
|
|
594
|
+
### Parameters
|
|
595
|
+
|
|
596
|
+
| Parameter | Type | Description |
|
|
597
|
+
| --- | --- | --- |
|
|
598
|
+
| `...args` | `number[] + callback` | One or more block handlers followed by the callback. |
|
|
599
|
+
|
|
600
|
+
### Return
|
|
601
|
+
|
|
602
|
+
The value returned by the callback.
|
|
603
|
+
|
|
604
|
+
### Exceptions
|
|
605
|
+
|
|
606
|
+
* `TypeError` — no handler is provided or the final argument is not a function.
|
|
607
|
+
* `Error` — a handler is invalid, duplicated, or already borrowed.
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
525
611
|
## `get(handler, index)`
|
|
526
612
|
|
|
527
613
|
Gets the element at the specified index.
|
|
@@ -723,11 +809,6 @@ const count = memory.occupied(handler);
|
|
|
723
809
|
|
|
724
810
|
## `length(handler)`
|
|
725
811
|
|
|
726
|
-
### `isFull(handler)`
|
|
727
|
-
|
|
728
|
-
Returns `true` when the number of occupied elements equals the block's physical capacity; otherwise returns `false`.
|
|
729
|
-
|
|
730
|
-
|
|
731
812
|
Returns the total quantity of available physical slots.
|
|
732
813
|
|
|
733
814
|
Capacity is independent of occupancy:
|
|
@@ -744,6 +825,22 @@ const capacity = memory.length(handler);
|
|
|
744
825
|
|
|
745
826
|
---
|
|
746
827
|
|
|
828
|
+
## `isFull(handler)`
|
|
829
|
+
|
|
830
|
+
Returns `true` when the number of occupied elements equals the block's physical capacity; otherwise returns `false`.
|
|
831
|
+
|
|
832
|
+
### Return
|
|
833
|
+
|
|
834
|
+
```text
|
|
835
|
+
boolean
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
### Exceptions
|
|
839
|
+
|
|
840
|
+
`Error` — invalid or corrupted handler.
|
|
841
|
+
|
|
842
|
+
---
|
|
843
|
+
|
|
747
844
|
# 6. Inter-block Operations
|
|
748
845
|
|
|
749
846
|
## `copy(source, destiny, slots = UNKNOWN)`
|
|
@@ -1256,25 +1353,30 @@ Generation participates in cookie validation. Consequently, an invalid handler o
|
|
|
1256
1353
|
| Instantiation | `constructor()` | `Balloc`|
|
|
1257
1354
|
| Lifecycle | `alloc()` | `number`|
|
|
1258
1355
|
| Lifecycle | `realloc()` | `void`|
|
|
1356
|
+
| Lifecycle | `shrink()` | `void`|
|
|
1259
1357
|
| Lifecycle | `free()` | `void`|
|
|
1260
1358
|
| Lifecycle | `gc()` | `void`|
|
|
1261
1359
|
| Stack | `push()` | `boolean`|
|
|
1262
|
-
| Stack | `pop()` | `number` |
|
|
1263
|
-
| Stack | `peek()` | `number` |
|
|
1360
|
+
| Stack | `pop()` | `number \| undefined` |
|
|
1361
|
+
| Stack | `peek()` | `number \| undefined` |
|
|
1264
1362
|
| Queue | `nudge()` | `boolean`|
|
|
1265
|
-
| Queue | `pull()` | `number` |
|
|
1266
|
-
| Queue | `head()` | `number` |
|
|
1363
|
+
| Queue | `pull()` | `number \| undefined` |
|
|
1364
|
+
| Queue | `head()` | `number \| undefined` |
|
|
1267
1365
|
| Access | `has()` | `boolean`|
|
|
1268
|
-
| Access | `get()` | `number` |
|
|
1366
|
+
| Access | `get()` | `number \| undefined` |
|
|
1269
1367
|
| Access | `set()` | `boolean`|
|
|
1270
1368
|
| Access | `clear()` | `void`|
|
|
1271
1369
|
| Access | `fill()` | `void`|
|
|
1272
1370
|
| Access | `fillAll()` | `void`|
|
|
1273
1371
|
| Access | `put()` | `void`|
|
|
1274
1372
|
| Access | `pick()` | `TypedArray`|
|
|
1373
|
+
| Access | `indexOf()` | `number`|
|
|
1374
|
+
| Access | `lastIndexOf()` | `number`|
|
|
1375
|
+
| Access | `withView()` | `any`|
|
|
1275
1376
|
| Capacity | `byteSize()` | `number`|
|
|
1276
1377
|
| Capacity | `occupied()` | `number`|
|
|
1277
1378
|
| Capacity | `length()` | `number`|
|
|
1379
|
+
| Capacity | `isFull()` | `boolean`|
|
|
1278
1380
|
| Blocks | `copy()` | `Uint8Array`|
|
|
1279
1381
|
| Blocks | `copyWithin()` | `Uint8Array`|
|
|
1280
1382
|
| Blocks | `append()` | `number`|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
También puedes conseguir esta documentación traducida a otros idiomas:
|
|
2
2
|
| Idioma | Enlace |
|
|
3
3
|
|---|---|
|
|
4
|
-
| Árabe | [API — balloc.ar.md](./
|
|
5
|
-
| Chino | [API — balloc.zh.md](./
|
|
6
|
-
| Español | [API — balloc.es.md](./
|
|
7
|
-
| Inglés | [API — balloc.en.md](./
|
|
8
|
-
| Japonés | [API — balloc.jp.md](./
|
|
9
|
-
| Portugués | [API — balloc.pt.md](./
|
|
4
|
+
| Árabe | [API — balloc.ar.md](./API%20—%20balloc.ar.md) |
|
|
5
|
+
| Chino | [API — balloc.zh.md](./API%20—%20balloc.zh.md) |
|
|
6
|
+
| Español | [API — balloc.es.md](./API%20—%20balloc.es.md) |
|
|
7
|
+
| Inglés | [API — balloc.en.md](./API%20—%20balloc.en.md) |
|
|
8
|
+
| Japonés | [API — balloc.jp.md](./API%20—%20balloc.jp.md) |
|
|
9
|
+
| Portugués | [API — balloc.pt.md](./API%20—%20balloc.pt.md) |
|
|
10
10
|
|
|
11
11
|
# Balloc.js
|
|
12
12
|
|
|
@@ -27,6 +27,7 @@ Balloc
|
|
|
27
27
|
├── Ciclo de vida de los bloques
|
|
28
28
|
│ ├── alloc()
|
|
29
29
|
│ ├── realloc()
|
|
30
|
+
│ ├── shrink()
|
|
30
31
|
│ ├── free()
|
|
31
32
|
│ └── gc()
|
|
32
33
|
│
|
|
@@ -35,7 +36,6 @@ Balloc
|
|
|
35
36
|
│ │ ├── push()
|
|
36
37
|
│ │ ├── pop()
|
|
37
38
|
│ │ └── peek()
|
|
38
|
-
│ │
|
|
39
39
|
│ └── Queue
|
|
40
40
|
│ ├── nudge()
|
|
41
41
|
│ ├── pull()
|
|
@@ -49,12 +49,16 @@ Balloc
|
|
|
49
49
|
│ ├── fill()
|
|
50
50
|
│ ├── fillAll()
|
|
51
51
|
│ ├── put()
|
|
52
|
-
│
|
|
52
|
+
│ ├── pick()
|
|
53
|
+
│ ├── indexOf()
|
|
54
|
+
│ ├── lastIndexOf()
|
|
55
|
+
│ └── withView()
|
|
53
56
|
│
|
|
54
57
|
├── Capacidad y ocupación
|
|
55
58
|
│ ├── byteSize()
|
|
56
59
|
│ ├── occupied()
|
|
57
|
-
│
|
|
60
|
+
│ ├── length()
|
|
61
|
+
│ └── isFull()
|
|
58
62
|
│
|
|
59
63
|
├── Operaciones entre bloques
|
|
60
64
|
│ ├── copy()
|
|
@@ -78,11 +82,9 @@ Balloc
|
|
|
78
82
|
├── Reciclaje
|
|
79
83
|
│ ├── recyclePush()
|
|
80
84
|
│ └── recyclePop()
|
|
81
|
-
│
|
|
82
85
|
├── Escalado
|
|
83
86
|
│ ├── grow()
|
|
84
87
|
│ └── headerGrow()
|
|
85
|
-
│
|
|
86
88
|
└── Utilidades
|
|
87
89
|
├── extractMetadata()
|
|
88
90
|
└── bakeCookie()
|
|
@@ -122,28 +124,44 @@ byteSize(handler) → bytes físicos reservados
|
|
|
122
124
|
|
|
123
125
|
---
|
|
124
126
|
|
|
125
|
-
## Préstamo de memoria
|
|
127
|
+
## Préstamo de memoria
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
Balloc permite el acceso directo y sin copia a los datos ocupados de uno o varios bloques. El callback recibe vistas tipadas sobre el almacenamiento interno, lo que permite leer y escribir sin asignar una copia.
|
|
128
130
|
|
|
129
|
-
El préstamo
|
|
131
|
+
El préstamo se limita a un callback síncrono. Mientras se ejecuta, Balloc bloquea los bloques prestados frente a operaciones que podrían invalidar las vistas o modificar su estructura. El bloqueo se libera en un bloque `finally`, incluso si se produce una excepción.
|
|
132
|
+
|
|
133
|
+
### Un solo bloque
|
|
134
|
+
|
|
135
|
+
Pasa un handler seguido del callback. Este recibe una vista que contiene únicamente los elementos ocupados, sin la capacidad no utilizada.
|
|
130
136
|
|
|
131
137
|
```js
|
|
132
|
-
const
|
|
138
|
+
const count = memory.withView(handler, view => {
|
|
133
139
|
view[0] = 42;
|
|
134
140
|
return view.length;
|
|
135
141
|
});
|
|
136
142
|
```
|
|
137
143
|
|
|
138
|
-
|
|
144
|
+
Las escrituras a través de la vista modifican inmediatamente el bloque; `withView()` devuelve el valor del callback.
|
|
145
|
+
|
|
146
|
+
### Varios bloques
|
|
147
|
+
|
|
148
|
+
Pasa dos o más handlers antes del callback. Este recibe una vista por handler, en el mismo orden:
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
memory.withView(source, target, (sourceView, targetView) => {
|
|
152
|
+
targetView.set(sourceView.subarray(0, targetView.length));
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Cada handler debe ser válido, distinto y no estar prestado. Balloc adquiere todos los bloqueos antes de ejecutar el callback y los libera al terminar.
|
|
139
157
|
|
|
140
|
-
### Restricciones
|
|
158
|
+
### Restricciones del préstamo
|
|
141
159
|
|
|
142
|
-
|
|
160
|
+
No se debe conservar, devolver ni utilizar la vista, ni ninguna subvista derivada, después de que termine el callback. Si devuelve una Promise, el préstamo finaliza inmediatamente; todo acceso debe ser síncrono.
|
|
143
161
|
|
|
144
|
-
Las operaciones
|
|
162
|
+
Las operaciones que modifican un bloque prestado se rechazan con `Error`: `push()`, `pop()`, `nudge()`, `pull()`, `set()`, `clear()`, `fill()`, `fillAll()`, `put()`, `realloc()`, `shrink()`, `free()` y `copyWithin()`. `copy()` y `append()` se rechazan si el bloque prestado es el destino; `swap()` se rechaza si cualquiera está prestado. Las operaciones de lectura siguen disponibles y se permite prestar el origen en `copy()` y `append()`.
|
|
145
163
|
|
|
146
|
-
Las operaciones que sustituyen o reasignan `dataBus`
|
|
164
|
+
Las operaciones que sustituyen o reasignan `dataBus` se rechazan mientras haya alguna vista activa. Esto incluye `gc()` y el crecimiento de `dataBus` provocado por `alloc()` o `realloc()`.
|
|
147
165
|
|
|
148
166
|
# 1. Instanciación
|
|
149
167
|
|
|
@@ -293,6 +311,30 @@ La operación duplica la capacidad física, llevándola a la siguiente potencia
|
|
|
293
311
|
|
|
294
312
|
---
|
|
295
313
|
|
|
314
|
+
## `shrink(handler)`
|
|
315
|
+
|
|
316
|
+
Reduce la capacidad física del bloque a la menor potencia de dos admitida que pueda contener los elementos ocupados. La capacidad mínima es de dos elementos. Si la capacidad actual ya es suficiente, no hace nada.
|
|
317
|
+
|
|
318
|
+
Los datos permanecen en la misma dirección y el handler sigue siendo válido porque se conserva el header; solo cambia el campo de capacidad. Si el bloque está en la parte superior de `dataBus`, `dataPointer` retrocede y el espacio vuelve al heap. En caso contrario, la cola liberada se divide en regiones de tamaño potencia de dos y se añade a la lista de reciclaje.
|
|
319
|
+
|
|
320
|
+
`shrink()` no modifica la ocupación ni mueve los elementos.
|
|
321
|
+
|
|
322
|
+
### Parámetros
|
|
323
|
+
|
|
324
|
+
| Parámetro | Tipo | Descripción |
|
|
325
|
+
|---|---|---|
|
|
326
|
+
| `handler` | `number` | Handler del bloque. |
|
|
327
|
+
|
|
328
|
+
### Retorno
|
|
329
|
+
|
|
330
|
+
`void`
|
|
331
|
+
|
|
332
|
+
### Excepciones
|
|
333
|
+
|
|
334
|
+
`Error` — handler no válido o corrupto, o el bloque está prestado mediante `withView()`.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
296
338
|
## `free(handler)`
|
|
297
339
|
|
|
298
340
|
Libera un bloque.
|
|
@@ -490,11 +532,17 @@ boolean
|
|
|
490
532
|
|
|
491
533
|
## `indexOf(handler, searchElement, fromIndex = 0)`
|
|
492
534
|
|
|
493
|
-
|
|
535
|
+
Busca la primera aparición de un valor en orden ascendente de índices. Solo examina los elementos ocupados e ignora la capacidad no utilizada.
|
|
494
536
|
|
|
495
537
|
## `lastIndexOf(handler, searchElement, fromIndex = -1)`
|
|
496
538
|
|
|
497
|
-
|
|
539
|
+
Busca la última aparición de un valor en orden descendente de índices. Solo examina los elementos ocupados e ignora la capacidad no utilizada.
|
|
540
|
+
|
|
541
|
+
## `withView(...args)`
|
|
542
|
+
|
|
543
|
+
Presta uno o varios bloques durante un callback síncrono. Pasa uno o más handlers y, al final, el callback; este recibe las vistas en el mismo orden. `...args` es `number[] + callback`. El retorno es el valor del callback. Lanza `TypeError` si falta un handler o el último argumento no es una función, y `Error` si algún handler no es válido, está duplicado o ya está prestado.
|
|
544
|
+
|
|
545
|
+
---
|
|
498
546
|
|
|
499
547
|
## `get(handler, index)`
|
|
500
548
|
|
|
@@ -680,7 +728,7 @@ const count = memory.occupied(handler);
|
|
|
680
728
|
|
|
681
729
|
## `length(handler)`
|
|
682
730
|
|
|
683
|
-
|
|
731
|
+
## `isFull(handler)`
|
|
684
732
|
|
|
685
733
|
Comprobar si el bloque está completamente ocupado. Devuelve `true` cuando el número de elementos ocupados coincide con la capacidad física del bloque; en caso contrario, devuelve `false`.
|
|
686
734
|
|
|
@@ -1172,6 +1220,7 @@ La generación participa en la validación mediante cookie. En consecuencia, un
|
|
|
1172
1220
|
| Instanciación | `constructor()` | `Balloc` |
|
|
1173
1221
|
| Ciclo de vida | `alloc()` | `number` |
|
|
1174
1222
|
| Ciclo de vida | `realloc()` | `void` |
|
|
1223
|
+
| Ciclo de vida | `shrink()` | `void` |
|
|
1175
1224
|
| Ciclo de vida | `free()` | `void` |
|
|
1176
1225
|
| Ciclo de vida | `gc()` | `void` |
|
|
1177
1226
|
| Stack | `push()` | `boolean` |
|
|
@@ -1181,6 +1230,9 @@ La generación participa en la validación mediante cookie. En consecuencia, un
|
|
|
1181
1230
|
| Queue | `pull()` | `number \| undefined` |
|
|
1182
1231
|
| Queue | `head()` | `number \| undefined` |
|
|
1183
1232
|
| Acceso | `has()` | `boolean` |
|
|
1233
|
+
| Acceso | `indexOf()` | `number` |
|
|
1234
|
+
| Acceso | `lastIndexOf()` | `number` |
|
|
1235
|
+
| Acceso | `withView()` | Valor del callback |
|
|
1184
1236
|
| Acceso | `get()` | `number \| undefined` |
|
|
1185
1237
|
| Acceso | `set()` | `boolean` |
|
|
1186
1238
|
| Acceso | `clear()` | `void` |
|
|
@@ -1191,6 +1243,7 @@ La generación participa en la validación mediante cookie. En consecuencia, un
|
|
|
1191
1243
|
| Capacidad | `byteSize()` | `number` |
|
|
1192
1244
|
| Capacidad | `occupied()` | `number` |
|
|
1193
1245
|
| Capacidad | `length()` | `number` |
|
|
1246
|
+
| Capacidad | `isFull()` | `boolean` |
|
|
1194
1247
|
| Bloques | `copy()` | `Uint8Array` |
|
|
1195
1248
|
| Bloques | `copyWithin()` | `Uint8Array` |
|
|
1196
1249
|
| Bloques | `append()` | `number` |
|