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
package/src/zh/balloc.mjs
CHANGED
|
@@ -248,7 +248,7 @@ export default class Balloc {
|
|
|
248
248
|
* @throws {AggregateError} 如果容量已达到支持的最大限制。
|
|
249
249
|
*/
|
|
250
250
|
realloc(handler) {
|
|
251
|
-
|
|
251
|
+
|
|
252
252
|
const generation = (handler / ROTATE_32BITS) & CLAMP_11BITS;
|
|
253
253
|
const headerAddress = handler >>> 0;
|
|
254
254
|
const dataAddress = this.controlAdapter.getUint32(headerAddress + ADDRESS_OFFSET, IS_LITTLE_ENDIAN);
|
|
@@ -293,19 +293,46 @@ export default class Balloc {
|
|
|
293
293
|
this.recyclePush(oldBlockSize, dataAddress);
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
|
|
297
|
-
*
|
|
296
|
+
/**
|
|
297
|
+
* 将内存块缩小到能够容纳其已占用元素的最小 2 的幂次容量,
|
|
298
|
+
* 同时保留其地址和句柄。
|
|
298
299
|
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
300
|
+
* 如果该块位于 dataBus 的顶部,则向后回退 dataPointer。
|
|
301
|
+
* 否则,将释放的尾部区域拆分为若干个容量为 2 的幂次的区域,
|
|
302
|
+
* 并将每个区域归还到回收列表。
|
|
302
303
|
*
|
|
303
|
-
* @param {number} handler -
|
|
304
|
+
* @param {number} handler - 要缩小的内存块的句柄。
|
|
304
305
|
* @returns {void}
|
|
305
|
-
* @throws {Error}
|
|
306
|
+
* @throws {Error} 如果句柄无效、已损坏,或该块正通过 withView() 被借用。
|
|
306
307
|
*/
|
|
308
|
+
shrink(handler) {
|
|
309
|
+
const meta = this.extractMetadata(handler, this.metadata);
|
|
310
|
+
this.assertNotBorrowed(meta.headerAddress);
|
|
311
|
+
|
|
312
|
+
const newCapacity = Math.max(1, 32 - Math.clz32(Math.max(2, meta.occupied) - 1));
|
|
313
|
+
if (newCapacity >= meta.capacityExponent) return;
|
|
314
|
+
|
|
315
|
+
const oldBlockSize = meta.byteCapacity;
|
|
316
|
+
const newBlockSize = (2 ** newCapacity) * this.wordSize;
|
|
317
|
+
const oldEnd = meta.dataAddress + oldBlockSize;
|
|
318
|
+
|
|
319
|
+
this.controlAdapter.setUint8(meta.headerAddress + CAPACITY_OFFSET, newCapacity);
|
|
320
|
+
|
|
321
|
+
if (oldEnd === this.dataPointer) {
|
|
322
|
+
this.dataPointer = meta.dataAddress + newBlockSize;
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
let address = meta.dataAddress + newBlockSize;
|
|
327
|
+
for (let exponent = newCapacity; exponent < meta.capacityExponent; exponent++) {
|
|
328
|
+
const segmentSize = (2 ** exponent) * this.wordSize;
|
|
329
|
+
this.recyclePush(segmentSize, address);
|
|
330
|
+
address += segmentSize;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
307
334
|
free(handler) {
|
|
308
|
-
|
|
335
|
+
|
|
309
336
|
const generation = (handler / ROTATE_32BITS) & CLAMP_11BITS;
|
|
310
337
|
const headerAddress = handler >>> 0;
|
|
311
338
|
const dataAddress = this.controlAdapter.getUint32(headerAddress + ADDRESS_OFFSET, IS_LITTLE_ENDIAN);
|
|
@@ -499,7 +526,6 @@ export default class Balloc {
|
|
|
499
526
|
* 该元素被写入最后一个占用元素之后的第一个空闲位置。
|
|
500
527
|
* 只有在容量范围内有可用空间时,块的占用数才会递增。
|
|
501
528
|
*
|
|
502
|
-
* @param {number} handler - 块句柄。
|
|
503
529
|
* @param {number} value - 要插入的值。
|
|
504
530
|
* @returns {boolean} 如果值已成功插入则为 `true`;如果块已无可用空间则为 `false`。
|
|
505
531
|
* @throws {Error} 如果句柄无效、已损坏,或者块正通过 withView() 被借用。
|
|
@@ -884,27 +910,45 @@ export default class Balloc {
|
|
|
884
910
|
* 此限制同样适用于从原始视图派生的子视图(subviews)。
|
|
885
911
|
*
|
|
886
912
|
* @param {number} handler - 块句柄。
|
|
887
|
-
* @param {Function}
|
|
913
|
+
* @param {...(number|Function)} args - 一个或多个块句柄,最后一个参数为回调函数。
|
|
888
914
|
* @returns {*} 回调函数产生 返回值。
|
|
889
|
-
* @throws {TypeError}
|
|
890
|
-
* @throws {Error}
|
|
915
|
+
* @throws {TypeError} 如果未提供句柄或回调不是函数。
|
|
916
|
+
* @throws {Error} 如果任一句柄无效、重复或已被借用。
|
|
891
917
|
*/
|
|
892
|
-
withView(
|
|
918
|
+
withView(...args) {
|
|
919
|
+
if (args.length < 2) throw new TypeError("At least one handler and one callback are required");
|
|
920
|
+
|
|
921
|
+
const callback = args.pop();
|
|
893
922
|
if (typeof callback !== "function") throw new TypeError("callback must be a function");
|
|
894
923
|
|
|
895
|
-
const
|
|
896
|
-
const
|
|
897
|
-
const
|
|
924
|
+
const handlers = args;
|
|
925
|
+
const metadata = handlers.map(handler => this.extractMetadata(handler, {}));
|
|
926
|
+
const headers = metadata.map(meta => meta.headerAddress);
|
|
898
927
|
|
|
899
|
-
if (
|
|
928
|
+
if (new Set(headers).size !== headers.length) throw new Error("Duplicate handler");
|
|
900
929
|
|
|
901
|
-
this.controlBus[
|
|
930
|
+
const flags = headers.map(header => this.controlBus[header + FLAGS_OFFSET]);
|
|
931
|
+
|
|
932
|
+
if (flags.some(flag => flag & VIEW_LOCK)) throw new Error("Block is already borrowed");
|
|
933
|
+
|
|
934
|
+
let acquiredCount = 0;
|
|
902
935
|
|
|
903
936
|
try {
|
|
904
|
-
const
|
|
905
|
-
|
|
937
|
+
for (const header of headers) {
|
|
938
|
+
this.controlBus[header + FLAGS_OFFSET] |= VIEW_LOCK;
|
|
939
|
+
acquiredCount++;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
const views = metadata.map(meta => {
|
|
943
|
+
const rawAddress = meta.dataAddress >>> this.wordShift;
|
|
944
|
+
return this.auxiliary.subarray(rawAddress, rawAddress + meta.occupied);
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
return callback(...views);
|
|
906
948
|
} finally {
|
|
907
|
-
|
|
949
|
+
for (let i = 0; i < acquiredCount; i++) {
|
|
950
|
+
this.controlBus[headers[i] + FLAGS_OFFSET] &= ~VIEW_LOCK;
|
|
951
|
+
}
|
|
908
952
|
}
|
|
909
953
|
}
|
|
910
954
|
|
|
@@ -967,24 +1011,24 @@ export default class Balloc {
|
|
|
967
1011
|
|
|
968
1012
|
// ========== 块间操作 (Operations between blocks)=============
|
|
969
1013
|
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1014
|
+
/**
|
|
1015
|
+
* 将占用元素从一个块复制到另一个块。
|
|
1016
|
+
*
|
|
1017
|
+
* 复制从 `source` 的第一个元素和 `destination` 的第一个槽位开始。
|
|
1018
|
+
* 实际复制的数量受源中占用元素数量、目标物理容量以及 `slots` 中指定限制的约束。
|
|
1019
|
+
*
|
|
1020
|
+
* 必要时会提高目标的占用数,以涵盖复制的元素。目标的容量保持不变。
|
|
1021
|
+
*
|
|
1022
|
+
* 该操作在 `dataBus` 上使用 `Uint8Array.prototype.copyWithin()`,
|
|
1023
|
+
* 因此返回值为代表数据总线的 `Uint8Array` 本身。
|
|
1024
|
+
*
|
|
1025
|
+
* @param {number} source - 源块句柄。
|
|
1026
|
+
* @param {number} destination - 目标块句柄。
|
|
1027
|
+
* @param {number} [slots=UNKNOWN] - 要复制的最大元素数。
|
|
1028
|
+
* `UNKNOWN` 代表哨兵值,用于不施加额外的限制。
|
|
1029
|
+
* @returns {Uint8Array} 操作后的 `dataBus`。
|
|
1030
|
+
* @throws {Error} 如果句柄无效、已损坏,或者目标块正通过 withView() 被借用。
|
|
1031
|
+
*/
|
|
988
1032
|
copy(source, destination, slots = UNKNOWN) {
|
|
989
1033
|
/** @type {Metadata} */
|
|
990
1034
|
const metaA = {};
|
package/types/ar/balloc.d.mts
CHANGED
|
@@ -126,19 +126,19 @@ export default class Balloc {
|
|
|
126
126
|
*/
|
|
127
127
|
realloc(handler: number): void;
|
|
128
128
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
free(handler:
|
|
129
|
+
* يقلّص الكتلة إلى أصغر سعة تمثل قوة للعدد اثنين وتكفي لاحتواء
|
|
130
|
+
* العناصر المشغولة فيها، مع الحفاظ على عنوانها ومعرّفها (handler).
|
|
131
|
+
*
|
|
132
|
+
* إذا كانت الكتلة في أعلى dataBus، يُرجع dataPointer إلى الخلف.
|
|
133
|
+
* وإلا، يُقسّم الجزء الطرفي المُحرر إلى مناطق ذات أحجام تمثل قوى للعدد
|
|
134
|
+
* اثنين، ثم تُعاد كل منطقة إلى قائمة إعادة التدوير.
|
|
135
|
+
*
|
|
136
|
+
* @param {number} handler - معرّف الكتلة المراد تقليصها.
|
|
137
|
+
* @returns {void}
|
|
138
|
+
* @throws {Error} إذا كان المعرّف غير صالح أو تالفاً أو مستعاراً عبر withView().
|
|
139
|
+
*/
|
|
140
|
+
shrink(handler: number): void;
|
|
141
|
+
free(handler: any): void;
|
|
142
142
|
/**
|
|
143
143
|
* [استخدام داخلي]
|
|
144
144
|
* يدخل منطقة حرة في قائمة إعادة التدوير.
|
|
@@ -228,14 +228,13 @@ export default class Balloc {
|
|
|
228
228
|
* مشغول. يتم زيادة إشغال الكتلة فقط عندما تكون هناك مساحة
|
|
229
229
|
* متاحة ضمن سعتها.
|
|
230
230
|
*
|
|
231
|
-
* @param {number} handler - مقبض الكتلة.
|
|
232
231
|
* @param {number} value - القيمة المراد إدراجها.
|
|
233
232
|
* @returns {boolean} `true` إذا تم إدراج القيمة؛ `false` إذا كانت الكتلة
|
|
234
233
|
* بلا مساحة متاحة.
|
|
235
234
|
* @throws {Error} إذا كان المقبض غير صالح، أو تالفاً، أو كانت الكتلة معارة بواسطة withView().
|
|
236
235
|
*
|
|
237
236
|
*/
|
|
238
|
-
push(handler:
|
|
237
|
+
push(handler: any, value: number): boolean;
|
|
239
238
|
/**
|
|
240
239
|
* يزيل آخر عنصر مشغول من الكتلة ويرجعه.
|
|
241
240
|
*
|
|
@@ -469,12 +468,12 @@ export default class Balloc {
|
|
|
469
468
|
* على العروض الفرعية (Subviews) المشتقة من العرض الأصلي.
|
|
470
469
|
*
|
|
471
470
|
* @param {number} handler - مقبض الكتلة.
|
|
472
|
-
* @param {Function}
|
|
471
|
+
* @param {...(number|Function)} args - مقبض كتلة واحد أو أكثر، تليها دالة رد الاتصال.
|
|
473
472
|
* @returns {*} القيمة المُرجعة بواسطة دالة رد الاتصال.
|
|
474
|
-
* @throws {TypeError} إذا لم تكن دالة رد الاتصال دالة.
|
|
475
|
-
* @throws {Error} إذا كان
|
|
473
|
+
* @throws {TypeError} إذا لم يتم توفير أي مقبض أو لم تكن دالة رد الاتصال دالة.
|
|
474
|
+
* @throws {Error} إذا كان أي مقبض غير صالح أو مكرراً أو معاراً مسبقاً.
|
|
476
475
|
*/
|
|
477
|
-
withView(
|
|
476
|
+
withView(...args: (number | Function)[]): any;
|
|
478
477
|
/**
|
|
479
478
|
* يرجع السعة الفيزيائية للكتلة بالبايت.
|
|
480
479
|
*
|
package/types/en/balloc.d.mts
CHANGED
|
@@ -128,6 +128,19 @@ export default class Balloc {
|
|
|
128
128
|
* supported limit.
|
|
129
129
|
*/
|
|
130
130
|
realloc(handler: number): void;
|
|
131
|
+
/**
|
|
132
|
+
* Reduces a block to the smallest power-of-two capacity that can contain
|
|
133
|
+
* its occupied elements, while preserving its address and handler.
|
|
134
|
+
*
|
|
135
|
+
* If the block is at the top of the dataBus, dataPointer is moved backward.
|
|
136
|
+
* Otherwise, the released tail is split into power-of-two regions and each
|
|
137
|
+
* region is returned to the recycling list.
|
|
138
|
+
*
|
|
139
|
+
* @param {number} handler - Handler of the block to shrink.
|
|
140
|
+
* @returns {void}
|
|
141
|
+
* @throws {Error} If the handler is invalid, corrupted, or borrowed by withView().
|
|
142
|
+
*/
|
|
143
|
+
shrink(handler: number): void;
|
|
131
144
|
/**
|
|
132
145
|
* Frees a memory block.
|
|
133
146
|
*
|
|
@@ -239,14 +252,13 @@ export default class Balloc {
|
|
|
239
252
|
* element. Block occupancy is incremented only when space is available
|
|
240
253
|
* within its capacity.
|
|
241
254
|
*
|
|
242
|
-
* @param {number} handler - Block handle.
|
|
243
255
|
* @param {number} value - Value to be inserted.
|
|
244
256
|
* @returns {boolean} `true` if the value was inserted; `false` if the block
|
|
245
257
|
* is already out of available space.
|
|
246
258
|
* @throws {Error} If the handle is invalid, corrupted, or the block is borrowed via withView().
|
|
247
259
|
*
|
|
248
260
|
*/
|
|
249
|
-
push(handler:
|
|
261
|
+
push(handler: any, value: number): boolean;
|
|
250
262
|
/**
|
|
251
263
|
* Removes the last occupied element from the block and returns it.
|
|
252
264
|
*
|
|
@@ -479,12 +491,12 @@ export default class Balloc {
|
|
|
479
491
|
* also applies to subviews derived from the original view.
|
|
480
492
|
*
|
|
481
493
|
* @param {number} handler - Block handle.
|
|
482
|
-
* @param {Function}
|
|
494
|
+
* @param {...(number|Function)} args - One or more block handles followed by the callback.
|
|
483
495
|
* @returns {*} Return value produced by the callback.
|
|
484
|
-
* @throws {TypeError} If callback is not a function.
|
|
485
|
-
* @throws {Error} If
|
|
496
|
+
* @throws {TypeError} If no handle is provided or the callback is not a function.
|
|
497
|
+
* @throws {Error} If a handle is invalid, duplicated, or already borrowed.
|
|
486
498
|
*/
|
|
487
|
-
withView(
|
|
499
|
+
withView(...args: (number | Function)[]): any;
|
|
488
500
|
/**
|
|
489
501
|
* Returns the physical capacity of the block in bytes.
|
|
490
502
|
*
|
package/types/es/balloc.d.mts
CHANGED
|
@@ -128,21 +128,20 @@ export default class Balloc {
|
|
|
128
128
|
*/
|
|
129
129
|
realloc(handler: number): void;
|
|
130
130
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
free(handler: number): void;
|
|
131
|
+
* Reduce un bloque a la menor capacidad potencia de dos que pueda contener
|
|
132
|
+
* sus elementos ocupados, preservando su dirección y su handler.
|
|
133
|
+
*
|
|
134
|
+
* Si el bloque está en la parte superior de dataBus, dataPointer retrocede.
|
|
135
|
+
* De lo contrario, la cola liberada se divide en regiones de potencias
|
|
136
|
+
* de dos y cada región se devuelve a la lista de reciclaje.
|
|
137
|
+
*
|
|
138
|
+
* @param {number} handler - Handler del bloque que se va a reducir.
|
|
139
|
+
* @returns {void}
|
|
140
|
+
* @throws {Error} Si el handler no es válido, está dañado o está prestado
|
|
141
|
+
* mediante withView().
|
|
142
|
+
*/
|
|
143
|
+
shrink(handler: number): void;
|
|
144
|
+
free(handler: any): void;
|
|
146
145
|
/**
|
|
147
146
|
* [USO INTERNO]
|
|
148
147
|
* Inserta una región libre en la lista de reciclaje.
|
|
@@ -239,14 +238,13 @@ export default class Balloc {
|
|
|
239
238
|
* ocupado. La ocupación del bloque se incrementa únicamente cuando hay espacio
|
|
240
239
|
* disponible dentro de su capacidad.
|
|
241
240
|
*
|
|
242
|
-
* @param {number} handler - Descriptor del bloque.
|
|
243
241
|
* @param {number} value - Valor que se va a insertar.
|
|
244
242
|
* @returns {boolean} `true` si el valor fue insertado; `false` si el bloque
|
|
245
243
|
* ya no dispone de espacio libre.
|
|
246
244
|
* @throws {Error} Si el descriptor no es válido, está corrupto o el bloque está prestado mediante `withView()`.
|
|
247
245
|
*
|
|
248
246
|
*/
|
|
249
|
-
push(handler:
|
|
247
|
+
push(handler: any, value: number): boolean;
|
|
250
248
|
/**
|
|
251
249
|
* Elimina el último elemento ocupado del bloque y lo devuelve.
|
|
252
250
|
*
|
|
@@ -481,12 +479,12 @@ export default class Balloc {
|
|
|
481
479
|
* también se aplica a las subvistas derivadas de la vista original.
|
|
482
480
|
*
|
|
483
481
|
* @param {number} handler - Descriptor del bloque.
|
|
484
|
-
* @param {Function}
|
|
482
|
+
* @param {...(number|Function)} args - Uno o más descriptores de bloque, seguidos de la retrollamada.
|
|
485
483
|
* @returns {*} Valor devuelto por la retrollamada.
|
|
486
|
-
* @throws {TypeError} Si la retrollamada no es una función.
|
|
487
|
-
* @throws {Error} Si
|
|
484
|
+
* @throws {TypeError} Si no se proporciona ningún descriptor o la retrollamada no es una función.
|
|
485
|
+
* @throws {Error} Si algún descriptor no es válido, está duplicado o ya está prestado.
|
|
488
486
|
*/
|
|
489
|
-
withView(
|
|
487
|
+
withView(...args: (number | Function)[]): any;
|
|
490
488
|
/**
|
|
491
489
|
* Devuelve la capacidad física del bloque en bytes.
|
|
492
490
|
*
|
package/types/jp/balloc.d.mts
CHANGED
|
@@ -123,20 +123,20 @@ export default class Balloc {
|
|
|
123
123
|
*/
|
|
124
124
|
realloc(handler: number): void;
|
|
125
125
|
/**
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
free(handler:
|
|
126
|
+
* ブロックのアドレスとハンドルを維持したまま、使用中の要素を格納できる
|
|
127
|
+
* 最小の2のべき乗の容量まで縮小します。
|
|
128
|
+
*
|
|
129
|
+
* ブロックが dataBus のトップにある場合、dataPointer を後退させます。
|
|
130
|
+
* それ以外の場合、解放された末尾領域を2のべき乗の領域に分割し、
|
|
131
|
+
* 各領域を再利用リストに戻します。
|
|
132
|
+
*
|
|
133
|
+
* @param {number} handler - 縮小するブロックのハンドル。
|
|
134
|
+
* @returns {void}
|
|
135
|
+
* @throws {Error} ハンドルが無効または破損している場合、あるいは
|
|
136
|
+
* withView() によってブロックが借用されている場合。
|
|
137
|
+
*/
|
|
138
|
+
shrink(handler: number): void;
|
|
139
|
+
free(handler: any): void;
|
|
140
140
|
/**
|
|
141
141
|
* [内部利用]
|
|
142
142
|
* 空き領域を再利用リストに挿入します。
|
|
@@ -223,14 +223,13 @@ export default class Balloc {
|
|
|
223
223
|
* 要素は、最後尾の占有要素の直後の最初の空き位置に書き込まれます。
|
|
224
224
|
* ブロックの占有数は、その容量内に空きスペースが存在する場合にのみインクリメントされます。
|
|
225
225
|
*
|
|
226
|
-
* @param {number} handler - ブロックのハンドル。
|
|
227
226
|
* @param {number} value - 挿入する値。
|
|
228
227
|
* @returns {boolean} 値が挿入された場合は `true`、ブロックに利用可能な
|
|
229
228
|
* スペースがない場合は `false`。
|
|
230
229
|
* @throws {Error} ハンドルが無効、破損している場合、またはブロックが withView() によって借用されている場合。
|
|
231
230
|
*
|
|
232
231
|
*/
|
|
233
|
-
push(handler:
|
|
232
|
+
push(handler: any, value: number): boolean;
|
|
234
233
|
/**
|
|
235
234
|
* ブロックから最後尾の占有要素を削除し、それを返します。
|
|
236
235
|
*
|
|
@@ -442,12 +441,12 @@ export default class Balloc {
|
|
|
442
441
|
* サブビューにも適用されます。
|
|
443
442
|
*
|
|
444
443
|
* @param {number} handler - ブロックのハンドル。
|
|
445
|
-
* @param {Function}
|
|
444
|
+
* @param {...(number|Function)} args - 1つ以上のブロックハンドルと、その後に続くコールバック。
|
|
446
445
|
* @returns {*} コールバックによって生成された戻り値。
|
|
447
|
-
* @throws {TypeError}
|
|
448
|
-
* @throws {Error}
|
|
446
|
+
* @throws {TypeError} ハンドルが指定されていない場合、またはコールバックが関数ではない場合。
|
|
447
|
+
* @throws {Error} いずれかのハンドルが無効、重複、または借用中の場合。
|
|
449
448
|
*/
|
|
450
|
-
withView(
|
|
449
|
+
withView(...args: (number | Function)[]): any;
|
|
451
450
|
/**
|
|
452
451
|
* ブロックの物理的容量をバイト単位で返します。
|
|
453
452
|
*
|
package/types/pt/balloc.d.mts
CHANGED
|
@@ -129,21 +129,20 @@ export default class Balloc {
|
|
|
129
129
|
*/
|
|
130
130
|
realloc(handler: number): void;
|
|
131
131
|
/**
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
free(handler: number): void;
|
|
132
|
+
* Reduz um bloco à menor capacidade em potência de dois capaz de comportar
|
|
133
|
+
* seus elementos ocupados, preservando seu endereço e handler.
|
|
134
|
+
*
|
|
135
|
+
* Se o bloco estiver no topo do dataBus, dataPointer será recuado.
|
|
136
|
+
* Caso contrário, a cauda liberada será dividida em regiões de potências
|
|
137
|
+
* de dois, e cada região será devolvida à lista de reciclagem.
|
|
138
|
+
*
|
|
139
|
+
* @param {number} handler - Handler do bloco a ser reduzido.
|
|
140
|
+
* @returns {void}
|
|
141
|
+
* @throws {Error} Se o handler for inválido, estiver corrompido ou estiver
|
|
142
|
+
* emprestado por withView().
|
|
143
|
+
*/
|
|
144
|
+
shrink(handler: number): void;
|
|
145
|
+
free(handler: any): void;
|
|
147
146
|
/**
|
|
148
147
|
* [USO INTERNO]
|
|
149
148
|
* Insere uma região livre na lista de reciclagem.
|
|
@@ -482,13 +481,12 @@ export default class Balloc {
|
|
|
482
481
|
* retornada ou utilizada após o término do callback. Essa restrição
|
|
483
482
|
* também se aplica a subviews derivadas da view original.
|
|
484
483
|
*
|
|
485
|
-
* @param {number}
|
|
486
|
-
* @param {Function} callback - Função que recebe a TypedArray compartilhada.
|
|
484
|
+
* @param {...number|Function} args - Um ou mais handlers, seguidos pelo callback.
|
|
487
485
|
* @returns {*} Retorno produzido pelo callback.
|
|
488
|
-
* @throws {TypeError} Se callback não for uma função.
|
|
489
|
-
* @throws {Error} Se
|
|
486
|
+
* @throws {TypeError} Se não houver handler ou se o callback não for uma função.
|
|
487
|
+
* @throws {Error} Se algum handler for inválido, duplicado ou já estiver emprestado.
|
|
490
488
|
*/
|
|
491
|
-
withView(
|
|
489
|
+
withView(...args: (number | Function)[]): any;
|
|
492
490
|
/**
|
|
493
491
|
* Retorna a capacidade física do bloco em bytes.
|
|
494
492
|
*
|
package/types/zh/balloc.d.mts
CHANGED
|
@@ -117,17 +117,19 @@ export default class Balloc {
|
|
|
117
117
|
*/
|
|
118
118
|
realloc(handler: number): void;
|
|
119
119
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
120
|
+
* 将内存块缩小到能够容纳其已占用元素的最小 2 的幂次容量,
|
|
121
|
+
* 同时保留其地址和句柄。
|
|
122
|
+
*
|
|
123
|
+
* 如果该块位于 dataBus 的顶部,则向后回退 dataPointer。
|
|
124
|
+
* 否则,将释放的尾部区域拆分为若干个容量为 2 的幂次的区域,
|
|
125
|
+
* 并将每个区域归还到回收列表。
|
|
126
|
+
*
|
|
127
|
+
* @param {number} handler - 要缩小的内存块的句柄。
|
|
128
|
+
* @returns {void}
|
|
129
|
+
* @throws {Error} 如果句柄无效、已损坏,或该块正通过 withView() 被借用。
|
|
130
|
+
*/
|
|
131
|
+
shrink(handler: number): void;
|
|
132
|
+
free(handler: any): void;
|
|
131
133
|
/**
|
|
132
134
|
* [内部使用]
|
|
133
135
|
* 将空闲区域插入回收列表。
|
|
@@ -209,13 +211,12 @@ export default class Balloc {
|
|
|
209
211
|
* 该元素被写入最后一个占用元素之后的第一个空闲位置。
|
|
210
212
|
* 只有在容量范围内有可用空间时,块的占用数才会递增。
|
|
211
213
|
*
|
|
212
|
-
* @param {number} handler - 块句柄。
|
|
213
214
|
* @param {number} value - 要插入的值。
|
|
214
215
|
* @returns {boolean} 如果值已成功插入则为 `true`;如果块已无可用空间则为 `false`。
|
|
215
216
|
* @throws {Error} 如果句柄无效、已损坏,或者块正通过 withView() 被借用。
|
|
216
217
|
*
|
|
217
218
|
*/
|
|
218
|
-
push(handler:
|
|
219
|
+
push(handler: any, value: number): boolean;
|
|
219
220
|
/**
|
|
220
221
|
* 移除块中最后一个占用的元素并将其返回。
|
|
221
222
|
*
|
|
@@ -414,12 +415,12 @@ export default class Balloc {
|
|
|
414
415
|
* 此限制同样适用于从原始视图派生的子视图(subviews)。
|
|
415
416
|
*
|
|
416
417
|
* @param {number} handler - 块句柄。
|
|
417
|
-
* @param {Function}
|
|
418
|
+
* @param {...(number|Function)} args - 一个或多个块句柄,最后一个参数为回调函数。
|
|
418
419
|
* @returns {*} 回调函数产生 返回值。
|
|
419
|
-
* @throws {TypeError}
|
|
420
|
-
* @throws {Error}
|
|
420
|
+
* @throws {TypeError} 如果未提供句柄或回调不是函数。
|
|
421
|
+
* @throws {Error} 如果任一句柄无效、重复或已被借用。
|
|
421
422
|
*/
|
|
422
|
-
withView(
|
|
423
|
+
withView(...args: (number | Function)[]): any;
|
|
423
424
|
/**
|
|
424
425
|
* 返回块的物理容量(以字节为单位)。
|
|
425
426
|
*
|
package/change.log.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# version 1.2
|
|
2
|
-
- Fix duplicate memory allocation in constructor - https://github.com/AugustoVasques75/balloc/issues/4
|
|
3
|
-
- Add `indexOf()` method - https://github.com/AugustoVasques75/balloc/issues/1
|
|
4
|
-
- Add `lastIndexOf()` method
|
|
5
|
-
- Add method isFull() - https://github.com/AugustoVasques75/balloc/issues/2
|
|
6
|
-
- Typo correction
|
|
7
|
-
- Add `withView()` method to address the Direct Mutable Access to Allocation Storage issue: https://github.com/AugustoVasques75/balloc/issues/3
|