Comparing version 0.0.800 to 0.0.801
@@ -10,3 +10,3 @@ import { Clock } from './clock'; | ||
const capacity = 96; | ||
const clock = new Clock<number, number>(capacity - 1, 100); | ||
const clock = new Clock<number, number>(capacity - 1); | ||
assert(clock['capacity'] === capacity); | ||
@@ -127,3 +127,3 @@ | ||
console.debug('Clock / LRU hit ratio', `${stats.clock / stats.lru * 100 | 0}%`); | ||
assert(stats.clock / stats.lru * 100 >>> 0 === 141); | ||
assert(stats.clock / stats.lru * 100 >>> 0 === 108); | ||
assert(clock['values'].length === capacity); | ||
@@ -151,3 +151,3 @@ }); | ||
console.debug('Clock / LRU hit ratio', `${stats.clock / stats.lru * 100 | 0}%`); | ||
assert(stats.clock / stats.lru * 100 >>> 0 === 127); | ||
assert(stats.clock / stats.lru * 100 >>> 0 === 105); | ||
assert(clock['values'].length === capacity); | ||
@@ -154,0 +154,0 @@ }); |
32
clock.ts
@@ -1,6 +0,3 @@ | ||
import { min } from './alias'; | ||
import { IterableDict } from './dict'; | ||
// True Clock | ||
const BASE = 32; | ||
@@ -19,3 +16,2 @@ const DIGIT = Math.log2(BASE); | ||
private readonly capacity: number, | ||
private readonly demotion: number = 8, | ||
) { | ||
@@ -32,16 +28,2 @@ assert(capacity > 0); | ||
private hand = 0; | ||
private stock = 0; | ||
private readonly threshold = 100 / this.demotion | 0; | ||
private $count = 0; | ||
public get count(): number { | ||
return this.$count; | ||
} | ||
public set count(value) { | ||
assert(value > 0); | ||
this.$count = value; | ||
if (value < this.threshold) return; | ||
this.stock = min(this.stock + value / this.threshold | 0, this.capacity); | ||
this.$count = min(value % this.threshold, this.capacity); | ||
assert(this.$count >= 0); | ||
} | ||
private $length = 0; | ||
@@ -95,7 +77,3 @@ public get length(): number { | ||
hand += BASE - r; | ||
this.count += BASE - r; | ||
if (this.stock > 0) { | ||
refs[i] = b & (1 << r) - 1; | ||
this.stock -= BASE - r; | ||
} | ||
refs[i] = b & (1 << r) - 1; | ||
r = 0; | ||
@@ -116,7 +94,3 @@ if (hand < capacity) { | ||
hand += l - r; | ||
this.count += l - r; | ||
if (this.stock > 0) { | ||
refs[i] = b & ~((1 << l) - 1 >>> r << r); | ||
this.stock -= l - r; | ||
} | ||
refs[i] = b & ~((1 << l) - 1 >>> r << r); | ||
} | ||
@@ -176,4 +150,2 @@ assert(hand < capacity); | ||
this.hand = 0; | ||
this.stock = 0; | ||
this.$count = 0; | ||
this.$length = 0; | ||
@@ -180,0 +152,0 @@ this.initial = 1; |
{ | ||
"name": "spica", | ||
"version": "0.0.800", | ||
"version": "0.0.801", | ||
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.", | ||
@@ -5,0 +5,0 @@ "private": false, |
862808
250
28082