Version: v0.0.0-...-a69e935 Latest Latest

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

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




This section is empty.


This section is empty.


This section is empty.


type CircularBuffer

type CircularBuffer struct {
	// contains filtered or unexported fields

CircularBuffer is a circular buffer implementation

func NewCircularBuffer

func NewCircularBuffer(bufferSize int) *CircularBuffer

NewCircularBuffer creates an circular buffer with size bufferSize

func (*CircularBuffer) AddItem

func (c *CircularBuffer) AddItem(data interface{}) (*CircularBufferItem, error)

AddItem add a data record into the circular buffer, returns the CircularBufferItem created

func (*CircularBuffer) Capacity

func (c *CircularBuffer) Capacity() int

Capacity returns the total capacity of the circular buffer

func (*CircularBuffer) GetItem

func (c *CircularBuffer) GetItem(sequence uint64) (*CircularBufferItem, error)

GetItem returns the CircularBufferItem located by sequence id

func (*CircularBuffer) GetItemsByRange

func (c *CircularBuffer) GetItemsByRange(from uint64, to uint64) ([]*CircularBufferItem, error)

GetItemsByRange returns the CircularBufferItems located by sequence id. Both from and to are inclusive This function is best effort, it returns partial content if the specified range overlap with the actual buffer range

func (*CircularBuffer) GetRange

func (c *CircularBuffer) GetRange() (uint64, uint64)

GetRange returns the head / tail of the circular buffer

func (*CircularBuffer) MoveTail

func (c *CircularBuffer) MoveTail(newTail uint64) ([]*CircularBufferItem, error)

MoveTail increases the tail position, and return the list of CircularBufferItem moved out

func (*CircularBuffer) Size

func (c *CircularBuffer) Size() int

Size returns the size used in the circular buffer

type CircularBufferItem

type CircularBufferItem struct {
	SequenceID uint64
	Value      interface{}

CircularBufferItem is the item stored in the circular buffer

Jump to

Keyboard shortcuts

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