Documentation
¶
Overview ¶
Package dedup provides a time-windowed deduplication cache suitable for suppressing recently-seen APRS/AX.25 frames across the transmit governor, the digipeater, and the iGate.
Window is generic over a key type and an optional per-entry value type. Callers that only need presence tracking use struct{} for the value; callers that need to carry a small amount of metadata (e.g. the iGate's "was the previous packet a fixed-station beacon" bit) parameterize Window with a richer value type.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// TTL is the suppression window. Required; a non-positive value
// panics in New to surface mis-configuration early.
TTL time.Duration
// GCThreshold is the map size at which opportunistic eviction of
// expired entries runs. Zero means defaultGCThreshold.
GCThreshold int
// Now overrides the clock for tests. Zero means time.Now.
Now func() time.Time
}
Config controls Window behavior.
type Window ¶
type Window[K comparable, V any] struct { // contains filtered or unexported fields }
Window is a time-based dedup cache. Keys are compared for equality; entries are evicted lazily when the caller touches the Window and the entry is older than the configured TTL. A background goroutine is not used.
func New ¶
func New[K comparable, V any](cfg Config) *Window[K, V]
New builds a Window. Panics if cfg.TTL <= 0.
func (*Window[K, V]) Len ¶
Len returns the current number of tracked entries. Intended for metrics and tests; does not run GC.
func (*Window[K, V]) Peek ¶
Peek returns the most recent recorded value and time for k, and whether k is currently tracked. Does not evict or refresh. The returned time may be older than the TTL; callers that care about TTL-bounded presence should compare against the configured window.
func (*Window[K, V]) Record ¶
func (w *Window[K, V]) Record(k K, v V)
Record stores (k, v) at the current time without returning whether k was previously present. Use after a capacity or condition check that is independent of the dedup state.
func (*Window[K, V]) Seen ¶
Seen records (k, v) at the current time and returns the previous value and true if k was already present within TTL before this call; otherwise returns (zero, false) after recording (k, v). The clock is sampled once per call.