/** * @ignore */ export interface RefCount { value: T; count: number; } /** * @ignore */ export interface IRefCountList { clear(): void; readonly count: number; get(index: number): T; push(value: T): void; done(): void; } /** * @ignore */ /** @ignore */ export class MaxRefCountList implements IRefCountList { private _list: T[] = []; clear() { this._list = []; } get count() { return this._list.length; } get(index: number): T { return this._list[index]; } push(value: T) { this._list.push(value); } // eslint-disable-next-line @typescript-eslint/no-empty-function done() {} } /** * @ignore */ /** @ignore */ export class RefCountList implements IRefCountList { private _readerCount: number; private _list: Map>; private _count = 0; constructor(readerCount: number) { this._readerCount = readerCount; this._list = new Map>(); } clear() { this._list.clear(); } get count() { return this._count; } get readerCount() { return this._readerCount; } set readerCount(value: number) { this._readerCount = value; } done() { this._readerCount--; } get(index: number): T { if (!this._list.has(index)) { throw new Error('Element no longer available in the buffer.'); } const res = this._list.get(index)!; const val = res.value; if (--res.count === 0) { this._list.delete(index); } return val; } push(value: T) { this._list.set(this._count++, { value: value, count: this._readerCount }); } }