summaryrefslogtreecommitdiff
path: root/series/series.go
diff options
context:
space:
mode:
Diffstat (limited to 'series/series.go')
-rw-r--r--series/series.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/series/series.go b/series/series.go
index 0084007..43d9809 100644
--- a/series/series.go
+++ b/series/series.go
@@ -15,6 +15,7 @@ package series
import (
"fmt"
+ "sync"
"github.com/network-quality/goresponsiveness/utilities"
"golang.org/x/exp/constraints"
@@ -278,3 +279,20 @@ func NewWindowSeries[Data any, Bucket constraints.Ordered](tipe WindowSeriesDura
}
panic("")
}
+
+type NumericBucketGenerator[T utilities.Number] struct {
+ mt sync.Mutex
+ currentValue T
+}
+
+func (bg *NumericBucketGenerator[T]) Generate() T {
+ bg.mt.Lock()
+ defer bg.mt.Unlock()
+
+ bg.currentValue++
+ return bg.currentValue
+}
+
+func NewNumericBucketGenerator[T utilities.Number](initialValue T) NumericBucketGenerator[T] {
+ return NumericBucketGenerator[T]{currentValue: initialValue}
+}