Skip to content

Commit

Permalink
Prep to fix the other side of the link list
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Dec 6, 2018
1 parent 8f18b83 commit c790d38
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
14 changes: 8 additions & 6 deletions lib/tiny-lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
const next = typeof process !== "undefined" ? process.nextTick : arg => setTimeout(arg, 1),
empty = null;

function link (item, key) {
item.next = key;
function link (item, key, dir) {
const other = dir === "next" ? "previous" : "next";

if (item.previous === key) {
item.previous = empty;
item[dir] = key;

if (item[other] === key) {
item[other] = empty;
}
}

Expand Down Expand Up @@ -143,7 +145,7 @@

if (this.first !== key) {
item.previous = this.first;
link(this.cache[this.first], key);
link(this.cache[this.first], key, "next");
}

if (this.last === key && item.previous !== empty) {
Expand All @@ -167,7 +169,7 @@
}

if (this.first !== empty && this.first !== key) {
link(this.cache[this.first], key);
link(this.cache[this.first], key, "next");
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tiny-lru.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c790d38

Please sign in to comment.