feat(collections): add new collection APIs, iterator support, and tree serialization utilities

This commit is contained in:
2026-03-22 08:44:49 +00:00
parent 20182a00f8
commit f4db131ede
23 changed files with 2251 additions and 2657 deletions

View File

@@ -12,6 +12,10 @@ export class BackpressuredArray<T> {
this.highWaterMark = highWaterMark;
}
public get length(): number {
return this.data.length;
}
push(item: T): boolean {
this.data.push(item);
this.itemsAvailable.next('itemsAvailable');
@@ -23,6 +27,13 @@ export class BackpressuredArray<T> {
return spaceAvailable;
}
pushMany(items: T[]): boolean {
for (const item of items) {
this.push(item);
}
return this.checkSpaceAvailable();
}
shift(): T | undefined {
const item = this.data.shift();
if (this.checkSpaceAvailable()) {
@@ -31,6 +42,10 @@ export class BackpressuredArray<T> {
return item;
}
peek(): T | undefined {
return this.data[0];
}
checkSpaceAvailable(): boolean {
return this.data.length < this.highWaterMark;
}
@@ -75,6 +90,10 @@ export class BackpressuredArray<T> {
});
}
public [Symbol.iterator](): Iterator<T> {
return this.data[Symbol.iterator]();
}
/**
* destroys the BackpressuredArray, completing all subjects
*/