Documentation
¶
Overview ¶
Package buffer implements ring buffers of bytes.
Index ¶
- type Buffer
- func (b Buffer) Cap() uint
- func (b *Buffer) Clear()
- func (b *Buffer) CommitBulkRead(length uint)
- func (b *Buffer) CommitBulkWrite(length uint)
- func (b Buffer) DebugString() string
- func (b Buffer) GoString() string
- func (b *Buffer) Init(numBits byte)
- func (b Buffer) IsEmpty() bool
- func (b Buffer) IsFull() bool
- func (b Buffer) Len() uint
- func (b Buffer) NumBits() byte
- func (b *Buffer) PrepareBulkRead(length uint) []byte
- func (b *Buffer) PrepareBulkWrite(length uint) []byte
- func (b *Buffer) Read(p []byte) (int, error)
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) ReadFrom(r io.Reader) (int64, error)
- func (b Buffer) String() string
- func (b *Buffer) Write(p []byte) (int, error)
- func (b *Buffer) WriteByte(ch byte) error
- func (b *Buffer) WriteTo(w io.Writer) (int64, error)
- type Error
- type Window
- func (w Window) Cap() uint
- func (w *Window) Clear()
- func (w Window) DebugString() string
- func (w Window) FindLongestPrefix(p []byte) (distance uint, length uint, ok bool)
- func (w Window) GoString() string
- func (w Window) Hash(hashes ...hash.Hash)
- func (w Window) Hash32(fn func() hash.Hash32) uint32
- func (w *Window) Init(numBits byte)
- func (w Window) IsEmpty() bool
- func (w Window) IsFull() bool
- func (w Window) Len() uint
- func (w Window) LookupByte(distance uint) (byte, error)
- func (w Window) NumBits() byte
- func (w Window) String() string
- func (w *Window) Write(p []byte) (int, error)
- func (w *Window) WriteByte(ch byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements a ring buffer. The ring buffer has space for 2**N bytes for user-specified N.
func (*Buffer) CommitBulkRead ¶
CommitBulkRead completes the bulk read begun by the previous call to PrepareBulkRead. The argument must be between 0 and the length of the slice returned by PrepareBulkRead.
func (*Buffer) CommitBulkWrite ¶
CommitBulkWrite completes the bulk write begun by the previous call to PrepareBulkWrite. The argument must be between 0 and the length of the slice returned by PrepareBulkWrite.
func (Buffer) DebugString ¶ added in v1.1.0
func (*Buffer) Init ¶
Init initializes the Buffer. The Buffer will hold a maximum of 2**N bits, where N is the argument provided. The argument must be a number between 0 and 31 inclusive.
func (Buffer) NumBits ¶ added in v1.1.0
NumBits returns the number of bits used to initialize this Buffer.
func (*Buffer) PrepareBulkRead ¶
PrepareBulkRead obtains a slice from which the caller can read bytes. The bytes do not leave the buffer's contents until CommitBulkRead is called. If CommitBulkRead is not subsequently called, the read acts as a "peek" operation.
The returned slice may contain fewer bytes than requested; it will return a zero-length slice iff the buffer is empty. The caller must check its length before using it. A short but non-empty return slice does *not* indicate an empty buffer.
The returned slice is only valid until the next call to any mutating method on this Buffer; mutating methods are those which take a pointer receiver.
func (*Buffer) PrepareBulkWrite ¶
PrepareBulkWrite obtains a slice into which the caller can write bytes. The bytes do not become a part of the buffer's contents until CommitBulkWrite is called. If CommitBulkWrite is not subsequently called, the write is considered abandoned.
The returned slice may contain fewer bytes than requested; it will return a nil slice iff the buffer is full. The caller must check the slice's length before using it. A short but non-empty return slice does *not* indicate a full buffer.
The returned slice is only valid until the next call to any mutating method on this Buffer; mutating methods are those which take a pointer receiver.
func (*Buffer) Read ¶
Read reads a slice of bytes from the Buffer. If the buffer is empty, ErrEmpty is returned.
func (*Buffer) ReadByte ¶
ReadByte reads a single byte from the Buffer. If the buffer is empty, ErrEmpty is returned.
func (*Buffer) ReadFrom ¶
ReadFrom attempts to fill this Buffer by reading from the provided Reader. May return any error returned by the Reader, including io.EOF. If a nil error is returned, then the buffer is now full.
func (*Buffer) Write ¶
Write writes a slice of bytes to the Buffer. If the Buffer is full, as many bytes as possible are written to the Buffer and ErrFull is returned.
type Error ¶
type Error byte
Error is the type for the error constants returned by this package.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window implements a sliding window backed by a ring buffer. The ring buffer has space for 2**N bytes for user-specified N.
func (Window) DebugString ¶ added in v1.1.0
func (Window) FindLongestPrefix ¶
FindLongestPrefix searches the Window for the longest prefix of the given byte slice that exists within the Window's history.
This method could use some additional optimization.
func (Window) Hash ¶
Hash non-destructively writes the contents of the Window into the provided Hash object(s).
func (Window) Hash32 ¶
Hash32 is a convenience method that constructs a Hash32, calls Window.Hash with it, and calls Sum32 on it.
func (*Window) Init ¶
Init initializes the Window. The Window will hold a maximum of 2**N bits, where N is the argument provided. The argument must be a number between 0 and 31 inclusive.
func (Window) LookupByte ¶
LookupByte returns a byte which was written previously. The argument is the offset into the window, with 1 representing the most recently written byte and Window.Cap() representing the oldest byte still within the Window.
func (Window) NumBits ¶ added in v1.1.0
NumBits returns the number of bits used to initialize this Window.