MCPcopy Create free account
hub / github.com/cosdata/cosdata / counter_age

Function counter_age

src/models/lru_cache.rs:17–24  ·  view source on GitHub ↗

Calculates counter age, while considering a possibility of wraparound (with the assumption that wraparound will happen at most once) `global_value` > `item_value` indicates that wraparound has happened. In that case, the age is calculated taking that into consideration.

(global_value: u32, item_value: u32)

Source from the content-addressed store, hash-verified

15// consideration.
16//
17fn counter_age(global_value: u32, item_value: u32) -> u32 {
18 if global_value >= item_value {
19 global_value - item_value
20 } else {
21 // until wrap around + after wraparound
22 (u32::MAX - item_value) + global_value
23 }
24}
25
26pub struct EvictionIndex {
27 inner: [AtomicU64; 256],

Callers 1

eviction_probabilityMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected