Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit b3b842c

Browse files
Add Reset() method to String array (#2)
1 parent 2d9728c commit b3b842c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

go/arrow/array/string.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
stringArrayMaximumCapacity = math.MaxInt32
3131
)
3232

33-
// A type which represents an immutable sequence of variable-length UTF-8 strings.
33+
// String is a type which represents an immutable sequence of variable-length UTF-8 strings.
3434
type String struct {
3535
array
3636
offsets []int32
@@ -45,11 +45,18 @@ func NewStringData(data *Data) *String {
4545
return a
4646
}
4747

48+
// Reset resets the String with a different set of Data.
49+
func (a *String) Reset(data *Data) {
50+
a.setData(data)
51+
}
52+
4853
// Value returns the slice at index i. This value should not be mutated.
4954
func (a *String) Value(i int) string {
5055
i = i + a.array.data.offset
5156
return a.values[a.offsets[i]:a.offsets[i+1]]
5257
}
58+
59+
// ValueOffset returns the offset of the value at index i.
5360
func (a *String) ValueOffset(i int) int { return int(a.offsets[i]) }
5461

5562
func (a *String) String() string {
@@ -104,6 +111,7 @@ type StringBuilder struct {
104111
builder *BinaryBuilder
105112
}
106113

114+
// NewStringBuilder creates a new StringBuilder.
107115
func NewStringBuilder(mem memory.Allocator) *StringBuilder {
108116
b := &StringBuilder{
109117
builder: NewBinaryBuilder(mem, arrow.BinaryTypes.String),
@@ -134,10 +142,12 @@ func (b *StringBuilder) Cap() int { return b.builder.Cap() }
134142
// NullN returns the number of null values in the array builder.
135143
func (b *StringBuilder) NullN() int { return b.builder.NullN() }
136144

145+
// Append appends a string to the builder.
137146
func (b *StringBuilder) Append(v string) {
138147
b.builder.Append([]byte(v))
139148
}
140149

150+
// AppendNull appends a null to the builder.
141151
func (b *StringBuilder) AppendNull() {
142152
b.builder.AppendNull()
143153
}
@@ -149,6 +159,7 @@ func (b *StringBuilder) AppendValues(v []string, valid []bool) {
149159
b.builder.AppendStringValues(v, valid)
150160
}
151161

162+
// Value returns the string at index i.
152163
func (b *StringBuilder) Value(i int) string {
153164
return string(b.builder.Value(i))
154165
}

0 commit comments

Comments
 (0)