MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / LFULogIncr

Function LFULogIncr

src/evict.cpp:309–317  ·  view source on GitHub ↗

Logarithmically increment a counter. The greater is the current counter value * the less likely is that it gets really implemented. Saturate it at 255. */

Source from the content-addressed store, hash-verified

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. */
309uint8_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

Callers 1

updateLFUFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected