@@ -4,21 +4,25 @@ import (
4
4
"math"
5
5
)
6
6
7
- // A count of something, capped at math.MaxUint32.
7
+ // Count32 is a count of something, capped at math.MaxUint32.
8
8
type Count32 uint32
9
9
10
+ // NewCount32 initializes a Count32 from a uint64, capped at
11
+ // math.MaxUint32.
10
12
func NewCount32 (n uint64 ) Count32 {
11
13
if n > math .MaxUint32 {
12
14
return Count32 (math .MaxUint32 )
13
15
}
14
16
return Count32 (n )
15
17
}
16
18
19
+ // ToUint64 returns the value of `n` as a `uint64`. If the value has
20
+ // overflowed, it returns `(math.MaxUint32, true)`.
17
21
func (n Count32 ) ToUint64 () (uint64 , bool ) {
18
22
return uint64 (n ), n == math .MaxUint32
19
23
}
20
24
21
- // Return the sum of two Count32s, capped at math.MaxUint32.
25
+ // Plus returns the sum of two Count32s, capped at math.MaxUint32.
22
26
func (n1 Count32 ) Plus (n2 Count32 ) Count32 {
23
27
n := n1 + n2
24
28
if n < n1 {
@@ -28,7 +32,7 @@ func (n1 Count32) Plus(n2 Count32) Count32 {
28
32
return n
29
33
}
30
34
31
- // Increment `*n1` by `n2`, capped at math.MaxUint32.
35
+ // Increment increases `*n1` by `n2`, capped at math.MaxUint32.
32
36
func (n1 * Count32 ) Increment (n2 Count32 ) {
33
37
* n1 = n1 .Plus (n2 )
34
38
}
@@ -55,18 +59,21 @@ func (n1 *Count32) AdjustMaxIfPossible(n2 Count32) bool {
55
59
}
56
60
}
57
61
58
- // A count of something, capped at math.MaxUint64.
62
+ // Count64 is a count of something, capped at math.MaxUint64.
59
63
type Count64 uint64
60
64
65
+ // NewCount64 initializes a Count64 from a uint64.
61
66
func NewCount64 (n uint64 ) Count64 {
62
67
return Count64 (n )
63
68
}
64
69
70
+ // ToUint64 returns the value of `n` as a `uint64`. If the value has
71
+ // overflowed, it returns `(math.MaxUint64, true)`.
65
72
func (n Count64 ) ToUint64 () (uint64 , bool ) {
66
73
return uint64 (n ), n == math .MaxUint64
67
74
}
68
75
69
- // Return the sum of two Count64s, capped at math.MaxUint64.
76
+ // Plus returns the sum of two Count64s, capped at math.MaxUint64.
70
77
func (n1 Count64 ) Plus (n2 Count64 ) Count64 {
71
78
n := n1 + n2
72
79
if n < n1 {
@@ -76,7 +83,7 @@ func (n1 Count64) Plus(n2 Count64) Count64 {
76
83
return n
77
84
}
78
85
79
- // Increment `*n1` by `n2`, capped at math.MaxUint64.
86
+ // Increment increases `*n1` by `n2`, capped at math.MaxUint64.
80
87
func (n1 * Count64 ) Increment (n2 Count64 ) {
81
88
* n1 = n1 .Plus (n2 )
82
89
}
0 commit comments