UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

60 lines (52 loc) 1.33 kB
/** * Doubly-linked list implementation for key-value pairs * @template Key, Value * @class */ export class CacheElement { /** * @template Key, Value * @constructor */ constructor() { /** * * @type {Key} */ this.key = null; /** * * @type {Value} */ this.value = null; /** * * @type {number} */ this.weight = 0; /** * Link to next element (implements linked list) * @type {CacheElement<Key,Value>|null} */ this.next = null; /** * Link to previous element (implements linked list) * @type {CacheElement<Key,Value>|null} */ this.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} }`; } }