diff --git a/lib/bcoin/lru.js b/lib/bcoin/lru.js index 397f632c..160b995b 100644 --- a/lib/bcoin/lru.js +++ b/lib/bcoin/lru.js @@ -53,7 +53,7 @@ LRU.prototype._createGetSize = function _createGetSize(size) { /** * Calculate size of an item. * @private - * @param {Object} item + * @param {LRUItem} item * @returns {Number} Size. */ @@ -139,6 +139,9 @@ LRU.prototype.reset = function reset() { LRU.prototype.set = function set(key, value) { var item; + if (value === undefined) + throw new Error('Cannot set value to undefined.'); + key = key + ''; item = this.data[key]; @@ -193,7 +196,7 @@ LRU.prototype.get = 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; }; +/** + * Prepend an item to the linked list (sets new head). + * @private + * @param {LRUItem} + */ + LRU.prototype._prependList = function prependList(item) { this._insertList(null, item); }; +/** + * Append an item to the linked list (sets new tail). + * @private + * @param {LRUItem} + */ + LRU.prototype._appendList = function appendList(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) { assert(!item.next); assert(!item.prev); @@ -253,6 +275,12 @@ LRU.prototype._insertList = function insertList(ref, item) { this.tail = item; }; +/** + * Remove item from the linked list. + * @private + * @param {LRUItem} + */ + LRU.prototype._removeList = function removeList(item) { if (item.prev) item.prev.next = item.next;