improve funkyArray's efficiency
This commit is contained in:
parent
67a995fb5a
commit
3ece5a575d
1 changed files with 10 additions and 6 deletions
|
@ -22,23 +22,26 @@ module.exports = class {
|
|||
let id;
|
||||
if (this.indexingMode) {
|
||||
this.items[id = this.index] = item;
|
||||
this.index++;
|
||||
} else {
|
||||
this.items[id = pRandom()] = item;
|
||||
}
|
||||
|
||||
if (regenerate) this.regenerateIterableArray();
|
||||
if (regenerate) {
|
||||
this.regenerateIterableArray();
|
||||
this.itemKeys = Object.keys(this.items);
|
||||
|
||||
this.index++;
|
||||
}
|
||||
|
||||
return this.items[id];
|
||||
}
|
||||
|
||||
remove(id, regenerate = true) {
|
||||
delete this.items[id];
|
||||
if (regenerate) this.regenerateIterableArray();
|
||||
if (regenerate) {
|
||||
this.regenerateIterableArray();
|
||||
this.itemKeys = Object.keys(this.items);
|
||||
}
|
||||
}
|
||||
|
||||
removeFirstItem(regenerate = true) {
|
||||
delete this.items[this.itemKeys[0]];
|
||||
|
@ -51,6 +54,7 @@ module.exports = class {
|
|||
for (let itemKey of this.itemKeys) {
|
||||
this.iterableArray.push(this.items[itemKey]);
|
||||
}
|
||||
this.itemKeys = Object.keys(this.items);
|
||||
}
|
||||
|
||||
getFirstItem() {
|
||||
|
|
Loading…
Reference in a new issue