goleveldb: github.com/syndtr/goleveldb/leveldb/util Index | Files

package util

import "github.com/syndtr/goleveldb/leveldb/util"

Package util provides utilities used throughout leveldb.

Index

Package Files

buffer.go buffer_pool.go crc32.go hash.go range.go util.go

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")
)

func Hash Uses

func Hash(data []byte, seed uint32) uint32

Hash return hash of the given data.

type BasicReleaser Uses

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

BasicReleaser provides basic implementation of Releaser and ReleaseSetter.

func (*BasicReleaser) Release Uses

func (r *BasicReleaser) Release()

Release implements Releaser.Release.

func (*BasicReleaser) Released Uses

func (r *BasicReleaser) Released() bool

Released returns whether Release method already called.

func (*BasicReleaser) SetReleaser Uses

func (r *BasicReleaser) SetReleaser(releaser Releaser)

SetReleaser implements ReleaseSetter.SetReleaser.

type Buffer Uses

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 Uses

func NewBuffer(buf []byte) *Buffer

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 Uses

func (b *Buffer) Alloc(n int) []byte

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 Uses

func (b *Buffer) Bytes() []byte

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 Uses

func (b *Buffer) Grow(n int)

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 Uses

func (b *Buffer) Len() int

Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).

func (*Buffer) Next Uses

func (b *Buffer) Next(n int) []byte

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 Uses

func (b *Buffer) Read(p []byte) (n int, err error)

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 Uses

func (b *Buffer) ReadByte() (c byte, err error)

ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.

func (*Buffer) ReadBytes Uses

func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)

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 Uses

func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

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 Uses

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 Uses

func (b *Buffer) String() 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 Uses

func (b *Buffer) Truncate(n int)

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 Uses

func (b *Buffer) Write(p []byte) (n int, err error)

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 Uses

func (b *Buffer) WriteByte(c byte) error

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.

func (*Buffer) WriteTo Uses

func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned.

type BufferPool Uses

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

BufferPool is a 'buffer pool'.

func NewBufferPool Uses

func NewBufferPool(baseline int) *BufferPool

NewBufferPool creates a new initialized 'buffer pool'.

func (*BufferPool) Close Uses

func (p *BufferPool) Close()

func (*BufferPool) Get Uses

func (p *BufferPool) Get(n int) []byte

Get returns buffer with length of n.

func (*BufferPool) Put Uses

func (p *BufferPool) Put(b []byte)

Put adds given buffer to the pool.

func (*BufferPool) String Uses

func (p *BufferPool) String() string

type CRC Uses

type CRC uint32

CRC is a CRC-32 checksum computed using Castagnoli's polynomial.

func NewCRC Uses

func NewCRC(b []byte) CRC

NewCRC creates a new crc based on the given bytes.

func (CRC) Update Uses

func (c CRC) Update(b []byte) CRC

Update updates the crc with the given bytes.

func (CRC) Value Uses

func (c CRC) Value() uint32

Value returns a masked crc.

type NoopReleaser Uses

type NoopReleaser struct{}

func (NoopReleaser) Release Uses

func (NoopReleaser) Release()

type Range Uses

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 Uses

func BytesPrefix(prefix []byte) *Range

BytesPrefix returns key range that satisfy the given prefix. This only applicable for the standard 'bytes comparer'.

type ReleaseSetter Uses

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.

type Releaser Uses

type Releaser interface {
    // Release releases associated resources. Release should always success
    // and can be called multiple times without causing error.
    Release()
}

Releaser is the interface that wraps the basic Release method.

Package util imports 9 packages (graph) and is imported by 1495 packages. Updated 2019-02-26. Refresh now. Tools for package owners.