Logarithmically increment a counter. The greater is the current counter value * the less likely is that it gets really implemented. Saturate it at 255. */
| 307 | /* Logarithmically increment a counter. The greater is the current counter value |
| 308 | * the less likely is that it gets really implemented. Saturate it at 255. */ |
| 309 | uint8_t LFULogIncr(uint8_t counter) { |
| 310 | if (counter == 255) return 255; |
| 311 | double r = (double)rand()/RAND_MAX; |
| 312 | double baseval = counter - LFU_INIT_VAL; |
| 313 | if (baseval < 0) baseval = 0; |
| 314 | double p = 1.0/(baseval*g_pserver->lfu_log_factor+1); |
| 315 | if (r < p) counter++; |
| 316 | return counter; |
| 317 | } |
| 318 | |
| 319 | /* If the object decrement time is reached decrement the LFU counter but |
| 320 | * do not update LFU fields of the object, we update the access time |