lru
Advanced tools
Comparing version 0.1.5 to 0.2.0
30
index.js
@@ -14,16 +14,16 @@ var events = require('events'); | ||
LRU.prototype.remove = function (key) { | ||
var element = this.cache[key]; | ||
if(element) { | ||
delete this.cache[key]; | ||
--this.length; | ||
if(element.prev) this.cache[element.prev].next = element.next; | ||
if(element.next) this.cache[element.next].prev = element.prev; | ||
if(this.head == key) { | ||
this.head = element.prev; | ||
var element = this.cache[key]; | ||
if(element) { | ||
delete this.cache[key]; | ||
--this.length; | ||
if(element.prev) this.cache[element.prev].next = element.next; | ||
if(element.next) this.cache[element.next].prev = element.prev; | ||
if(this.head == key) { | ||
this.head = element.prev; | ||
} | ||
if(this.tail == key) { | ||
this.tail = element.next; | ||
} | ||
} | ||
if(this.tail == key) { | ||
this.tail = element.next; | ||
} | ||
} | ||
return element; | ||
return element; | ||
} | ||
@@ -34,3 +34,3 @@ | ||
element = element || { value:value }; | ||
element.value = value | ||
@@ -54,2 +54,4 @@ element.next = null; | ||
} | ||
return value | ||
}; | ||
@@ -56,0 +58,0 @@ |
@@ -1,6 +0,7 @@ | ||
{ "name" : "lru", | ||
"description" : "A simple O(1) LRU cache", | ||
"version" : "0.1.5", | ||
"author" : "Chris O'Hara <cohara87@gmail.com>", | ||
"main" : "index", | ||
{ | ||
"name": "lru", | ||
"description": "A simple O(1) LRU cache", | ||
"version": "0.2.0", | ||
"author": "Chris O'Hara <cohara87@gmail.com>", | ||
"main": "index", | ||
"bugs": { | ||
@@ -16,9 +17,17 @@ "mail": "cohara87@gmail.com" | ||
}, | ||
"engines": { "node": ">= 0.4.0" }, | ||
"licenses": [{ | ||
"type": "MIT" | ||
}], | ||
"engines": { | ||
"node": ">= 0.4.0" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT" | ||
} | ||
], | ||
"devDependencies": { | ||
"vows": "~0.6" | ||
} | ||
"vows": "^0.8.1" | ||
}, | ||
"scripts": { | ||
"test": "vows test/*.js --spec" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -62,2 +62,10 @@ var assert = require('assert'); | ||
suite.addBatch({ | ||
"get() returns item value": function() { | ||
var lru = new LRU.LRU(2) | ||
assert.equal( lru.set('foo','bar'), 'bar') | ||
} | ||
}); | ||
suite.addBatch({ | ||
"idempotent 'changes'": { | ||
@@ -64,0 +72,0 @@ "set() and remove() on empty LRU is idempotent": function() { |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
7149
175
0