package delta

import (
	
	

	
)

type int32Buffer struct {
	values []int32
}

func ( *int32Buffer) ( int) {
	if cap(.values) <  {
		.values = make([]int32, , 2*)
	} else {
		.values = .values[:]
	}
}

func ( *int32Buffer) ( []byte) ([]byte, error) {
	, ,  := decodeInt32(unsafecast.Slice[byte](.values[:0]), )
	.values = unsafecast.Slice[int32]()
	return , 
}

func ( *int32Buffer) () ( int32) {
	for ,  := range .values {
		 += 
	}
	return 
}

var (
	int32BufferPool sync.Pool // *int32Buffer
)

func getInt32Buffer() *int32Buffer {
	,  := int32BufferPool.Get().(*int32Buffer)
	if  != nil {
		.values = .values[:0]
	} else {
		 = &int32Buffer{
			values: make([]int32, 0, 1024),
		}
	}
	return 
}

func putInt32Buffer( *int32Buffer) {
	int32BufferPool.Put()
}

func resizeNoMemclr( []byte,  int) []byte {
	if cap() <  {
		return grow(, )
	}
	return [:]
}

func resize( []byte,  int) []byte {
	if cap() <  {
		return grow(, )
	}
	if  > len() {
		 := [len():]
		for  := range  {
			[] = 0
		}
	}
	return [:]
}

func grow( []byte,  int) []byte {
	 := 2 * cap()
	if  <  {
		 = 
	}
	 := make([]byte, , )
	copy(, )
	return 
}

func errPrefixAndSuffixLengthMismatch(,  int) error {
	return fmt.Errorf("length of prefix and suffix mismatch: %d != %d", , )
}

func errInvalidNegativeValueLength( int) error {
	return fmt.Errorf("invalid negative value length: %d", )
}

func errInvalidNegativePrefixLength( int) error {
	return fmt.Errorf("invalid negative prefix length: %d", )
}

func errValueLengthOutOfBounds(,  int) error {
	return fmt.Errorf("value length is larger than the input size: %d > %d", , )
}

func errPrefixLengthOutOfBounds(,  int) error {
	return fmt.Errorf("prefix length %d is larger than the last value of size %d", , )
}