Skip to content

Commit 258a5e4

Browse files
committed
history: improve variable names and comments
1 parent f8fe590 commit 258a5e4

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

pkg/kv/kvserver/asim/history/thrashing.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,29 @@ func computeThrashing(values []float64) thrashing {
7979
// in the dominant direction (if there is one). If no direction is dominant, the
8080
// result roughly matches the total variation.
8181
//
82-
// The inputs tu and td are the upwards and (positive) downwards total
83-
// variations, respectively.
82+
// The inputs u and d are the upwards and (positive) downwards total variations,
83+
// respectively.
8484
//
8585
// Properties:
86-
// - symmetric in tu, td
87-
// - min(u,d) <= tdtv(tu,td) <= tu+td
86+
// - tdtv(u,d) = tdtv(d,u) (symmetry)
87+
// - min(u,d) <= tdtv(u,d) <= u+d
8888
// - tdtv(u,0) = tdtv(0,u) = 0
89-
// - tdtv(u,u) = 2t
90-
// - tdtv(ku,kd) = k*tdtv(u,d) for k>=0
91-
// - tdtv(l*ku, kd) > tdtv(ku) for l>1 (same for kd)
92-
func tdtv(tu, td float64) float64 {
93-
tmin := min(tu, td)
89+
// - tdtv(u,u) = 2⋅u
90+
// - tdtv(k⋅u,k⋅d) = ktdtv(u,d) for k0
91+
// - tdtv(l⋅u, d) > tdtv(u) for l>1 (same in second argument)
92+
func tdtv(u, d float64) float64 {
93+
tmin := min(u, d)
9494
if tmin == 0 {
9595
// There's only one direction of movement, so we discount all variation.
9696
return 0
9797
}
98-
frac := tmin / max(tu, td) // in [0, 1]
98+
frac := tmin / max(u, d) // in [0, 1]
9999
// The exponent can't exceed 1 because that would violate the scaling property
100-
// (last property above). For the endpoint 1, tdtv=2min(tu,td). The choice of
101-
// 0.8 is somewhat arbitrary, but gives a reasonable trade-off.
100+
// (last property above). For the endpoint exponent 1, tdtv=2⋅min(u,d), and for
101+
// the endpoint exponent 0, we get the (vanilla) total variation u+d.
102+
// The choice of 0.8 is somewhat arbitrary, but gives a reasonable trade-off.
102103
alpha := math.Pow(frac, 0.8)
103-
return alpha*(tu+td) + (1-alpha)*tmin
104+
return alpha*(u+d) + (1-alpha)*tmin
104105
}
105106

106107
func extrema(vs []float64) (vmin, vmax, vrange float64) {

0 commit comments

Comments
 (0)