ints

package
v0.0.0-...-53ff736 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 0 Imported by: 1

Documentation

Index

Constants

View Source
const (
	INT_BLOCK_SHIFT = 13
	INT_BLOCK_SIZE  = 1 << INT_BLOCK_SHIFT
	INT_BLOCK_MASK  = INT_BLOCK_SIZE - 1
)

Variables

View Source
var (
	// INT_NEXT_LEVEL_ARRAY An array holding the offset into the INT_LEVEL_SIZE_ARRAY to quickly navigate to the next slice level.
	INT_NEXT_LEVEL_ARRAY = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 9}

	// INT_LEVEL_SIZE_ARRAY An array holding the level sizes for int slices.
	INT_LEVEL_SIZE_ARRAY = []int{2, 4, 8, 16, 16, 32, 32, 64, 64, 128}

	// INT_FIRST_LEVEL_SIZE The first level size for new slices
	INT_FIRST_LEVEL_SIZE = INT_LEVEL_SIZE_ARRAY[0]
)

Functions

This section is empty.

Types

type AllocatorImp

type AllocatorImp struct {
	IntsArrayAllocatorNeed
	// contains filtered or unexported fields
}

AllocatorImp Abstract class for allocating and freeing int blocks.

func NewAllocator

func NewAllocator(blockSize int, need IntsArrayAllocatorNeed) *AllocatorImp

func (*AllocatorImp) GetIntBlock

func (a *AllocatorImp) GetIntBlock() []int

type BlockPool

type BlockPool struct {

	// Current head offset
	IntOffset int
	// contains filtered or unexported fields
}

BlockPool A pool for int blocks similar to ByteBlockPool

func NewBlockPool

func NewBlockPool(allocator IntsAllocator) *BlockPool

func (*BlockPool) AddIntUpto

func (i *BlockPool) AddIntUpto(v int)

func (*BlockPool) Buffer

func (i *BlockPool) Buffer() []int

func (*BlockPool) Get

func (i *BlockPool) Get(index int) []int

func (*BlockPool) IntUpto

func (i *BlockPool) IntUpto() int

func (*BlockPool) NextBuffer

func (i *BlockPool) NextBuffer()

NextBuffer Advances the pool to its next buffer. This method should be called once after the constructor to initialize the pool. In contrast to the constructor a reset() call will advance the pool to its first buffer immediately.

func (*BlockPool) Reset

func (i *BlockPool) Reset(zeroFillBuffers, reuseFirst bool)

Reset Expert: Resets the pool to its initial state reusing the first buffer. Params: zeroFillBuffers – if true the buffers are filled with 0. This should be set to true if this pool

is used with IntBlockPool.SliceWriter.
reuseFirst – if true the first buffer will be reused and calling nextBuffer() is not needed after
reset iff the block pool was used before ie. nextBuffer() was called before.

type DirectAllocator

type DirectAllocator struct {
	*AllocatorImp
}

func NewDirectAllocator

func NewDirectAllocator(blockSize int) *DirectAllocator

func (*DirectAllocator) RecycleIntBlocks

func (d *DirectAllocator) RecycleIntBlocks(blocks [][]int, start, end int)

type IntsAllocator

type IntsAllocator interface {
	RecycleIntBlocks(blocks [][]int, start, end int)
	GetIntBlock() []int
}

type IntsAllocatorDefault

type IntsAllocatorDefault struct {
	BlockSize          int
	FnRecycleIntBlocks func(blocks [][]int, start, end int)
}

func (*IntsAllocatorDefault) GetIntBlock

func (i *IntsAllocatorDefault) GetIntBlock() []int

func (*IntsAllocatorDefault) RecycleIntBlocks

func (i *IntsAllocatorDefault) RecycleIntBlocks(blocks [][]int, start, end int)

type IntsArrayAllocatorNeed

type IntsArrayAllocatorNeed interface {
	RecycleIntBlocks(blocks [][]int, start, end int)
}

type RecyclingIntBlockAllocator

type RecyclingIntBlockAllocator struct {
	*AllocatorImp

	DEFAULT_BUFFERED_BLOCKS int
	// contains filtered or unexported fields
}

func NewRecyclingIntBlockAllocator

func NewRecyclingIntBlockAllocator(blockSize, maxBufferedBlocks int) *RecyclingIntBlockAllocator

func (*RecyclingIntBlockAllocator) GetIntBlock

func (r *RecyclingIntBlockAllocator) GetIntBlock() []int

func (*RecyclingIntBlockAllocator) RecycleIntBlocks

func (r *RecyclingIntBlockAllocator) RecycleIntBlocks(blocks [][]int, start, end int)

type SliceReader

type SliceReader struct {
	// contains filtered or unexported fields
}

SliceReader A IntBlockPool.SliceReader that can read int slices written by a IntBlockPool.SliceWriter

func NewSliceReader

func NewSliceReader(pool *BlockPool) *SliceReader

func (*SliceReader) EndOfSlice

func (s *SliceReader) EndOfSlice() bool

EndOfSlice Returns true iff the current slice is fully read. If this method returns true readInt() should not be called again on this slice.

func (*SliceReader) ReadInt

func (s *SliceReader) ReadInt() int

ReadInt Reads the next int from the current slice and returns it. See Also: endOfSlice()

func (*SliceReader) Reset

func (s *SliceReader) Reset(startOffset, endOffset int)

Reset Resets the reader to a slice give the slices absolute start and end offset in the pool

type SliceWriter

type SliceWriter struct {
	// contains filtered or unexported fields
}

SliceWriter A IntBlockPool.SliceWriter that allows to write multiple integer slices into a given BlockPool. See Also: IntBlockPool.SliceReader

func NewSliceWriter

func NewSliceWriter(pool *BlockPool) *SliceWriter

func (*SliceWriter) GetCurrentOffset

func (s *SliceWriter) GetCurrentOffset() int

GetCurrentOffset Returns the offset of the currently written slice. The returned value should be used as the end offset to initialize a IntBlockPool.SliceReader once this slice is fully written or to reset the this writer if another slice needs to be written.

func (*SliceWriter) Reset

func (s *SliceWriter) Reset(sliceOffset int)

func (*SliceWriter) StartNewSlice

func (s *SliceWriter) StartNewSlice() int

StartNewSlice starts a new slice and returns the start offset. The returned value should be used as the start offset to initialize a IntBlockPool.SliceReader.

func (*SliceWriter) WriteInt

func (s *SliceWriter) WriteInt(value int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL