diff --git a/go.mod b/go.mod index 28953423..868102c6 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/named-data/YaNFD go 1.23.0 require ( - github.com/cornelk/hashmap v1.0.8 github.com/goccy/go-yaml v1.15.10 github.com/gorilla/websocket v1.5.3 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index f8c736b0..b9a2f970 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cornelk/hashmap v1.0.8 h1:nv0AWgw02n+iDcawr5It4CjQIAcdMMKRrs10HOJYlrc= -github.com/cornelk/hashmap v1.0.8/go.mod h1:RfZb7JO3RviW/rT6emczVuC/oxpdz4UsSB2LJSclR1k= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/goccy/go-yaml v1.15.10 h1:9exV2CDYm/FWHPptIIgcDiPQS+X/4uTR+HEl+GF9xJU= diff --git a/table/measurements.go b/table/measurements.go deleted file mode 100644 index 32351086..00000000 --- a/table/measurements.go +++ /dev/null @@ -1,74 +0,0 @@ -/* YaNFD - Yet another NDN Forwarding Daemon - * - * Copyright (C) 2020-2021 Eric Newberry. - * - * This file is licensed under the terms of the MIT License, as found in LICENSE.md. - */ - -package table - -import ( - "github.com/cornelk/hashmap" -) - -type measurements struct { - table hashmap.Map[string, any] -} - -// Measurements contains the global measurements table, -var Measurements *measurements - -func init() { - Measurements = new(measurements) -} - -// Get returns the measurement table value at the specified key or nil if it does not exist. -func (m *measurements) Get(key string) interface{} { - value, isOk := m.table.Get(key) - if !isOk { - return nil - } - return value -} - -// Set atomically sets the value of the specified measurement table key only if it is equal to the expected value, -// returning whether the operation was successful. -func (m *measurements) Set(key string, expected interface{}, value interface{}) bool { - if v, ok := m.table.Get(key); ok && v == expected { - m.table.Set(key, value) - return true - } else { - return false - } -} - -// AddToInt adds the specified value to the given measurement key, setting as value if unitialized. -func (m *measurements) AddToInt(key string, value int) { - wasSet := false - for !wasSet { - expected := m.Get(key) - if expected != nil { - wasSet = m.Set(key, expected, expected.(int)+value) - } else { - _, wasSet = m.table.GetOrInsert(key, value) - // We need to flip this because it returns false if set - wasSet = !wasSet - } - } -} - -// AddSampleToEWMA adds a sample to an exponentially weighted moving average -func (m *measurements) AddSampleToEWMA(key string, measurement float64, alpha float64) { - wasSet := false - for !wasSet { - expected := m.Get(key) - if expected != nil { - newValue := measurement + alpha*(measurement-expected.(float64)) - wasSet = m.Set(key, expected, newValue) - } else { - _, wasSet = m.table.GetOrInsert(key, measurement) - // We need to flip this because it returns false if set - wasSet = !wasSet - } - } -}