Comparing version 0.1.1 to 0.1.3
22
index.js
@@ -19,2 +19,5 @@ var LRU = exports.LRU = function (max) { | ||
if (this.head) { | ||
if (!(this.head in this.cache)) { | ||
return this.reset(); | ||
} | ||
this.cache[this.head].next = key; | ||
@@ -41,5 +44,11 @@ } | ||
if (element.next) { | ||
if (!(element.next in this.cache)) { | ||
return this.reset(); | ||
} | ||
this.cache[element.next].prev = element.prev; | ||
} | ||
if (element.prev) { | ||
if (!(element.prev in this.cache)) { | ||
return this.reset(); | ||
} | ||
this.cache[element.prev].next = element.next; | ||
@@ -52,2 +61,5 @@ } else { | ||
if (this.head) { | ||
if (!(this.head in this.cache)) { | ||
return this.reset(); | ||
} | ||
this.cache[this.head].next = key; | ||
@@ -62,2 +74,5 @@ } | ||
delete this.cache[this.tail]; | ||
if (!(tail in this.cache)) { | ||
return this.reset(); | ||
} | ||
this.cache[tail].prev = null; | ||
@@ -68,1 +83,8 @@ this.tail = tail; | ||
LRU.prototype.reset = function () { | ||
//Super shit but this sometimes (rarely) fails | ||
this.cache = {}; | ||
this.length = 0; | ||
this.head = this.tail = null; | ||
}; | ||
{ "name" : "lru", | ||
"description" : "A simple O(1) LRU cache", | ||
"version" : "0.1.1", | ||
"version" : "0.1.3", | ||
"author" : "Chris O'Hara <cohara87@gmail.com>", | ||
@@ -5,0 +5,0 @@ "main" : "index", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6249
150