- splice(start: number, deleteCount?: number, ...items: T[]): T[] {
- this.push(...items);
- return super.splice(start, deleteCount);
+ public resize(size: number): void {
+ this.checkSize(size);
+ if (size === 0) {
+ this.length = 0;
+ } else if (size < this.size) {
+ for (let i = size; i < this.size; i++) {
+ super.pop();
+ }
+ }
+ this.size = size;
+ }
+
+ public empty(): boolean {
+ return this.length === 0;
+ }
+
+ public full(): boolean {
+ return this.length === this.size;
+ }
+
+ private checkSize(size: number) {
+ if (!Number.isSafeInteger(size)) {
+ throw new TypeError(`Invalid circular array size: ${size} is not a safe integer`);
+ }
+ if (size < 0) {
+ throw new RangeError(`Invalid circular array size: ${size} < 0`);
+ }