lru. comments.

This commit is contained in:
Christopher Jeffrey 2016-07-01 23:57:27 -07:00
parent 27a8a83969
commit 6062972da5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -53,7 +53,7 @@ LRU.prototype._createGetSize = function _createGetSize(size) {
/** /**
* Calculate size of an item. * Calculate size of an item.
* @private * @private
* @param {Object} item * @param {LRUItem} item
* @returns {Number} Size. * @returns {Number} Size.
*/ */
@ -139,6 +139,9 @@ LRU.prototype.reset = function reset() {
LRU.prototype.set = function set(key, value) { LRU.prototype.set = function set(key, value) {
var item; var item;
if (value === undefined)
throw new Error('Cannot set value to undefined.');
key = key + ''; key = key + '';
item = this.data[key]; item = this.data[key];
@ -193,7 +196,7 @@ LRU.prototype.get = function get(key) {
*/ */
LRU.prototype.has = function get(key) { LRU.prototype.has = function get(key) {
return this.data[key] != null; return this.data[key] !== undefined;
}; };
/** /**
@ -221,14 +224,33 @@ LRU.prototype.remove = function remove(key) {
return true; return true;
}; };
/**
* Prepend an item to the linked list (sets new head).
* @private
* @param {LRUItem}
*/
LRU.prototype._prependList = function prependList(item) { LRU.prototype._prependList = function prependList(item) {
this._insertList(null, item); this._insertList(null, item);
}; };
/**
* Append an item to the linked list (sets new tail).
* @private
* @param {LRUItem}
*/
LRU.prototype._appendList = function appendList(item) { LRU.prototype._appendList = function appendList(item) {
this._insertList(this.tail, item); this._insertList(this.tail, item);
}; };
/**
* Insert item into the linked list.
* @private
* @param {LRUItem|null} ref
* @param {LRUItem} item
*/
LRU.prototype._insertList = function insertList(ref, item) { LRU.prototype._insertList = function insertList(ref, item) {
assert(!item.next); assert(!item.next);
assert(!item.prev); assert(!item.prev);
@ -253,6 +275,12 @@ LRU.prototype._insertList = function insertList(ref, item) {
this.tail = item; this.tail = item;
}; };
/**
* Remove item from the linked list.
* @private
* @param {LRUItem}
*/
LRU.prototype._removeList = function removeList(item) { LRU.prototype._removeList = function removeList(item) {
if (item.prev) if (item.prev)
item.prev.next = item.next; item.prev.next = item.next;