1// Code generated by array/bufferbuilder_numeric.gen.go.tmpl. DO NOT EDIT.
2
3// Licensed to the Apache Software Foundation (ASF) under one
4// or more contributor license agreements.  See the NOTICE file
5// distributed with this work for additional information
6// regarding copyright ownership.  The ASF licenses this file
7// to you under the Apache License, Version 2.0 (the
8// "License"); you may not use this file except in compliance
9// with the License.  You may obtain a copy of the License at
10//
11// http://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS,
15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16// See the License for the specific language governing permissions and
17// limitations under the License.
18
19package array
20
21import (
22	"github.com/apache/arrow/go/v6/arrow"
23	"github.com/apache/arrow/go/v6/arrow/bitutil"
24	"github.com/apache/arrow/go/v6/arrow/memory"
25)
26
27type int32BufferBuilder struct {
28	bufferBuilder
29}
30
31func newInt32BufferBuilder(mem memory.Allocator) *int32BufferBuilder {
32	return &int32BufferBuilder{bufferBuilder: bufferBuilder{refCount: 1, mem: mem}}
33}
34
35// AppendValues appends the contents of v to the buffer, growing the buffer as needed.
36func (b *int32BufferBuilder) AppendValues(v []int32) { b.Append(arrow.Int32Traits.CastToBytes(v)) }
37
38// Values returns a slice of length b.Len().
39// The slice is only valid for use until the next buffer modification. That is, until the next call
40// to Advance, Reset, Finish or any Append function. The slice aliases the buffer content at least until the next
41// buffer modification.
42func (b *int32BufferBuilder) Values() []int32 { return arrow.Int32Traits.CastFromBytes(b.Bytes()) }
43
44// Value returns the int32 element at the index i. Value will panic if i is negative or ≥ Len.
45func (b *int32BufferBuilder) Value(i int) int32 { return b.Values()[i] }
46
47// Len returns the number of int32 elements in the buffer.
48func (b *int32BufferBuilder) Len() int { return b.length / arrow.Int32SizeBytes }
49
50// AppendValue appends v to the buffer, growing the buffer as needed.
51func (b *int32BufferBuilder) AppendValue(v int32) {
52	if b.capacity < b.length+arrow.Int32SizeBytes {
53		newCapacity := bitutil.NextPowerOf2(b.length + arrow.Int32SizeBytes)
54		b.resize(newCapacity)
55	}
56	arrow.Int32Traits.PutValue(b.bytes[b.length:], v)
57	b.length += arrow.Int32SizeBytes
58}
59