Documentation ¶
Overview ¶
Package buffer provides multiple byte buffer implementations.
Index ¶
- type Buffer
- func (buffer Buffer) Bytes() []byte
- func (buffer Buffer) BytesView() []byte
- func (buffer *Buffer) Clear()
- func (buffer *Buffer) CommitBulkRead(length uint)
- func (buffer *Buffer) CommitBulkWrite(length uint)
- func (buffer Buffer) DebugString() string
- func (buffer Buffer) GoString() string
- func (buffer *Buffer) Init(numBits uint)
- func (buffer Buffer) IsEmpty() bool
- func (buffer Buffer) IsFull() bool
- func (buffer Buffer) Len() uint
- func (buffer Buffer) NumBits() uint
- func (buffer *Buffer) PrepareBulkRead(length uint) []byte
- func (buffer *Buffer) PrepareBulkWrite(length uint) []byte
- func (buffer *Buffer) Read(data []byte) (int, error)
- func (buffer *Buffer) ReadByte() (byte, error)
- func (buffer *Buffer) ReadFrom(r io.Reader) (int64, error)
- func (buffer Buffer) Size() uint
- func (buffer Buffer) String() string
- func (buffer *Buffer) Write(data []byte) (int, error)
- func (buffer *Buffer) WriteByte(ch byte) error
- func (buffer *Buffer) WriteTo(w io.Writer) (int64, error)
- type Error
- type Hybrid
- func (hybrid *Hybrid) Advance() (buf []byte, matchDistance uint, matchLength uint, matchFound bool)
- func (hybrid Hybrid) BufferNumBits() uint
- func (hybrid *Hybrid) Clear()
- func (hybrid *Hybrid) CommitBulkRead(length uint)
- func (hybrid *Hybrid) CommitBulkWrite(length uint)
- func (hybrid Hybrid) DebugString() string
- func (hybrid Hybrid) GoString() string
- func (hybrid Hybrid) HashNumBits() uint
- func (hybrid *Hybrid) Init(o HybridOptions)
- func (hybrid Hybrid) IsEmpty() bool
- func (hybrid Hybrid) IsFull() bool
- func (hybrid Hybrid) Len() uint
- func (hybrid Hybrid) Options() HybridOptions
- func (hybrid *Hybrid) PrepareBulkRead(length uint) []byte
- func (hybrid *Hybrid) PrepareBulkWrite(length uint) []byte
- func (hybrid *Hybrid) Read(data []byte) (int, error)
- func (hybrid *Hybrid) ReadByte() (byte, error)
- func (hybrid *Hybrid) SetWindow(data []byte)
- func (hybrid Hybrid) String() string
- func (hybrid *Hybrid) WindowClear()
- func (hybrid Hybrid) WindowNumBits() uint
- func (hybrid *Hybrid) Write(data []byte) (int, error)
- func (hybrid *Hybrid) WriteByte(ch byte) error
- type HybridOptions
- type Window
- func (window Window) Bytes() []byte
- func (window Window) BytesView() []byte
- func (window *Window) Clear()
- func (window *Window) CommitBulkWrite(length uint)
- func (window Window) DebugString() string
- func (window Window) GoString() string
- func (window Window) Hash(hashes ...hash.Hash)
- func (window Window) Hash32(fn func() hash.Hash32) uint32
- func (window *Window) Init(numBits uint)
- func (window Window) IsZero() bool
- func (window Window) LookupByte(distance uint) (byte, error)
- func (window Window) NumBits() uint
- func (window *Window) PrepareBulkWrite(length uint) []byte
- func (window Window) Size() uint
- func (window Window) String() string
- func (window *Window) Write(data []byte) (int, error)
- func (window *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 byte buffer. The 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 ¶
DebugString returns a detailed dump of the Buffer's internal state.
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) 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 Hybrid ¶
type Hybrid struct {
// contains filtered or unexported fields
}
Hybrid implements a combination Window/Buffer that uses the Window to remember bytes that were recently removed from the Buffer, and that hashes all data that enters the Window so that LZ77-style prefix matching can be made efficient.
func NewHybrid ¶
func NewHybrid(o HybridOptions) *Hybrid
NewHybrid is a convenience function that allocates a Hybrid and calls Init on it.
func (*Hybrid) Advance ¶
Advance moves a slice of bytes from the Hybrid's Buffer to its Window. The nature of the slice depends on the Hybrid's prefix match settings, the contents of the Hybrid's Window, and the contents of the Hybrid's Buffer.
func (Hybrid) BufferNumBits ¶
BufferNumBits returns the size of the Buffer in bits.
func (*Hybrid) 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 (*Hybrid) 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 (Hybrid) DebugString ¶
DebugString returns a detailed dump of the Hybrid's internal state.
func (Hybrid) HashNumBits ¶
HashNumBits returns the size of the hash function output in bits.
func (Hybrid) Options ¶
func (hybrid Hybrid) Options() HybridOptions
Options returns a HybridOptions struct which can be used to construct a new Hybrid with the same settings.
func (*Hybrid) PrepareBulkRead ¶
PrepareBulkRead obtains a slice from which the caller can read bytes. See Buffer.PrepareBulkRead for more details.
func (*Hybrid) PrepareBulkWrite ¶
PrepareBulkWrite obtains a slice into which the caller can write bytes. See Buffer.PrepareBulkWrite for more details.
func (*Hybrid) Read ¶
Read reads a slice of bytes from the Hybrid's Buffer. If the buffer is empty, ErrEmpty is returned.
func (*Hybrid) WindowClear ¶
func (hybrid *Hybrid) WindowClear()
WindowClear clears just the data in the Hybrid's Window.
func (Hybrid) WindowNumBits ¶
WindowNumBits returns the size of the Window in bits.
type HybridOptions ¶
type HybridOptions struct { BufferNumBits uint WindowNumBits uint HashNumBits uint MinMatchLength uint MaxMatchLength uint MaxMatchDistance uint HasMinMatchLength bool HasMaxMatchLength bool HasMaxMatchDistance bool }
HybridOptions holds options for initializing an instance of Hybrid.
func (HybridOptions) Equal ¶
func (opts HybridOptions) Equal(other HybridOptions) bool
Equal returns true iff the given HybridOptions is semantically equal to this one.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window implements a sliding window. The Window has space for 2**N bytes for user-specified N.
func (Window) BytesView ¶
BytesView returns a slice into the Window's contents.
The returned slice is only valid until the next call to any mutating method on this Window; mutating methods are those which take a pointer receiver.
func (*Window) 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 (Window) DebugString ¶
DebugString returns a detailed dump of the Window's internal state.
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.Size() representing the oldest byte still within the Window.
func (*Window) PrepareBulkWrite ¶
PrepareBulkWrite obtains a slice into which the caller can write bytes. The bytes do not become a part of the Window'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, if the provided length is greater than the size of the Window. The caller must check the slice's length before using it.
The returned slice is only valid until the next call to any mutating method on this Window; mutating methods are those which take a pointer receiver.