Logarithmically increment a counter. The greater is the current counter value * the less likely is that it gets really implemented. Saturate it at 255. */
| 296 | /* Logarithmically increment a counter. The greater is the current counter value |
| 297 | * the less likely is that it gets really implemented. Saturate it at 255. */ |
| 298 | uint8_t LFULogIncr(uint8_t counter) { |
| 299 | if (counter == 255) return 255; |
| 300 | double r = (double)rand()/RAND_MAX; |
| 301 | double baseval = counter - LFU_INIT_VAL; |
| 302 | if (baseval < 0) baseval = 0; |
| 303 | double p = 1.0/(baseval*server.lfu_log_factor+1); |
| 304 | if (r < p) counter++; |
| 305 | return counter; |
| 306 | } |
| 307 | |
| 308 | /* If the object decrement time is reached decrement the LFU counter but |
| 309 | * do not update LFU fields of the object, we update the access time |