@@ -16,6 +16,14 @@ limitations under the License.
16
16
17
17
package buffer
18
18
19
+ // RingGrowingOptions sets parameters for [RingGrowing] and
20
+ // [TypedRingGrowing].
21
+ type RingGrowingOptions struct {
22
+ // InitialSize is the number of pre-allocated elements in the
23
+ // initial underlying storage buffer.
24
+ InitialSize int
25
+ }
26
+
19
27
// RingGrowing is a growing ring buffer.
20
28
// Not thread safe.
21
29
//
@@ -26,7 +34,7 @@ type RingGrowing = TypedRingGrowing[any]
26
34
//
27
35
// Deprecated: Use NewTypedRingGrowing[any] instead.
28
36
func NewRingGrowing (initialSize int ) * RingGrowing {
29
- return NewTypedRingGrowing [any ](initialSize )
37
+ return NewTypedRingGrowing [any ](RingGrowingOptions { InitialSize : initialSize } )
30
38
}
31
39
32
40
// TypedRingGrowing is a growing ring buffer.
@@ -39,10 +47,10 @@ type TypedRingGrowing[T any] struct {
39
47
}
40
48
41
49
// NewTypedRingGrowing constructs a new TypedRingGrowing instance with provided parameters.
42
- func NewTypedRingGrowing [T any ](initialSize int ) * TypedRingGrowing [T ] {
50
+ func NewTypedRingGrowing [T any ](opts RingGrowingOptions ) * TypedRingGrowing [T ] {
43
51
return & TypedRingGrowing [T ]{
44
- data : make ([]T , initialSize ),
45
- n : initialSize ,
52
+ data : make ([]T , opts . InitialSize ),
53
+ n : opts . InitialSize ,
46
54
}
47
55
}
48
56
@@ -95,6 +103,16 @@ func (r *TypedRingGrowing[T]) Cap() int {
95
103
return r .n
96
104
}
97
105
106
+ // RingGrowingOptions sets parameters for [Ring].
107
+ type RingOptions struct {
108
+ // InitialSize is the number of pre-allocated elements in the
109
+ // initial underlying storage buffer.
110
+ InitialSize int
111
+ // NormalSize is the number of elements to allocate for new storage
112
+ // buffers once the Ring is consumed.
113
+ NormalSize int
114
+ }
115
+
98
116
// Ring is a dynamically-sized ring buffer which can grow and shrink as-needed.
99
117
// Not thread safe.
100
118
type Ring [T any ] struct {
@@ -103,10 +121,10 @@ type Ring[T any] struct {
103
121
}
104
122
105
123
// NewRing constructs a new Ring instance with provided parameters.
106
- func NewRing [T any ](initialSize int ) * Ring [T ] {
124
+ func NewRing [T any ](opts RingOptions ) * Ring [T ] {
107
125
return & Ring [T ]{
108
- growing : * NewTypedRingGrowing [T ](initialSize ),
109
- normalSize : initialSize ,
126
+ growing : * NewTypedRingGrowing [T ](RingGrowingOptions { InitialSize : opts . InitialSize } ),
127
+ normalSize : opts . NormalSize ,
110
128
}
111
129
}
112
130
0 commit comments