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;
|
let id;
|
||||||
if (this.indexingMode) {
|
if (this.indexingMode) {
|
||||||
this.items[id = this.index] = item;
|
this.items[id = this.index] = item;
|
||||||
|
this.index++;
|
||||||
} else {
|
} else {
|
||||||
this.items[id = pRandom()] = item;
|
this.items[id = pRandom()] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regenerate) this.regenerateIterableArray();
|
if (regenerate) {
|
||||||
|
this.regenerateIterableArray();
|
||||||
this.itemKeys = Object.keys(this.items);
|
this.itemKeys = Object.keys(this.items);
|
||||||
|
}
|
||||||
this.index++;
|
|
||||||
|
|
||||||
return this.items[id];
|
return this.items[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id, regenerate = true) {
|
remove(id, regenerate = true) {
|
||||||
delete this.items[id];
|
delete this.items[id];
|
||||||
if (regenerate) this.regenerateIterableArray();
|
if (regenerate) {
|
||||||
|
this.regenerateIterableArray();
|
||||||
this.itemKeys = Object.keys(this.items);
|
this.itemKeys = Object.keys(this.items);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
removeFirstItem(regenerate = true) {
|
removeFirstItem(regenerate = true) {
|
||||||
delete this.items[this.itemKeys[0]];
|
delete this.items[this.itemKeys[0]];
|
||||||
|
@ -51,6 +54,7 @@ module.exports = class {
|
||||||
for (let itemKey of this.itemKeys) {
|
for (let itemKey of this.itemKeys) {
|
||||||
this.iterableArray.push(this.items[itemKey]);
|
this.iterableArray.push(this.items[itemKey]);
|
||||||
}
|
}
|
||||||
|
this.itemKeys = Object.keys(this.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFirstItem() {
|
getFirstItem() {
|
||||||
|
|
Loading…
Reference in a new issue