Skip to content

Commit

Permalink
feat: Renaming append and move in CacheNode to appendToTail and moveT…
Browse files Browse the repository at this point in the history
…oTail
  • Loading branch information
aholstenson committed Apr 8, 2019
1 parent fb50343 commit be6b221
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/cache/bounded/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class BoundedCache<K extends KeyType, V> extends AbstractCache<K, V> impl
}

// Append the new node to the window space
node.append(data.window.head);
node.appendToTail(data.window.head);
data.window.size += node.weight;

// Register access to the key
Expand Down Expand Up @@ -253,31 +253,31 @@ export class BoundedCache<K extends KeyType, V> extends AbstractCache<K, V> impl
switch(node.location) {
case Location.WINDOW:
// In window cache, mark as most recently used
node.move(data.window.head);
node.moveToTail(data.window.head);
break;
case Location.PROBATION:
// In SLRU probation segment, move to protected
node.location = Location.PROTECTED;
node.move(data.protected.head);
node.moveToTail(data.protected.head);

// Plenty of room, keep track of the size
data.protected.size += node.weight;

while(data.protected.size > data.protected.maxSize) {
/*
* There is now too many nodes in the protected segment
* so demote the least recently used.
*/
* There is now too many nodes in the protected segment
* so demote the least recently used.
*/
const lru = data.protected.head.next;
lru.location = Location.PROBATION;
lru.move(data.probation.head);
lru.moveToTail(data.probation.head);
data.protected.size -= lru.weight;
}

break;
case Location.PROTECTED:
// SLRU protected segment, mark as most recently used
node.move(data.protected.head);
node.moveToTail(data.protected.head);
break;
}

Expand Down Expand Up @@ -401,7 +401,7 @@ export class BoundedCache<K extends KeyType, V> extends AbstractCache<K, V> impl
while(data.window.size > data.window.maxSize) {
const first = data.window.head.next;

first.move(data.probation.head);
first.moveToTail(data.probation.head);
first.location = Location.PROBATION;

data.window.size -= first.weight;
Expand Down
6 changes: 3 additions & 3 deletions src/cache/cache-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export class CacheNode<K, V> {
this.next = this.previous = this;
}

public append(head: this) {
public appendToTail(head: this) {
const tail = head.previous;
head.previous = this;
tail.next = this;
this.next = head;
this.previous = tail;
}

public move(head: this) {
public moveToTail(head: this) {
this.remove();
this.append(head);
this.appendToTail(head);
}
}
4 changes: 2 additions & 2 deletions src/cache/expiration/timer-wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class TimerWheel<K extends KeyType, V> {
// Find a new bucket to put this node in
const b = this.findBucket(node);
if(b) {
node.append(b);
node.appendToTail(b);
}
}
node = next;
Expand Down Expand Up @@ -155,7 +155,7 @@ export class TimerWheel<K extends KeyType, V> {
const parent = this.findBucket(node);
if(! parent) return false;

node.append(parent);
node.appendToTail(parent);
return true;
}

Expand Down

0 comments on commit be6b221

Please sign in to comment.