Skip to content

Commit

Permalink
Updated to Golang 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
edmc-ss committed Dec 7, 2022
1 parent 8f9596b commit 2dba26e
Show file tree
Hide file tree
Showing 29 changed files with 284 additions and 448 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ FROM alpine:3.17 as base
RUN apk add --no-cache libc6-compat

FROM base as dev
ARG GolangVersion=1.19.3
ARG GolangVersion=1.19.4
RUN apk add --no-cache \
bind-tools \
curl \
Expand Down
61 changes: 22 additions & 39 deletions bucketstats/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// placed in a structure and registered, with a name, via a call to Register()
// before being used. The set of the statistics registered can be queried using
// the registered name or individually.
//
package bucketstats

import (
Expand All @@ -31,7 +30,6 @@ const (
// values added.
//
// Adding a negative value is not supported.
//
type Totaler interface {
Increment()
Add(value uint64)
Expand All @@ -43,7 +41,6 @@ type Totaler interface {
//
// This adds a CountGet() function that returns the number of values added as
// well as an AverageGet() method that returns the average.
//
type Averager interface {
Totaler
CountGet() (count uint64)
Expand All @@ -57,11 +54,11 @@ type Averager interface {
// RangeHigh the largest value mapped to the bucket
// NominalVal the nominal value of the bucket (sqrt(2)^n or 2^n)
// MeanVal the mean value of values added to the bucket, assuming
// a uniform distribution
//
// a uniform distribution
//
// When performing math on these statistics be careful of overflowing a uint64.
// It may be a good idea to use the "math/big" package.
//
type BucketInfo struct {
Count uint64
NominalVal uint64
Expand All @@ -77,7 +74,6 @@ type BucketInfo struct {
//
// DistGet() returns the distribution of values across the buckets as an array
// of BucketInfo.
//
type Bucketer interface {
Averager
DistGet() []BucketInfo
Expand All @@ -93,7 +89,6 @@ type Bucketer interface {
// of stats. One or the other, but not both, can be the empty string.
// Whitespace characters, '"' (double quote), '*' (asterik), and ':' (colon) are
// not allowed in either name.
//
func Register(pkgName string, statsGroupName string, statsStruct interface{}) {
register(pkgName, statsGroupName, statsStruct)
}
Expand All @@ -102,7 +97,6 @@ func Register(pkgName string, statsGroupName string, statsStruct interface{}) {
//
// Once unregistered, the same or a different set of statistics can be
// registered using the same name.
//
func UnRegister(pkgName string, statsGroupName string) {
unRegister(pkgName, statsGroupName)
}
Expand All @@ -115,7 +109,6 @@ func UnRegister(pkgName string, statsGroupName string) {
//
// Use "*" to select all package names with a given group name, all
// groups with a given package name, or all groups.
//
func SprintStats(stringFmt StatStringFormat, pkgName string, statsGroupName string) (values string) {
return sprintStats(stringFmt, pkgName, statsGroupName)
}
Expand All @@ -124,7 +117,6 @@ func SprintStats(stringFmt StatStringFormat, pkgName string, statsGroupName stri
//
// Name must be unique within statistics in the structure. If it is "" then
// Register() will assign a name based on the name of the field.
//
type Total struct {
total uint64 // Ensure 64-bit alignment
Name string
Expand All @@ -143,7 +135,6 @@ func (this *Total) TotalGet() uint64 {
}

// Return a string with the statistic's value in the specified format.
//
func (this *Total) Sprint(stringFmt StatStringFormat, pkgName string, statsGroupName string) string {
return this.sprint(stringFmt, pkgName, statsGroupName)
}
Expand All @@ -153,22 +144,19 @@ func (this *Total) Sprint(stringFmt StatStringFormat, pkgName string, statsGroup
//
// Name must be unique within statistics in the structure. If it is "" then
// Register() will assign a name based on the name of the field.
//
type Average struct {
count uint64 // Ensure 64-bit alignment
total uint64 // Ensure 64-bit alignment
Name string
}

// Add a value to the mean statistics.
//
func (this *Average) Add(value uint64) {
atomicAddUint64(&this.total, value)
atomicAddUint64(&this.count, 1)
}

// Add a value of 1 to the mean statistics.
//
func (this *Average) Increment() {
this.Add(1)
}
Expand All @@ -186,7 +174,6 @@ func (this *Average) AverageGet() uint64 {
}

// Return a string with the statistic's value in the specified format.
//
func (this *Average) Sprint(stringFmt StatStringFormat, pkgName string, statsGroupName string) string {
return this.sprint(stringFmt, pkgName, statsGroupName)
}
Expand All @@ -206,18 +193,19 @@ func (this *Average) Sprint(stringFmt StatStringFormat, pkgName string, statsGro
//
// Example mappings of values to buckets:
//
// Values Bucket
// 0 0
// 1 1
// 2 2
// 3 - 5 3
// 6 - 11 4
// Values Bucket
// 0 0
// 1 1
// 2 2
// 3 - 5 3
// 6 - 11 4
//
// 12 - 22 5
// etc.
//
// etc.
//
// Note that value 2^n increments the count in bucket n + 1, but the average of
// values in bucket n is very slightly larger than 2^n.
//
type BucketLog2Round struct {
Name string
NBucket uint
Expand All @@ -243,7 +231,6 @@ func (this *BucketLog2Round) Add(value uint64) {
}

// Add a value of 1 to the bucketized statistics.
//
func (this *BucketLog2Round) Increment() {
this.Add(1)
}
Expand All @@ -264,13 +251,11 @@ func (this *BucketLog2Round) AverageGet() uint64 {
}

// Return BucketInfo information for all the buckets.
//
func (this *BucketLog2Round) DistGet() []BucketInfo {
return bucketDistMake(this.NBucket, this.statBuckets[:], log2RoundBucketTable[:])
}

// Return a string with the statistic's value in the specified format.
//
func (this *BucketLog2Round) Sprint(stringFmt StatStringFormat, pkgName string, statsGroupName string) string {
return bucketSprint(stringFmt, pkgName, statsGroupName, this.Name, this.DistGet())
}
Expand All @@ -293,20 +278,21 @@ func (this *BucketLog2Round) Sprint(stringFmt StatStringFormat, pkgName string,
//
// Example mappings of values to buckets:
//
// Values Bucket
// 0 0
// 1 1
// 2 2
// 3 3
// 4 4
// 5 - 6 5
// 7 - 9 6
// Values Bucket
// 0 0
// 1 1
// 2 2
// 3 3
// 4 4
// 5 - 6 5
// 7 - 9 6
//
// 10 - 13 7
// etc.
//
// etc.
//
// Note that a value sqrt(2)^n increments the count in bucket 2 * n, but the
// average of values in bucket n is slightly larger than sqrt(2)^n.
//
type BucketLogRoot2Round struct {
Name string
NBucket uint
Expand All @@ -332,7 +318,6 @@ func (this *BucketLogRoot2Round) Add(value uint64) {
}

// Add a value of 1 to the bucketized statistics.
//
func (this *BucketLogRoot2Round) Increment() {
this.Add(1)
}
Expand All @@ -353,13 +338,11 @@ func (this *BucketLogRoot2Round) AverageGet() uint64 {
}

// Return BucketInfo information for all the buckets.
//
func (this *BucketLogRoot2Round) DistGet() []BucketInfo {
return bucketDistMake(this.NBucket, this.statBuckets[:], logRoot2RoundBucketTable[:])
}

// Return a string with the statistic's value in the specified format.
//
func (this *BucketLogRoot2Round) Sprint(stringFmt StatStringFormat, pkgName string, statsGroupName string) string {
return bucketSprint(stringFmt, pkgName, statsGroupName, this.Name, this.DistGet())
}
2 changes: 0 additions & 2 deletions bucketstats/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ func TestTotaler(t *testing.T) {
}

// Test Bucketer specific functionality (which is mostly buckets)
//
func TestBucketer(t *testing.T) {

var (
Expand Down Expand Up @@ -553,7 +552,6 @@ func TestSprintStats(t *testing.T) {
//
// If panic() is called with a nil argument then this function also returns the
// empty string.
//
func catchAPanic(aFunc func()) (panicStr string) {

defer func() {
Expand Down
15 changes: 3 additions & 12 deletions bucketstats/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var (

// Register a set of statistics, where the statistics are one or more fields in
// the passed structure.
//
func register(pkgName string, statsGroupName string, statsStruct interface{}) {

var ok bool
Expand Down Expand Up @@ -157,7 +156,6 @@ func unRegister(pkgName string, statsGroupName string) {
}

// Return the selected group(s) of statistics as a string.
//
func sprintStats(statFmt StatStringFormat, pkgName string, statsGroupName string) (statValues string) {

statsNameMapLock.Lock()
Expand Down Expand Up @@ -246,7 +244,6 @@ func sprintStatsStruct(statFmt StatStringFormat, pkgName string, statsGroupName
}

// Construct and return a statistics name (fully qualified field name) in the specified format.
//
func statisticName(statFmt StatStringFormat, pkgName string, statsGroupName string, fieldName string) string {

switch statFmt {
Expand All @@ -273,7 +270,6 @@ func statisticName(statFmt StatStringFormat, pkgName string, statsGroupName stri
}

// Return the "name" of the bucket that would hold 'n' as the string "2^x".
//
func bucketNameLog2(value uint64) string {

var idx uint
Expand All @@ -289,7 +285,6 @@ func bucketNameLog2(value uint64) string {

// Return the "name" of the bucket that would hold 'n' as the string "2^x",
// where x can have the suffix ".5" as in "2^7.5".
//
func bucketNameLogRoot2(value uint64) string {

var idx uint
Expand All @@ -307,7 +302,6 @@ func bucketNameLogRoot2(value uint64) string {
}

// Return a string with the statistic's value in the specified format.
//
func (this *Total) sprint(statFmt StatStringFormat, pkgName string, statsGroupName string) string {

statName := statisticName(statFmt, pkgName, statsGroupName, this.Name)
Expand All @@ -321,7 +315,6 @@ func (this *Total) sprint(statFmt StatStringFormat, pkgName string, statsGroupNa
}

// Return a string with the statistic's value in the specified format.
//
func (this *Average) sprint(statFmt StatStringFormat, pkgName string, statsGroupName string) string {

statName := statisticName(statFmt, pkgName, statsGroupName, this.Name)
Expand All @@ -341,7 +334,6 @@ func (this *Average) sprint(statFmt StatStringFormat, pkgName string, statsGroup

// The canonical distribution for a bucketized statistic is an array of BucketInfo.
// Create one based on the information for this bucketstat .
//
func bucketDistMake(nBucket uint, statBuckets []uint32, bucketInfoBase []BucketInfo) []BucketInfo {

// copy the base []BucketInfo before modifying it
Expand Down Expand Up @@ -371,11 +363,12 @@ func bucketDistMake(nBucket uint, statBuckets []uint32, bucketInfoBase []BucketI
//
// o the index of the first entry with a non-zero count
// o the index + 1 of the last entry with a non-zero count, or zero if no such
// bucket exists
//
// bucket exists
//
// o the count (number things in buckets)
// o sum of counts * count_meanVal, and
// o mean (average)
//
func bucketCalcStat(bucketInfo []BucketInfo) (firstIdx int, maxIdx int, count uint64, sum uint64, mean uint64) {

var (
Expand Down Expand Up @@ -421,7 +414,6 @@ func bucketCalcStat(bucketInfo []BucketInfo) (firstIdx int, maxIdx int, count ui
}

// Return a string with the bucketized statistic content in the specified format.
//
func bucketSprint(statFmt StatStringFormat, pkgName string, statsGroupName string, fieldName string,
bucketInfo []BucketInfo) string {

Expand Down Expand Up @@ -459,7 +451,6 @@ func bucketSprint(statFmt StatStringFormat, pkgName string, statsGroupName strin
}

// Replace illegal characters in names with underbar (`_`)
//
func scrubName(name string) string {

// Names should include only pritable characters that are not
Expand Down
7 changes: 0 additions & 7 deletions bucketstats/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
// values they hold.

// generate the tables for BucketStatsLogRoot2
//
func genLogRoot2Table() {

logRoot2Index := func(val int) (logRoot2_x float64, idx uint) {
Expand All @@ -41,7 +40,6 @@ func genLogRoot2Table() {
}

// generate the tables for BucketStatsLog2
//
func genLog2Table() {

log2Index := func(val int) (log2_x float64, idx uint) {
Expand All @@ -68,7 +66,6 @@ func genLog2Table() {
// indexFunc() is either our tweaked version of log2(x) or logRoot2(x) with
// float64 being the actual value and int being the bucket index its mapped
// to.
//
func genIdxTable(name string, indexFunc func(int) (float64, uint)) {
var (
indent int = 8
Expand Down Expand Up @@ -115,7 +112,6 @@ func genIdxTable(name string, indexFunc func(int) (float64, uint)) {
// indexFunc() is either our tweaked version of log2(x) or logRoot2(x) for the
// table with float64 being the actual value and int being the bucket index its
// mapped to.
//
func genBucketTable(name string, indexFunc func(int) (float64, uint),
nBucket uint, bucketsPerBit uint) {

Expand Down Expand Up @@ -209,7 +205,6 @@ func genBucketTable(name string, indexFunc func(int) (float64, uint),

// Compute round(sqrt(2)^n) for 0 <= n < 128 and return as a uint64 accurate in
// all 64 bits.
//
func powRoot2(n uint) (pow64 uint64) {
var (
bigBase big.Float
Expand All @@ -236,7 +231,6 @@ func powRoot2(n uint) (pow64 uint64) {

// print a list of which bucket the first 256 values go in and the average
// value represented by the bucket
//
func showDistr(bucketTable []uint8) {

// track info for each bucket
Expand Down Expand Up @@ -283,7 +277,6 @@ func showDistr(bucketTable []uint8) {
//
// One consequence is that the log base 2 statistics require 65 buckets for 64
// bit numbers instead of 64 buckets.
//
var log2RoundIdxTable = [256]uint8{
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// -Inf 0.0 1.0 1.6 2.0 2.3 2.6 2.8 3.0 3.2 3.3 3.5 3.6 3.7 3.8 3.9
Expand Down
Loading

0 comments on commit 2dba26e

Please sign in to comment.