UNPKG

array-ring

Version:

Advanced Array and Ring structure for Large data: A High-Performance Solution, mostly created to implement array methods, bringing 2 data structures, An efficient resizable array with similar methods to javascript array which are optmized methods like shi

35 lines (34 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EArray = void 0; const _Array_1 = require("./_Array"); class EArray extends _Array_1._Array { resize() { const newSize = this.size * 2; const newBuffer = new Array(newSize).fill(undefined); for (let i = 0; i < this.count; i++) { newBuffer[i] = this.buffer[(this.start + i) % this.size]; } this.buffer = newBuffer; this.size = newSize; this.start = 0; this.end = this.count; } _push(item) { if (this.count === this.size) { this.resize(); } this.buffer[this.end] = item; this.end = (this.end + 1) % this.size; this.count++; } _unshift(item) { if (this.count === this.size) { this.resize(); } this.start = (this.start - 1 + this.size) % this.size; this.buffer[this.start] = item; this.count++; } } exports.EArray = EArray;