lfu

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.5.0

type Config struct {
	// Capacity is total cache capacity in items (used to size structures). Required.
	Capacity int
	// Shards (power-of-two). If <= 0, we choose based on GOMAXPROCS and capacity.
	Shards int
	// MinTableLenPerShard clamps the per-shard table length (power-of-two). Default 8192.
	MinTableLenPerShard int
	// SampleMultiplier scales the reset (aging) threshold: resetAt = SampleMultiplier * numCounters.
	// Typical 8–16; default 10.
	SampleMultiplier int
	// DoorBitsPerCounter controls doorkeeper size; default 8 bits per counter index.
	DoorBitsPerCounter int
}

type ShardedAdmitter added in v1.5.0

type ShardedAdmitter struct {
	// contains filtered or unexported fields
}

func NewShardedAdmitter added in v1.5.0

func NewShardedAdmitter(cfg Config) *ShardedAdmitter

func (*ShardedAdmitter) Allow added in v1.5.0

func (a *ShardedAdmitter) Allow(candidate, victim uint64) bool

Allow returns true if the candidate should replace a victim according to TinyLFU. If the candidate is unseen by the doorkeeper we conservatively reject (unless caller uses a small “window” segment to bypass admission).

func (*ShardedAdmitter) Estimate added in v1.5.0

func (a *ShardedAdmitter) Estimate(h uint64) uint8

Estimate exposes freq estimate (for metrics/diagnostics).

func (*ShardedAdmitter) Record added in v1.5.0

func (a *ShardedAdmitter) Record(h uint64)

Record observes a key access. We use the doorkeeper to gate noise: first sight ➜ set bit only. Second (or FP) sight ➜ increment TinyLFU sketch (approximate frequency).

func (*ShardedAdmitter) Reset added in v1.5.0

func (a *ShardedAdmitter) Reset()

Reset forces aging now (useful for tests or ops hooks). Also resets the doorkeeper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL