Comparing version 0.0.799 to 0.0.800
@@ -857,3 +857,3 @@ import { max, min } from './alias'; | ||
constructor( | ||
private readonly step: number = 2, | ||
private readonly demotion: number = 2, | ||
private readonly window: number = 0, | ||
@@ -885,6 +885,6 @@ private readonly retrial: boolean = true, | ||
this.count = -max( | ||
//list.length * this.step / 100 / max(this.count / list.length * this.step, 1) | 0, | ||
(list.length - this.count) * this.step / 100 | 0, | ||
//list.length * this.demotion / 100 / max(this.count / list.length * this.demotion, 1) | 0, | ||
(list.length - this.count) * this.demotion / 100 | 0, | ||
list.length * this.window / 100 - this.count | 0, | ||
this.step && 1); | ||
this.demotion && 1); | ||
assert(this.count <= 0); | ||
@@ -891,0 +891,0 @@ } |
@@ -10,3 +10,3 @@ import { Clock } from './clock'; | ||
const capacity = 96; | ||
const clock = new Clock<number, number>(capacity - 1); | ||
const clock = new Clock<number, number>(capacity - 1, 100); | ||
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 === 108); | ||
assert(stats.clock / stats.lru * 100 >>> 0 === 141); | ||
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 === 105); | ||
assert(stats.clock / stats.lru * 100 >>> 0 === 127); | ||
assert(clock['values'].length === capacity); | ||
@@ -154,0 +154,0 @@ }); |
32
clock.ts
@@ -0,3 +1,6 @@ | ||
import { min } from './alias'; | ||
import { IterableDict } from './dict'; | ||
// True Clock | ||
const BASE = 32; | ||
@@ -16,2 +19,3 @@ const DIGIT = Math.log2(BASE); | ||
private readonly capacity: number, | ||
private readonly demotion: number = 8, | ||
) { | ||
@@ -28,2 +32,16 @@ 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; | ||
@@ -77,3 +95,7 @@ public get length(): number { | ||
hand += BASE - r; | ||
refs[i] = b & (1 << r) - 1; | ||
this.count += BASE - r; | ||
if (this.stock > 0) { | ||
refs[i] = b & (1 << r) - 1; | ||
this.stock -= BASE - r; | ||
} | ||
r = 0; | ||
@@ -94,3 +116,7 @@ if (hand < capacity) { | ||
hand += l - r; | ||
refs[i] = b & ~((1 << l) - 1 >>> r << r); | ||
this.count += l - r; | ||
if (this.stock > 0) { | ||
refs[i] = b & ~((1 << l) - 1 >>> r << r); | ||
this.stock -= l - r; | ||
} | ||
} | ||
@@ -150,2 +176,4 @@ assert(hand < capacity); | ||
this.hand = 0; | ||
this.stock = 0; | ||
this.$count = 0; | ||
this.$length = 0; | ||
@@ -152,0 +180,0 @@ this.initial = 1; |
{ | ||
"name": "spica", | ||
"version": "0.0.799", | ||
"version": "0.0.800", | ||
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -18,7 +18,7 @@ import { max } from './alias'; | ||
private readonly capacity: number, | ||
private readonly step: number = 2, | ||
private readonly demotion: number = 2, | ||
private readonly window: number = 0, | ||
private readonly retrial: boolean = true, | ||
// ヒットにより前方が増えるためstep=100では不足する。 | ||
private readonly pure: boolean = step >= 100, | ||
private readonly pure: boolean = demotion >= 100, | ||
) { | ||
@@ -43,6 +43,6 @@ assert(capacity > 0); | ||
this.count = -max( | ||
//list.length * this.step / 100 / max(this.count / list.length * this.step, 1) | 0, | ||
(list.length - this.count) * this.step / 100 | 0, | ||
//list.length * this.demotion / 100 / max(this.count / list.length * this.demotion, 1) | 0, | ||
(list.length - this.count) * this.demotion / 100 | 0, | ||
list.length * this.window / 100 - this.count | 0, | ||
this.step && 1); | ||
this.demotion && 1); | ||
assert(this.count <= 0); | ||
@@ -49,0 +49,0 @@ } |
@@ -18,3 +18,3 @@ import { max } from './alias'; | ||
private readonly capacity: number, | ||
private readonly step: number = 2, | ||
private readonly demotion: number = 2, | ||
private readonly window: number = 0, | ||
@@ -46,4 +46,4 @@ private readonly retrial: boolean = true, | ||
this.count = -max( | ||
//list.length * this.step / 100 / max(this.count / list.length * this.step, 1) | 0, | ||
(list.length - this.count) * this.step / 100 | 0, | ||
//list.length * this.demotion / 100 / max(this.count / list.length * this.demotion, 1) | 0, | ||
(list.length - this.count) * this.demotion / 100 | 0, | ||
list.length * this.window / 100 - this.count | 0, | ||
@@ -50,0 +50,0 @@ 1) - 1; |
@@ -13,3 +13,3 @@ // TLRU: True LRU | ||
stepパラメータはヒットエントリを重み付けおよび保護しており | ||
step=100で重み付けと保護なしの純粋なTLRUを設定できる。 | ||
demotion=100で重み付けと保護なしの純粋なTLRUを設定できる。 | ||
windowパラメータでSLRU同様捕捉可能最小再利用距離を設定できるが | ||
@@ -16,0 +16,0 @@ 降格区間内では捕捉可能再利用距離が半減しSLRUより短くなる。 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
851414
27728