Documentation ¶
Index ¶
- type CircularBuffer
- func (c *CircularBuffer) AddItem(data interface{}) (*CircularBufferItem, error)
- func (c *CircularBuffer) Capacity() int
- func (c *CircularBuffer) GetItem(sequence uint64) (*CircularBufferItem, error)
- func (c *CircularBuffer) GetItemsByRange(from uint64, to uint64) ([]*CircularBufferItem, error)
- func (c *CircularBuffer) GetRange() (uint64, uint64)
- func (c *CircularBuffer) MoveTail(newTail uint64) ([]*CircularBufferItem, error)
- func (c *CircularBuffer) Size() int
- type CircularBufferItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircularBuffer ¶
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