mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
LFU: Fix bugs in frequency decay code.
This commit is contained in:
parent
a8e2d0849e
commit
dbce190ad0
@ -264,7 +264,7 @@ unsigned long LFUGetTimeInMinutes(void) {
|
||||
* exactly once. */
|
||||
unsigned long LFUTimeElapsed(unsigned long ldt) {
|
||||
unsigned long now = LFUGetTimeInMinutes();
|
||||
if (now > ldt) return now-ldt;
|
||||
if (now >= ldt) return now-ldt;
|
||||
return 65535-ldt+now;
|
||||
}
|
||||
|
||||
@ -291,7 +291,7 @@ uint8_t LFULogIncr(uint8_t counter) {
|
||||
unsigned long LFUDecrAndReturn(robj *o) {
|
||||
unsigned long ldt = o->lru >> 8;
|
||||
unsigned long counter = o->lru & 255;
|
||||
if (LFUTimeElapsed(ldt) > LFU_DECR_INTERVAL && counter) {
|
||||
if (LFUTimeElapsed(ldt) >= LFU_DECR_INTERVAL && counter) {
|
||||
if (counter > LFU_INIT_VAL*2) {
|
||||
counter /= 2;
|
||||
if (counter < LFU_INIT_VAL*2) counter = LFU_INIT_VAL*2;
|
||||
|
Loading…
Reference in New Issue
Block a user