ringbuffer

package
v0.0.0-...-cb5804f Latest Latest
Warning

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

Go to latest
Published: May 23, 2016 License: BSD-3-Clause Imports: 0 Imported by: 1

Documentation

Overview

Package ringbuffer implements ringbuffer calculations. It is limited to a maximum of maxUint64 operations and will panic then.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any interface{}

Any type you want

type AnyBuffer

type AnyBuffer struct {
	Buffer *Buffer
	// contains filtered or unexported fields
}

AnyBuffer implements a ringbuffer over bytes

func NewAnyBuffer

func NewAnyBuffer(size uint64) *AnyBuffer

NewAnyBuffer returns a ringbuffer over any interface with size.

func (*AnyBuffer) GetPos

func (bb *AnyBuffer) GetPos(pos uint64) (Any, bool)

GetPos returns the entry at position pos, or !ok if it isnt contained.

func (*AnyBuffer) Pop

func (bb *AnyBuffer) Pop() (d Any, ok bool)

Pop reads one element from the buffer, returning success.

func (*AnyBuffer) PopSlice

func (bb *AnyBuffer) PopSlice(b []Any) (n int, ok bool)

PopSlice up to len(b) elements from the buffer, returning the number of elements read.

func (*AnyBuffer) Push

func (bb *AnyBuffer) Push(b ...Any) (n int, ok bool)

Push adds b to the buffer, returning the number of elements added.

func (*AnyBuffer) PushSlice

func (bb *AnyBuffer) PushSlice(b []Any) (n int, ok bool)

PushSlice adds elements from slice b to the buffer, returning the number of elemnts added.

func (*AnyBuffer) Resize

func (bb *AnyBuffer) Resize(size uint64) (newbuffer *AnyBuffer, ok bool)

Resize the AnyBuffer to new size. Returns true on success, false otherwise. Copies of AnyBuffer data become invalid with this operation.

type Buffer

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

Buffer implements a ring buffer calculator

func New

func New(size, fill uint64) *Buffer

New returns a new buffer of size. Fill is the current write position (when copying buffers).

func (*Buffer) Available

func (buf *Buffer) Available() uint64

Available returns the bytes available in the buffer for writing.

func (*Buffer) CutPoints

func (buf *Buffer) CutPoints() (firstSliceBegin, firstSliceEnd, secondSliceSkip, secondSliceBegin, secondSliceEnd uint64)

CutPoints returns the cut points for reslicing. The cutpoints can be used for simple reslicing for grow/shrink operations like this:

