Comparing version 0.0.782 to 0.0.783
{ | ||
"name": "spica", | ||
"version": "0.0.782", | ||
"version": "0.0.783", | ||
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -17,16 +17,11 @@ // https://jasony.me/publication/sosp23-s3fifo.pdf | ||
constructor( | ||
private capacity: number, | ||
private readonly capacity: number, | ||
) { | ||
this.capS = capacity * 0.1 >>> 0; | ||
this.capM = capacity - this.capS; | ||
this.fifoS = new Queue(); | ||
this.fifoM = new Queue(); | ||
this.fifoG = new Queue(); | ||
} | ||
private readonly dict = new Map<K, Node<K, V>>(); | ||
private readonly capS: number; | ||
private readonly capM: number; | ||
private readonly fifoS: Queue<Node<K, V>>; | ||
private readonly fifoM: Queue<Node<K, V>>; | ||
private readonly fifoG: Queue<Node<K, undefined>>; | ||
private readonly capS = this.capacity * 0.1 >>> 0; | ||
private readonly capM = this.capacity - this.capS; | ||
private readonly fifoS = new Queue<Node<K, V>>(); | ||
private readonly fifoM = new Queue<Node<K, V>>(); | ||
private readonly fifoG = new Queue<Node<K, undefined>>(); | ||
public get length(): number { | ||
@@ -111,15 +106,8 @@ return this.fifoS.length + this.fifoM.length; | ||
} | ||
public add(key: K, value: V): boolean { | ||
const node = new Node(key, value); | ||
this.insert(node); | ||
this.dict.set(key, node); | ||
assert(this.dict.size <= this.capacity + this.capM); | ||
assert(this.length <= this.capacity); | ||
assert(this.fifoG.length <= this.capM); | ||
return true; | ||
} | ||
public set(key: K, value: V): this { | ||
const node = this.dict.get(key); | ||
if (node === undefined) { | ||
this.add(key, value); | ||
const node = new Node(key, value); | ||
this.insert(node); | ||
this.dict.set(key, node); | ||
} | ||
@@ -126,0 +114,0 @@ else { |
@@ -16,3 +16,3 @@ import { List } from './list'; | ||
constructor( | ||
private capacity: number, | ||
private readonly capacity: number, | ||
private readonly partition = 80, | ||
@@ -19,0 +19,0 @@ ) { |
@@ -106,4 +106,4 @@ import { max } from './alias'; | ||
const { list } = this; | ||
if (list.length === 0) return; | ||
const entry = this.handV ??= list.last!; | ||
const entry = this.handV ?? list.last; | ||
if (entry === undefined) return; | ||
this.delete(entry.key); | ||
@@ -110,0 +110,0 @@ return [entry.key, entry.value]; |
@@ -118,4 +118,4 @@ import { max } from './alias'; | ||
const { list } = this; | ||
if (list.length === 0) return; | ||
const entry = list.last!; | ||
const entry = list.last; | ||
if (entry === undefined) return; | ||
this.delete(entry.key); | ||
@@ -122,0 +122,0 @@ return [entry.key, entry.value]; |
@@ -9,4 +9,8 @@ // TLRU: True LRU | ||
TLRUはすべての最近性を保持する。 | ||
DWCより高速かつ堅牢で小さいキャッシュサイズに適している。 | ||
パラメータを調整しやすくDWCより高ヒット率となることもある。 | ||
パラメータを調整しやすく用途に合わせてヒット率を上げやすい。 | ||
stepパラメータはヒットエントリを重み付けおよび保護しており | ||
step=100で重み付けと保護なしの純粋なTLRUを設定できる。 | ||
windowパラメータでSLRU同様捕捉可能最小再利用距離を保証できる。 | ||
DWCより高速かつ堅牢でアプリケーションのインメモリキャッシュなどの | ||
極端に変化の大きいアクセスパターンにも適応する。 | ||
@@ -13,0 +17,0 @@ */ |
842036
27490