2020-02-06 11:11:16 +00:00
|
|
|
import * as plugins from './lik.plugins';
|
|
|
|
|
2020-02-06 15:31:58 +00:00
|
|
|
/**
|
|
|
|
* fast map allows for very quick lookups of objects with a unique key
|
|
|
|
*/
|
2020-02-06 11:11:16 +00:00
|
|
|
export class FastMap<T> {
|
|
|
|
private mapObject: { [key: string]: T } = {};
|
|
|
|
|
2020-02-06 15:31:58 +00:00
|
|
|
public isUniqueKey(keyArg: string): boolean {
|
|
|
|
return this.mapObject[keyArg] ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addToMap(keyArg: string, objectArg: T): boolean {
|
|
|
|
if (this.isUniqueKey(keyArg)) {
|
|
|
|
this.mapObject[keyArg] = objectArg;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getByKey(keyArg: string) {
|
|
|
|
return this.mapObject[keyArg];
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeFromMap(keyArg): T {
|
|
|
|
const removedItem = this.getByKey(keyArg);
|
|
|
|
delete this.mapObject[keyArg];
|
|
|
|
return removedItem;
|
|
|
|
}
|
2020-02-06 11:11:16 +00:00
|
|
|
|
2020-02-06 15:31:58 +00:00
|
|
|
public getKeys() {
|
|
|
|
const keys: string[] = [];
|
|
|
|
for (const keyArg in this.mapObject) {
|
|
|
|
if (this.mapObject[keyArg]) {
|
|
|
|
keys.push(keyArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return keys;
|
2020-02-06 11:11:16 +00:00
|
|
|
}
|
2020-02-16 23:15:50 +00:00
|
|
|
|
|
|
|
public clean() {
|
|
|
|
this.mapObject = {};
|
|
|
|
}
|
2020-02-06 11:11:16 +00:00
|
|
|
}
|