Documentation ¶
Overview ¶
Package ringbuffer implements ringbuffer calculations. It is limited to a maximum of maxUint64 operations and will panic then.
Index ¶
- type Any
- type AnyBuffer
- func (bb *AnyBuffer) GetPos(pos uint64) (Any, bool)
- func (bb *AnyBuffer) Pop() (d Any, ok bool)
- func (bb *AnyBuffer) PopSlice(b []Any) (n int, ok bool)
- func (bb *AnyBuffer) Push(b ...Any) (n int, ok bool)
- func (bb *AnyBuffer) PushSlice(b []Any) (n int, ok bool)
- func (bb *AnyBuffer) Resize(size uint64) (newbuffer *AnyBuffer, ok bool)
- type Buffer
- func (buf *Buffer) Available() uint64
- func (buf *Buffer) CutPoints() (firstSliceBegin, firstSliceEnd, secondSliceSkip, secondSliceBegin, ... uint64)
- func (buf *Buffer) Fill() uint64
- func (buf *Buffer) GetReadPos() (uint64, bool)
- func (buf *Buffer) GetWritePos() (uint64, bool)
- func (buf *Buffer) Set(readpos, writepos uint64)
- func (buf *Buffer) Stat() (size, readpos, writepos uint64)
- func (buf *Buffer) TransPos(pos uint64) (uint64, bool)
- type ByteBuffer
- func (bb *ByteBuffer) CutToPos(pos uint64) ([]byte, bool)
- func (bb *ByteBuffer) FindByte(sep []byte, skip uint64) (uint64, bool)
- func (bb *ByteBuffer) GetPos(pos uint64) (byte, bool)
- func (bb *ByteBuffer) Pop() (d byte, ok bool)
- func (bb *ByteBuffer) PopSlice(b []byte) (n int, ok bool)
- func (bb *ByteBuffer) Push(b ...byte) (n int, ok bool)
- func (bb *ByteBuffer) PushSlice(b []byte) (n int, ok bool)
- func (bb *ByteBuffer) Resize(size uint64) (newbuffer *ByteBuffer, ok bool)
- type ByteSliceBuffer
- func (bb *ByteSliceBuffer) GetPos(pos uint64) ([]byte, bool)
- func (bb *ByteSliceBuffer) Pop() (d []byte, ok bool)
- func (bb *ByteSliceBuffer) PopSlice(b [][]byte) (n int, ok bool)
- func (bb *ByteSliceBuffer) Push(b ...[]byte) (n int, ok bool)
- func (bb *ByteSliceBuffer) PushSlice(b [][]byte) (n int, ok bool)
- func (bb *ByteSliceBuffer) Resize(size uint64) (newbuffer *ByteSliceBuffer, ok bool)
- type StringBuffer
- func (bb *StringBuffer) GetPos(pos uint64) (string, bool)
- func (bb *StringBuffer) Pop() (d string, ok bool)
- func (bb *StringBuffer) PopSlice(b []string) (n int, ok bool)
- func (bb *StringBuffer) Push(b ...string) (n int, ok bool)
- func (bb *StringBuffer) PushSlice(b []string) (n int, ok bool)
- func (bb *StringBuffer) Resize(size uint64) (newbuffer *StringBuffer, ok bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnyBuffer ¶
type AnyBuffer struct { Buffer *Buffer // contains filtered or unexported fields }
AnyBuffer implements a ringbuffer over bytes
func NewAnyBuffer ¶
NewAnyBuffer returns a ringbuffer over any interface with size.
func (*AnyBuffer) PopSlice ¶
PopSlice up to len(b) elements from the buffer, returning the number of elements read.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements a ring buffer calculator
func New ¶
New returns a new buffer of size. Fill is the current write position (when copying buffers).
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) GetReadPos ¶
GetReadPos returns the next read position, or 0,false.
func (*Buffer) GetWritePos ¶
GetWritePos returns the next write position, or 0,false.
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.