| 1 |
// options.go - functional options for sieve cache construction |
| 2 |
// |
| 3 |
// (c) 2024 Sudhi Herle <[email protected]> |
| 4 |
// |
| 5 |
// Copyright 2024- Sudhi Herle <sw-at-herle-dot-net> |
| 6 |
// License: BSD-2-Clause |
| 7 |
// |
| 8 |
// If you need a commercial license for this work, please contact |
| 9 |
// the author. |
| 10 |
// |
| 11 |
// This software does not come with any express or implied |
| 12 |
// warranty; it is provided "as is". No claim is made to its |
| 13 |
// suitability for any purpose. |
| 14 |
|
| 15 |
package sieve |
| 16 |
|
| 17 |
// config holds internal configuration built from Options. |
| 18 |
type config struct { |
| 19 |
k int // visited counter saturation; 1 = classic SIEVE |
| 20 |
} |
| 21 |
|
| 22 |
// Option configures a Sieve cache at construction time. |
| 23 |
type Option func(*config) |
| 24 |
|
| 25 |
// WithVisitClamp creates a SIEVE-k cache where each entry can accumulate |
| 26 |
// up to k visit counts before being considered "maximally visited". |
| 27 |
// k=1 is equivalent to classic SIEVE (the default). k>1 uses multi-bit |
| 28 |
// saturating counters: an item accessed k+1 times survives k eviction |
| 29 |
// passes. Values less than 1 are clamped to 1. |
| 30 |
func WithVisitClamp(k int) Option { |
| 31 |
return func(c *config) { c.k = k } |
| 32 |
} |