From 66627838a3431e1a82636fb5fb9377777c2c0047 Mon Sep 17 00:00:00 2001 From: Dennis Trautwein Date: Thu, 4 Aug 2022 10:47:51 +0200 Subject: [PATCH] chore: remove obsolete least square fit --- netsize/netsize.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/netsize/netsize.go b/netsize/netsize.go index 3840a42f2..2fd6db809 100644 --- a/netsize/netsize.go +++ b/netsize/netsize.go @@ -34,7 +34,6 @@ type Estimator struct { localID kbucket.ID rt *kbucket.RoutingTable bucketSize int - lsqConst float64 measurementsLk sync.RWMutex measurements map[int][]measurement @@ -49,17 +48,22 @@ func NewEstimator(localID peer.ID, rt *kbucket.RoutingTable, bucketSize int) *Es measurements[i] = []measurement{} } - k := float64(bucketSize) - return &Estimator{ localID: kbucket.ConvertPeerID(localID), rt: rt, bucketSize: bucketSize, measurements: measurements, - lsqConst: k * (k + 1) * (2*k + 1) / 6.0, } } +// NormedDistance calculates the normed XOR distance of the given keys (from 0 to 1). +func NormedDistance(p peer.ID, k ks.Key) float64 { + pKey := ks.XORKeySpace.Key([]byte(p)) + ksDistance := new(big.Float).SetInt(pKey.Distance(k)) + normedDist, _ := new(big.Float).Quo(ksDistance, keyspaceMaxFloat).Float64() + return normedDist +} + type measurement struct { distance float64 weight float64 @@ -212,14 +216,6 @@ func (e *Estimator) calcWeight(key string) float64 { return math.Pow(2, float64(bucketLevel-e.bucketSize)) } -// NormedDistance calculates the normed XOR distance of the given keys (from 0 to 1). -func NormedDistance(p peer.ID, k ks.Key) float64 { - pKey := ks.XORKeySpace.Key([]byte(p)) - ksDistance := new(big.Float).SetInt(pKey.Distance(k)) - normedDist, _ := new(big.Float).Quo(ksDistance, keyspaceMaxFloat).Float64() - return normedDist -} - // garbageCollect removes all measurements from the list that fell out of the measurement time window. func (e *Estimator) garbageCollect() { logger.Debug("Running garbage collection")