modified TS linear container class

Signed-off-by: wangyong <wangyong237@huawei.com>
This commit is contained in:
wangyong
2022-01-16 11:36:49 +08:00
parent 5e2c79abb4
commit dd2b7787cd
7 changed files with 45 additions and 22 deletions
+4 -1
View File
@@ -265,12 +265,15 @@ if (flag || fastArrayList == undefined) {
private resize(): void {
this._capacity = 1.5 * this._capacity;
}
isEmpty(): boolean {
return this._length == 0;
}
increaseCapacityTo(newCapacity: number): void {
if (newCapacity >= this._length) {
this._capacity = newCapacity;
}
}
trimToCurrentSize(): void {
trimToCurrentLength(): void {
this._capacity = this._length;
}
[Symbol.iterator](): IterableIterator<T> {
+7 -7
View File
@@ -73,8 +73,8 @@ if (flag || fastDeque == undefined) {
}
return;
}
setPrototypeOf(obj: any, prop: any): T {
throw new Error("Can setPrototype on ArrayList Object");
setPrototypeOf(obj: any, prop: any): any {
throw new Error("Can setPrototype on Deque Object");
}
}
interface IterableIterator<T> {
@@ -171,13 +171,13 @@ if (flag || fastDeque == undefined) {
return (this._rear + 1) % this._capacity === this._front;
}
[Symbol.iterator](): IterableIterator<T> {
let _this = this;
let count = _this._front;
let deque = this;
let count = deque._front;
return {
next: function () {
var done = count == _this._rear;
var value = !done ? _this[count] : undefined;
count = (count + 1) % _this._capacity;
var done = count == deque._rear;
var value = !done ? deque[count] : undefined;
count = (count + 1) % deque._capacity;
return {
done: done,
value: value,
+8 -6
View File
@@ -36,12 +36,11 @@ if (flag || fastLinkedList == undefined) {
return obj[prop];
}
set(obj: LinkedList<T>, prop: any, value: any) {
if (
prop === "_length" ||
prop === "_capacity" ||
prop === "_head" ||
prop == "next" ||
prop == "_tail") {
if (prop === "_length" ||
prop === "_capacity" ||
prop === "_head" ||
prop == "next" ||
prop == "_tail" ) {
obj[prop] = value;
return true;
}
@@ -95,6 +94,9 @@ if (flag || fastLinkedList == undefined) {
}
return;
}
setPrototypeOf(obj: any, prop: any): any {
throw new Error("Can setPrototype on LinkedList Object");
}
}
interface IterableIterator<T> {
next: () => {
+7 -1
View File
@@ -88,6 +88,9 @@ if (flag || fastList == undefined) {
}
return;
}
setPrototypeOf(obj: any, prop: any): any {
throw new Error("Can setPrototype on List Object");
}
}
interface IterableIterator<T> {
next: () => {
@@ -180,7 +183,7 @@ if (flag || fastList == undefined) {
}
return false;
}
equals(obj: Object): boolean {
equal(obj: Object): boolean {
if (obj === this) {
return true;
}
@@ -327,6 +330,9 @@ if (flag || fastList == undefined) {
}
return arr;
}
isEmpty(): boolean {
return this._length == 0;
}
forEach(callbackfn: (value: T, index?: number, list?: List<T>) => void,
thisArg?: Object): void {
let index = 0;
+7 -4
View File
@@ -70,7 +70,9 @@ if (flag || fastQueue == undefined) {
}
return;
}
setPrototypeOf(obj: any, prop: any): any {
throw new Error("Can setPrototype on Queue Object");
}
}
interface IterableIterator<T> {
next: () => {
@@ -125,11 +127,12 @@ if (flag || fastQueue == undefined) {
}
[Symbol.iterator](): IterableIterator<T> {
let count = this._front;
let queue = this;
return {
next: function () {
var done = count == this._rear;
var value = !done ? this[count] : undefined;
count = (count + 1) % this._capacity;
var done = count == queue._rear;
var value = !done ? queue[count] : undefined;
count = (count + 1) % queue._capacity;
return {
done: done,
value: value,
+3
View File
@@ -74,6 +74,9 @@ if (flag || fastStack == undefined) {
}
return;
}
setPrototypeOf(obj: any, prop: any): any {
throw new Error("Can setPrototype on Stack Object");
}
}
interface IterableIterator<T> {
next: () => {
+9 -3
View File
@@ -84,6 +84,9 @@ if (flag || fastVector == undefined) {
}
return;
}
setPrototypeOf(obj: any, prop: any): any {
throw new Error("Can setPrototype on Vector Object");
}
}
interface IterableIterator<T> {
next: () => {
@@ -170,7 +173,7 @@ if (flag || fastVector == undefined) {
}
return -1;
}
getLastIndexOfFrom(element: T, index: number): number {
getLastIndexFrom(element: T, index: number): number {
if (this.has(element)) {
for (let i = index; i >= 0; i--) {
if (this[i] === element) {
@@ -180,7 +183,7 @@ if (flag || fastVector == undefined) {
}
return -1;
}
getIndexOfFrom(element: T, index: number): number {
getIndexFrom(element: T, index: number): number {
if (this.has(element)) {
for (let i = index; i < this._length; i++) {
if (this[i] === element) {
@@ -315,12 +318,15 @@ if (flag || fastVector == undefined) {
this._capacity = newCapacity;
}
}
trimToCurrentSize(): void {
trimToCurrentLength(): void {
this._capacity = this._length;
}
setSize(newSize: number): void {
this._length = newSize;
}
isEmpty(): boolean {
return this._length == 0;
}
[Symbol.iterator](): IterableIterator<T> {
let count = 0;
let vector = this