lru.
This commit is contained in:
parent
f29aec13f4
commit
381e2c52b9
@ -14,10 +14,9 @@ var assert = utils.assert;
|
||||
* @constructor
|
||||
* @param {Number} maxSize
|
||||
* @param {Function?} getSize
|
||||
* @param {Function?} onRemove
|
||||
*/
|
||||
|
||||
function LRU(maxSize, getSize, onRemove) {
|
||||
function LRU(maxSize, getSize) {
|
||||
if (!(this instanceof LRU))
|
||||
return new LRU(maxSize, getSize);
|
||||
|
||||
@ -25,7 +24,6 @@ function LRU(maxSize, getSize, onRemove) {
|
||||
this.size = 0;
|
||||
this.maxSize = maxSize;
|
||||
this.getSize = this._createGetSize(getSize);
|
||||
this.onRemove = onRemove;
|
||||
|
||||
this.head = null;
|
||||
this.tail = null;
|
||||
@ -88,8 +86,6 @@ LRU.prototype._compact = function _compact() {
|
||||
break;
|
||||
this.size -= this._getSize(item);
|
||||
delete this.data[item.key];
|
||||
if (this.onRemove)
|
||||
this.onRemove(item.key, item.value);
|
||||
next = item.next;
|
||||
item.prev = null;
|
||||
item.next = null;
|
||||
@ -114,8 +110,6 @@ LRU.prototype.reset = function reset() {
|
||||
|
||||
for (item = this.head; item; item = next) {
|
||||
delete this.data[item.key];
|
||||
if (this.onRemove)
|
||||
this.onRemove(item.key, item.value);
|
||||
next = item.next;
|
||||
item.prev = null;
|
||||
item.next = null;
|
||||
@ -213,8 +207,6 @@ LRU.prototype.remove = function remove(key) {
|
||||
this.size -= this._getSize(item);
|
||||
|
||||
delete this.data[key];
|
||||
if (this.onRemove)
|
||||
this.onRemove(item.key, item.value);
|
||||
|
||||
this._removeList(item);
|
||||
|
||||
@ -313,19 +305,4 @@ LRU.prototype.toArray = function toArray() {
|
||||
return items;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an iterator with a `next` method.
|
||||
* @returns {Function}
|
||||
*/
|
||||
|
||||
LRU.prototype.iterator = function iterator() {
|
||||
return {
|
||||
item: { next: this.head },
|
||||
next: function() {
|
||||
this.item = this.item.next;
|
||||
return this.item;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = LRU;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user