array

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcSharedArraySize

func CalcSharedArraySize(size, elemSize int) int

CalcSharedArraySize returns the size, needed to place shared array in memory.

Types

type SharedArray

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

SharedArray is an array placed in the shared memory with fixed length and element size. It is possible to swap elements and pop them from any position. It never moves elements in memory, so can be used to implement an array of futexes or spin locks.

func NewSharedArray

func NewSharedArray(raw unsafe.Pointer, size, elemSize int) *SharedArray

NewSharedArray initializes new shared array with size and element size.

func OpenSharedArray

func OpenSharedArray(raw unsafe.Pointer) *SharedArray

OpenSharedArray opens existing shared array.

func (*SharedArray) At

func (arr *SharedArray) At(i int) []byte

At returns data at the position i. Returned slice references to the data in the array. It does not perform border check.

func (*SharedArray) AtPointer

func (arr *SharedArray) AtPointer(i int) unsafe.Pointer

AtPointer returns pointer to the data at the position i. It does not perform border check.

func (*SharedArray) Cap

func (arr *SharedArray) Cap() int

Cap returns array's cpacity

func (*SharedArray) ElemSize

func (arr *SharedArray) ElemSize() int

ElemSize returns size of the element.

func (*SharedArray) Len

func (arr *SharedArray) Len() int

Len returns current length.

func (*SharedArray) PopBack

func (arr *SharedArray) PopBack()

PopBack removes the last element of the array.

func (*SharedArray) PopFront

func (arr *SharedArray) PopFront()

PopFront removes the first element of the array.

func (*SharedArray) PushBack

func (arr *SharedArray) PushBack(datas ...[]byte) int

PushBack add new element to the end of the array, merging given datas. Returns number of bytes copied, less or equal, than the size of the element.

func (*SharedArray) RemoveAt added in v0.4.0

func (arr *SharedArray) RemoveAt(i int)

RemoveAt removes i'th element.

func (*SharedArray) SafeLen added in v0.4.0

func (arr *SharedArray) SafeLen() int

SafeLen atomically loads returns current length.

func (*SharedArray) Swap

func (arr *SharedArray) Swap(i, j int)

Swap swaps two elements of the array.

Jump to

Keyboard shortcuts

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