Skip to content

Commit

Permalink
chore: remove obsolete least square fit
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Aug 4, 2022
1 parent 316ab00 commit 6662783
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions netsize/netsize.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Estimator struct {
localID kbucket.ID
rt *kbucket.RoutingTable
bucketSize int
lsqConst float64

measurementsLk sync.RWMutex
measurements map[int][]measurement
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6662783

Please sign in to comment.