mirror of
https://github.com/openharmony/js_util_module.git
synced 2026-07-20 02:33:35 -04:00
modified TS linear container class
Signed-off-by: wangyong <wangyong237@huawei.com>
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: () => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: () => {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user