|
@@ -3,8 +3,7 @@
|
|
|
public data: Array<T>;
|
|
|
public length: number = 0;
|
|
|
|
|
|
- private _id: number;
|
|
|
- private _duplicateId = 0;
|
|
|
+ protected _id: number;
|
|
|
|
|
|
[index: number]: T;
|
|
|
|
|
@@ -19,12 +18,6 @@
|
|
|
if (this.length > this.data.length) {
|
|
|
this.data.length *= 2;
|
|
|
}
|
|
|
-
|
|
|
- if (!(<any>value).__smartArrayFlags) {
|
|
|
- (<any>value).__smartArrayFlags = {};
|
|
|
- }
|
|
|
-
|
|
|
- (<any>value).__smartArrayFlags[this._id] = this._duplicateId;
|
|
|
}
|
|
|
|
|
|
public forEach(func: (content: T) => void): void {
|
|
@@ -32,22 +25,13 @@
|
|
|
func(this.data[index]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public pushNoDuplicate(value: T): boolean {
|
|
|
- if ((<any>value).__smartArrayFlags && (<any>value).__smartArrayFlags[this._id] === this._duplicateId) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- this.push(value);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
public sort(compareFn: (a: T, b: T) => number): void {
|
|
|
this.data.sort(compareFn);
|
|
|
}
|
|
|
|
|
|
public reset(): void {
|
|
|
this.length = 0;
|
|
|
- this._duplicateId++;
|
|
|
}
|
|
|
|
|
|
public dispose(): void {
|
|
@@ -72,20 +56,6 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public concatWithNoDuplicate(array: any): void {
|
|
|
- if (array.length === 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.length + array.length > this.data.length) {
|
|
|
- this.data.length = (this.length + array.length) * 2;
|
|
|
- }
|
|
|
-
|
|
|
- for (var index = 0; index < array.length; index++) {
|
|
|
- var item = (array.data || array)[index];
|
|
|
- this.pushNoDuplicate(item);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public indexOf(value: T): number {
|
|
|
var position = this.data.indexOf(value);
|
|
|
|
|
@@ -103,4 +73,48 @@
|
|
|
// Statics
|
|
|
private static _GlobalId = 0;
|
|
|
}
|
|
|
+
|
|
|
+ export class SmartArrayNoDuplicate<T> extends SmartArray<T> {
|
|
|
+ private _duplicateId = 0;
|
|
|
+
|
|
|
+ [index: number]: T;
|
|
|
+
|
|
|
+ public push(value: T): void {
|
|
|
+ super.push(value);
|
|
|
+
|
|
|
+ if (!(<any>value).__smartArrayFlags) {
|
|
|
+ (<any>value).__smartArrayFlags = {};
|
|
|
+ }
|
|
|
+
|
|
|
+ (<any>value).__smartArrayFlags[this._id] = this._duplicateId;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public pushNoDuplicate(value: T): boolean {
|
|
|
+ if ((<any>value).__smartArrayFlags && (<any>value).__smartArrayFlags[this._id] === this._duplicateId) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ this.push(value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public reset(): void {
|
|
|
+ super.reset();
|
|
|
+ this._duplicateId++;
|
|
|
+ }
|
|
|
+
|
|
|
+ public concatWithNoDuplicate(array: any): void {
|
|
|
+ if (array.length === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.length + array.length > this.data.length) {
|
|
|
+ this.data.length = (this.length + array.length) * 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var index = 0; index < array.length; index++) {
|
|
|
+ var item = (array.data || array)[index];
|
|
|
+ this.pushNoDuplicate(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|