Documentation ¶
Overview ¶
Package util provides utilities used throughout leveldb.
Index ¶
- Constants
- Variables
- func Hash(data []byte, seed uint32) uint32
- type BasicReleaser
- type Buffer
- func (b *Buffer) Alloc(n int) []byte
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Grow(n int)
- func (b *Buffer) Len() int
- func (b *Buffer) Next(n int) []byte
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (b *Buffer) ReadByte() (c byte, err error)
- func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)
- func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)
- func (b *Buffer) Reset()
- func (b *Buffer) String() string
- func (b *Buffer) Truncate(n int)
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteByte(c byte) error
- func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)
- type BufferPool
- type CRC
- type NoopReleaser
- type Range
- type ReleaseSetter
- type Releaser
Constants ¶
const MinRead = 512
MinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, ReadFrom will not grow the underlying buffer.
Variables ¶
var ( ErrReleased = errors.New("leveldb: resource already relesed") ErrHasReleaser = errors.New("leveldb: releaser already defined") )
Functions ¶
Types ¶
type BasicReleaser ¶
type BasicReleaser struct {
// contains filtered or unexported fields
}
BasicReleaser provides basic implementation of Releaser and ReleaseSetter.
func (*BasicReleaser) Release ¶
func (r *BasicReleaser) Release()
Release implements Releaser.Release.
func (*BasicReleaser) Released ¶
func (r *BasicReleaser) Released() bool
Released returns whether Release method already called.
func (*BasicReleaser) SetReleaser ¶
func (r *BasicReleaser) SetReleaser(releaser Releaser)
SetReleaser implements ReleaseSetter.SetReleaser.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.
func NewBuffer ¶
NewBuffer creates and initializes a new Buffer using buf as its initial contents. It is intended to prepare a Buffer to read existing data. It can also be used to size the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func (*Buffer) Alloc ¶
Alloc allocs n bytes of slice from the buffer, growing the buffer as needed. If n is negative, Alloc will panic. If the buffer can't grow it will panic with bytes.ErrTooLarge.
func (*Buffer) Bytes ¶
Bytes returns a slice of the contents of the unread portion of the buffer; len(b.Bytes()) == b.Len(). If the caller changes the contents of the returned slice, the contents of the buffer will change provided there are no intervening method calls on the Buffer.
func (*Buffer) Grow ¶
Grow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with bytes.ErrTooLarge.
func (*Buffer) Len ¶
Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).
func (*Buffer) Next ¶
Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
func (*Buffer) Read ¶
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (*Buffer) ReadByte ¶
ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.
func (*Buffer) ReadBytes ¶
ReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim.
func (*Buffer) ReadFrom ¶
ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with bytes.ErrTooLarge.
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset resets the buffer so it has no content. b.Reset() is the same as b.Truncate(0).
func (*Buffer) String ¶
String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".
func (*Buffer) Truncate ¶
Truncate discards all but the first n unread bytes from the buffer. It panics if n is negative or greater than the length of the buffer.
func (*Buffer) Write ¶
Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with bytes.ErrTooLarge.
func (*Buffer) WriteByte ¶
WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with bytes.ErrTooLarge.
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool is a 'buffer pool'.
func NewBufferPool ¶
func NewBufferPool(baseline int) *BufferPool
NewBufferPool creates a new initialized 'buffer pool'.
func (*BufferPool) Close ¶
func (p *BufferPool) Close()
func (*BufferPool) Get ¶
func (p *BufferPool) Get(n int) []byte
Get returns buffer with length of n.
func (*BufferPool) String ¶
func (p *BufferPool) String() string
type NoopReleaser ¶
type NoopReleaser struct{}
func (NoopReleaser) Release ¶
func (NoopReleaser) Release()
type Range ¶
type Range struct { // Start of the key range, include in the range. Start []byte // Limit of the key range, not include in the range. Limit []byte }
Range is a key range.
func BytesPrefix ¶
BytesPrefix returns key range that satisfy the given prefix. This only applicable for the standard 'bytes comparer'.
type ReleaseSetter ¶
type ReleaseSetter interface { // SetReleaser associates the given releaser to the resources. The // releaser will be called once coresponding resources released. // Calling SetReleaser with nil will clear the releaser. // // This will panic if a releaser already present or coresponding // resource is already released. Releaser should be cleared first // before assigned a new one. SetReleaser(releaser Releaser) }
ReleaseSetter is the interface that wraps the basic SetReleaser method.