Atlas › Test

TestUpdateSameBucket

Exact test identity: go.temporal.io/server/common/number/TestCompact8Suite/TestUpdateSameBucket

Package
go.temporal.io/server/common/number
Suite / test hierarchy
TestCompact8Suite/TestUpdateSameBucket
Test
TestUpdateSameBucket
Introduced at
TestUpdateSameBucket Frontier kind: Test frontier
Covered ranges
7
Covered lines
25
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/number/compact8.go 25 covered LOC · 7 ranges

Open complete file

34 // The value is rounded down to the nearest representable value.
35 // Negative values go to 0 and values above the maximum representable go to 255.
36 > func EncodeCompact8(value int64) Compact8 { compact8.go
37 > if value <= 0 {
38 return 0
39 }
40
41 > uval := uint64(value) compact8.go
42 > bitLen := bits.Len64(uval)
43 >
44 > // Find shift such that uval >> shift is in [12, 23].
45 > // This extracts the significand for the normalized representation.
46 > shift := max(bitLen-5, 0)
47 > sig := int(uval >> uint(shift))
48 > if sig >= 24 {
49 > shift++
50 > sig = int(uval >> uint(shift))
51 > }
52
53 > e := shift - compact8offset compact8.go
54 >
55 > if e >= 1 {
56 > m := sig - 12 compact8.go
57 > b := e*12 + m
58 > if b > 255 {
59 return 255
60 }
61 > return Compact8(b) compact8.go
62 }
63
76 // it sticks to prev unless the new code is significantly closer. This prevents
77 // oscillation when the underlying value fluctuates near a bucket boundary.
78 > func UpdateCompact8(value int64, prev Compact8) Compact8 { compact8.go
79 > newCode := EncodeCompact8(value)
80 > if newCode == prev {
81 > return prev compact8.go
82 > }
83 newDist := value - DecodeCompact8(newCode) // always >= 0 (round-down)
84 oldDist := DecodeCompact8(prev) - value