util

package
v1.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2016 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package util provides utilities used throughout leveldb.

Index

Constants

View Source
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

View Source
var (
	ErrReleased    = errors.New("leveldb: resource already relesed")
	ErrHasReleaser = errors.New("leveldb: releaser already defined")
)

Functions

func Hash

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

Hash return hash of the given data.

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 added in v0.9.17

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 added in v0.9.17

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

BufferPool is a 'buffer pool'.

func NewBufferPool added in v0.9.17

func NewBufferPool(baseline int) *BufferPool

NewBufferPool creates a new initialized 'buffer pool'.

func (*BufferPool) Close added in v0.9.17

func (p *BufferPool) Close()

func (*BufferPool) Get added in v0.9.17

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

Get returns buffer with length of n.

func (*BufferPool) Put added in v0.9.17

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

Put adds given buffer to the pool.

func (*BufferPool) String added in v0.9.17

func (p *BufferPool) String() string

type CRC

type CRC uint32

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

func NewCRC

func NewCRC(b []byte) CRC

NewCRC creates a new crc based on the given bytes.

func (CRC) Update

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

Update updates the crc with the given bytes.

func (CRC) Value

func (c CRC) Value() uint32

Value returns a masked crc.

type NoopReleaser added in v0.9.17

type NoopReleaser struct{}

func (NoopReleaser) Release added in v0.9.17

func (NoopReleaser) Release()

type Pool added in v0.9.17

type Pool struct {
	sync.Pool
}

func NewPool added in v0.9.17

func NewPool(cap int) *Pool

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 added in v0.9.17

func BytesPrefix(prefix []byte) *Range

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.

type Releaser

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

Releaser is the interface that wraps the basic Release method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL