@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
56 lines (47 loc) • 1.12 kB
JavaScript
/**
* Doubly linked list implementation for key-value pairs
* @template Key
* @template Value
* @class
*/
export class CacheElement {
/**
*
* @type {Key}
*/
key = null;
/**
*
* @type {Value}
*/
value = null;
/**
*
* @type {number}
*/
weight = 0;
/**
* Link to next element (implements linked list)
* @type {CacheElement<Key,Value>|null}
*/
next = null;
/**
* Link to previous element (implements linked list)
* @type {CacheElement<Key,Value>|null}
*/
previous = null;
unlink() {
const next = this.next;
const previous = this.previous;
// re-wire links around self
if (previous !== null) {
previous.next = next;
}
if (next !== null) {
next.previous = previous;
}
}
toString() {
return `CacheElement{ hasNext:${this.next !== null}, hasPrevious:${this.previous !== null}, weight:${this.weight}, key:${this.key}, value:${this.value} }`;
}
}