Add natural mob spawning for rotwalker
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// a Map that forgets the least recently used entries past max_size
|
||||
export class LruMap<K, V> {
|
||||
#map = new Map<K, V>();
|
||||
#newest: K | undefined;
|
||||
readonly max_size: number;
|
||||
|
||||
constructor(max_size: number) {
|
||||
@@ -9,7 +10,10 @@ export class LruMap<K, V> {
|
||||
|
||||
get(key: K): V | undefined {
|
||||
const value = this.#map.get(key);
|
||||
// already the most recent, the same key over and over is common
|
||||
if (key === this.#newest) return value;
|
||||
if (value !== undefined) {
|
||||
this.#newest = key;
|
||||
// maps keep insertion order, so re-inserting moves it to the back
|
||||
this.#map.delete(key);
|
||||
this.#map.set(key, value);
|
||||
@@ -18,6 +22,7 @@ export class LruMap<K, V> {
|
||||
}
|
||||
|
||||
set(key: K, value: V) {
|
||||
this.#newest = key;
|
||||
this.#map.delete(key);
|
||||
this.#map.set(key, value);
|
||||
if (this.#map.size > this.max_size) {
|
||||
@@ -25,6 +30,11 @@ export class LruMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
// without counting as a use
|
||||
has(key: K) {
|
||||
return this.#map.has(key);
|
||||
}
|
||||
|
||||
delete(key: K) {
|
||||
this.#map.delete(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user