2 export default class CircularArray
<T
> extends Array<T
> {
4 private readonly maximumCircularArraySize
= 2000;
6 constructor(size
?: number) {
8 this.size
= size
&& size
<= this.maximumCircularArraySize
? size
: this.maximumCircularArraySize
;
11 push(...items
: T
[]): number {
12 if (this.length
+ items
.length
> this.size
) {
13 super.splice(0, (this.length
+ items
.length
) - this.size
);
15 return super.push(...items
);
18 unshift(...items
: T
[]): number {
19 if (this.length
+ items
.length
> this.size
) {
20 super.splice(this.size
- items
.length
, (this.length
+ items
.length
) - this.size
);
22 return super.unshift(...items
);
25 concat(...items
: (T
| ConcatArray
<T
>)[]): T
[] {
26 if (this.length
+ items
.length
> this.size
) {
27 super.splice(0, (this.length
+ items
.length
) - this.size
);
29 return super.concat(items
as T
[]);
32 splice(start
: number, deleteCount
?: number, ...items
: T
[]): T
[] {
34 return super.splice(start
, deleteCount
);