buffer_new:=New(newsize,buffer_old.Fill())
firstSliceBegin, firstSliceEnd, secondSliceSkip, secondSliceBegin, secondSliceEnd=huffer_old.CutPoints()
copy(buffer_new_data, buffer_old_data[firstSliceBegin:firstSliceEnd]
copy(buffer_new_data[secondSliceSkip:], buffer_old_data[secondSliceBegin:secondSliceEnd])

This results in a new ring buffer that has the correct read/write positions set.

func (*Buffer) Fill

func (buf *Buffer) Fill() uint64

Fill returns the number of elements in the buffer.

func (*Buffer) GetReadPos

func (buf *Buffer) GetReadPos() (uint64, bool)

GetReadPos returns the next read position, or 0,false.

func (*Buffer) GetWritePos

func (buf *Buffer) GetWritePos() (uint64, bool)

GetWritePos returns the next write position, or 0,false.

func (*Buffer) Set

func (buf *Buffer) Set(readpos, writepos uint64)

Set readpos and writepos.

func (*Buffer) Stat

func (buf *Buffer) Stat() (size, readpos, writepos uint64)

Stat returns the status of a buffer.

func (*Buffer) TransPos

func (buf *Buffer) TransPos(pos uint64) (uint64, bool)

TransPos translates positiong to the correct address. Returns false if not contained in ring.

type ByteBuffer

type ByteBuffer struct {
	Buffer *Buffer
	// contains filtered or unexported fields
}

ByteBuffer implements a ringbuffer over bytes

func NewByteBuffer

func NewByteBuffer(size uint64) *ByteBuffer

NewByteBuffer returns a ringbuffer over bytes with size.

func (*ByteBuffer) CutToPos

func (bb *ByteBuffer) CutToPos(pos uint64) ([]byte, bool)

CutToPos returns a byteslice containing all bytes up to and including pos. Returns false on failure

func (*ByteBuffer) FindByte

func (bb *ByteBuffer) FindByte(sep []byte, skip uint64) (uint64, bool)

FindByte finds s in buffer and returns the position. If the byte was not found, return the number of bytes searched.

func (*ByteBuffer) GetPos

func (bb *ByteBuffer) GetPos(pos uint64) (byte, bool)

GetPos returns the entry at position pos, or !ok if it isnt contained.

func (*ByteBuffer) Pop

func (bb *ByteBuffer) Pop() (d byte, ok bool)

Pop reads one byte from the buffer, returning success.

func (*ByteBuffer) PopSlice

func (bb *ByteBuffer) PopSlice(b []byte) (n int, ok bool)

PopSlice up to len(b) bytes from the buffer, returning the number of bytes read.

func (*ByteBuffer) Push

func (bb *ByteBuffer) Push(b ...byte) (n int, ok bool)

Push adds bytes b to the buffer, returning the number of bytes added.

func (*ByteBuffer) PushSlice

func (bb *ByteBuffer) PushSlice(b []byte) (n int, ok bool)

PushSlice adds bytes from slice b to the buffer, returning the number of bytes added.

func (*ByteBuffer) Resize

func (bb *ByteBuffer) Resize(size uint64) (newbuffer *ByteBuffer, ok bool)

Resize the bytebuffer to new size. Returns true on success, false otherwise. Copies of ByteBuffer data become invalid with this operation.

type ByteSliceBuffer

type ByteSliceBuffer struct {
	Buffer *Buffer
	// contains filtered or unexported fields
}

ByteSliceBuffer implements a ringbuffer over bytes

func NewByteSliceBuffer

func NewByteSliceBuffer(size uint64) *ByteSliceBuffer

NewByteSliceBuffer returns a ringbuffer over bytes with size.

func (*ByteSliceBuffer) GetPos

func (bb *ByteSliceBuffer) GetPos(pos uint64) ([]byte, bool)

GetPos returns the entry at position pos, or !ok if it isnt contained.

func (*ByteSliceBuffer) Pop

func (bb *ByteSliceBuffer) Pop() (d []byte, ok bool)

Pop reads one byteslice from the buffer, returning success.

func (*ByteSliceBuffer) PopSlice

func (bb *ByteSliceBuffer) PopSlice(b [][]byte) (n int, ok bool)

PopSlice up to len(b) byteslices from the buffer, returning the number of bytes read.

func (*ByteSliceBuffer) Push

func (bb *ByteSliceBuffer) Push(b ...[]byte) (n int, ok bool)

Push adds byteslice b to the buffer, returning the number of bytes added.

func (*ByteSliceBuffer) PushSlice

func (bb *ByteSliceBuffer) PushSlice(b [][]byte) (n int, ok bool)

PushSlice adds byteslices from slice b to the buffer, returning the number of bytes added.

func (*ByteSliceBuffer) Resize

func (bb *ByteSliceBuffer) Resize(size uint64) (newbuffer *ByteSliceBuffer, ok bool)

Resize the byteSlicebuffer to new size. Returns true on success, false otherwise. Copies of ByteSliceBuffer data become invalid with this operation.

type StringBuffer

type StringBuffer struct {
	Buffer *Buffer
	// contains filtered or unexported fields
}

StringBuffer implements a ringbuffer over bytes

func NewStringBuffer

func NewStringBuffer(size uint64) *StringBuffer

NewStringBuffer returns a ringbuffer over bytes with size.

func (*StringBuffer) GetPos

func (bb *StringBuffer) GetPos(pos uint64) (string, bool)

GetPos returns the entry at position pos, or !ok if it isnt contained.

func (*StringBuffer) Pop

func (bb *StringBuffer) Pop() (d string, ok bool)

Pop reads one string from the buffer, returning success.

func (*StringBuffer) PopSlice

func (bb *StringBuffer) PopSlice(b []string) (n int, ok bool)

PopSlice up to len(b) stringslice from the buffer, returning the number of bytes read.

func (*StringBuffer) Push

func (bb *StringBuffer) Push(b ...string) (n int, ok bool)

Push adds string b to the buffer, returning the number of bytes added.

func (*StringBuffer) PushSlice

func (bb *StringBuffer) PushSlice(b []string) (n int, ok bool)

PushSlice adds stringslice from slice b to the buffer, returning the number of bytes added.

func (*StringBuffer) Resize

func (bb *StringBuffer) Resize(size uint64) (newbuffer *StringBuffer, ok bool)

Resize the Stringbuffer to new size. Returns true on success, false otherwise. Copies of StringBuffer data become invalid with this operation.

Jump to

Keyboard shortcuts

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