@@ -4,21 +4,25 @@ import (
44 "math"
55)
66
7- // A count of something, capped at math.MaxUint32.
7+ // Count32 is a count of something, capped at math.MaxUint32.
88type Count32 uint32
99
10+ // NewCount32 initializes a Count32 from a uint64, capped at
11+ // math.MaxUint32.
1012func NewCount32 (n uint64 ) Count32 {
1113 if n > math .MaxUint32 {
1214 return Count32 (math .MaxUint32 )
1315 }
1416 return Count32 (n )
1517}
1618
19+ // ToUint64 returns the value of `n` as a `uint64`. If the value has
20+ // overflowed, it returns `(math.MaxUint32, true)`.
1721func (n Count32 ) ToUint64 () (uint64 , bool ) {
1822 return uint64 (n ), n == math .MaxUint32
1923}
2024
21- // Return the sum of two Count32s, capped at math.MaxUint32.
25+ // Plus returns the sum of two Count32s, capped at math.MaxUint32.
2226func (n1 Count32 ) Plus (n2 Count32 ) Count32 {
2327 n := n1 + n2
2428 if n < n1 {
@@ -28,7 +32,7 @@ func (n1 Count32) Plus(n2 Count32) Count32 {
2832 return n
2933}
3034
31- // Increment `*n1` by `n2`, capped at math.MaxUint32.
35+ // Increment increases `*n1` by `n2`, capped at math.MaxUint32.
3236func (n1 * Count32 ) Increment (n2 Count32 ) {
3337 * n1 = n1 .Plus (n2 )
3438}
@@ -55,18 +59,21 @@ func (n1 *Count32) AdjustMaxIfPossible(n2 Count32) bool {
5559 }
5660}
5761
58- // A count of something, capped at math.MaxUint64.
62+ // Count64 is a count of something, capped at math.MaxUint64.
5963type Count64 uint64
6064
65+ // NewCount64 initializes a Count64 from a uint64.
6166func NewCount64 (n uint64 ) Count64 {
6267 return Count64 (n )
6368}
6469
70+ // ToUint64 returns the value of `n` as a `uint64`. If the value has
71+ // overflowed, it returns `(math.MaxUint64, true)`.
6572func (n Count64 ) ToUint64 () (uint64 , bool ) {
6673 return uint64 (n ), n == math .MaxUint64
6774}
6875
69- // Return the sum of two Count64s, capped at math.MaxUint64.
76+ // Plus returns the sum of two Count64s, capped at math.MaxUint64.
7077func (n1 Count64 ) Plus (n2 Count64 ) Count64 {
7178 n := n1 + n2
7279 if n < n1 {
@@ -76,7 +83,7 @@ func (n1 Count64) Plus(n2 Count64) Count64 {
7683 return n
7784}
7885
79- // Increment `*n1` by `n2`, capped at math.MaxUint64.
86+ // Increment increases `*n1` by `n2`, capped at math.MaxUint64.
8087func (n1 * Count64 ) Increment (n2 Count64 ) {
8188 * n1 = n1 .Plus (n2 )
8289}
0 commit comments