diff options
author | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-20 17:58:55 +0530 |
---|---|---|
committer | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-20 17:58:55 +0530 |
commit | 2f95efc236520485c7cc1439acae24140657d76c (patch) | |
tree | 10eac60e3eec8e6b3bb9c27e131cd531363c39d6 /utils.go | |
parent | Added Eviction and Options setup (diff) | |
download | cache-2f95efc236520485c7cc1439acae24140657d76c.tar cache-2f95efc236520485c7cc1439acae24140657d76c.tar.gz cache-2f95efc236520485c7cc1439acae24140657d76c.tar.bz2 cache-2f95efc236520485c7cc1439acae24140657d76c.tar.lz cache-2f95efc236520485c7cc1439acae24140657d76c.tar.xz cache-2f95efc236520485c7cc1439acae24140657d76c.tar.zst cache-2f95efc236520485c7cc1439acae24140657d76c.zip |
Add Tests and benchmarks
Diffstat (limited to '')
-rw-r--r-- | utils.go | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -6,11 +6,15 @@ import ( "time" ) +// pauseTimer is a struct that wraps a time.Ticker and provides additional functionality +// to pause and resume the ticker. +// If the duration is 0, the timer is created in a stopped state. type pauseTimer struct { *time.Ticker duration time.Duration } +// newPauseTimer creates a new pauseTimer with the specified duration. func newPauseTimer(d time.Duration) *pauseTimer { ret := &pauseTimer{duration: d} if d != 0 { @@ -22,12 +26,15 @@ func newPauseTimer(d time.Duration) *pauseTimer { return ret } +// newPauseTimerStopped creates a new pauseTimer with the specified duration and stops it immediately. func newPauseTimerStopped(d time.Duration) *pauseTimer { ret := newPauseTimer(d) ret.Stop() return ret } +// Reset sets the timer to the specified duration and starts it. +// If the duration is 0, the timer is stopped. func (t *pauseTimer) Reset(d time.Duration) { t.duration = d if t.duration == 0 { @@ -37,19 +44,23 @@ func (t *pauseTimer) Reset(d time.Duration) { } } +// Resume resumes the timer with its last set duration. func (t *pauseTimer) Resume() { t.Reset(t.GetDuration()) } +// GetDuration returns the current duration of the timer. func (t *pauseTimer) GetDuration() time.Duration { return t.duration } +// zero returns the zero value for the specified type. func zero[T any]() T { var ret T return ret } +// hash computes the 64-bit FNV-1a hash of the provided data. func hash(data []byte) uint64 { hasher := fnv.New64() if _, err := hasher.Write(data); err != nil { |