mirror of
https://github.com/luxfi/math.git
synced 2026-07-27 01:24:06 +00:00
- Create math/big for big.Int utilities (HexOrDecimal256, U256, parsing) - Create math/safe for overflow-safe arithmetic (SafeAdd, SafeMul, etc.) - Move averager files to root package level - Add re-exports in root package for backwards compatibility - Update README with new package structure documentation - Remove old math/meter directory (consolidated elsewhere) - Remove redundant math/ subdirectory structure
35 lines
593 B
Go
35 lines
593 B
Go
// Copyright (C) 2019-2024, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package math
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type syncAverager struct {
|
|
lock sync.RWMutex
|
|
averager Averager
|
|
}
|
|
|
|
func NewSyncAverager(averager Averager) Averager {
|
|
return &syncAverager{
|
|
averager: averager,
|
|
}
|
|
}
|
|
|
|
func (a *syncAverager) Observe(value float64, currentTime time.Time) {
|
|
a.lock.Lock()
|
|
defer a.lock.Unlock()
|
|
|
|
a.averager.Observe(value, currentTime)
|
|
}
|
|
|
|
func (a *syncAverager) Read() float64 {
|
|
a.lock.RLock()
|
|
defer a.lock.RUnlock()
|
|
|
|
return a.averager.Read()
|
|
}
|