Replacer
source: bluebase/pf/replacer.py
- class PfReplacer[source]
Bases:
ABCAn abstract base class for replacers that select eviction candidate keys.
- class PfRandomReplacer(*, seed: int = 0)[source]
Bases:
PfReplacerA replacer that selects eviction candidate keys using a random policy.
- Variables:
seed (int) – the random seed
rng (random.Random) – the random number generator
set – the container holding the currently managed keys
- class PfFifoReplacer[source]
Bases:
PfReplacerA replacer that selects eviction candidate keys using a FIFO policy.
- Variables:
keys (collections.OrderedDict[object, None]) – the container holding the currently managed keys
- class PfClockReplacer(*, chance: int = 2)[source]
Bases:
PfReplacerA replacer that selects eviction candidate keys using the Clock algorithm.
- Variables:
chance (int) – the maximum grace count used by the Clock algorithm
slots (list[object | None]) – the container holding the currently managed keys
counter (list[int]) – the grace counts corresponding to the slots
find (dict[object, int]) – a mapping from each key to its slot index
frees (list[int]) – the indices of free slots
hand (int) – the slot index currently pointed to by the clock hand
- class PfLruReplacer[source]
Bases:
PfReplacerA replacer that selects eviction candidate keys using an LRU policy.
- Variables:
keys (collections.OrderedDict[object, None]) – the container holding the currently managed keys
- assignmentadd(key: object) None[source]
Add a key.
Hint
When using either
dictorOrderedDict, the insertion order is preserved.
- assignmentremove(key: object) None[source]
Remove a key.
Hint
It should not raise an exception even if the key is not found.