bitbucket

package
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version = 1
)

Variables

View Source
var ErrIncompatibleVersion = errors.New("bitbucket: incompatible version")
View Source
var ErrUnsupportedWidth = errors.New("bitbucket: requested bucket width exceeds maximum of 8")

Functions

func Len

func Len(n int, w uint8) int

Len returns the length of the buffer required to serialize a bit bucket with n buckets each of width w bits.

Types

type BitBucket

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

A BitBucket is a collection of buckets capable of storing values from zero up to maximum specified by the configured number of bits.

func New

func New(n int, w uint8) BitBucket

New creates a new BitBucket with n buckets each consisting of w bits. When w is 1 then the bitbucket is equivalent to a bitset. Panics if w > 8.

func WithBytes

func WithBytes(buf []byte) (BitBucket, error)

WithBytes creates a new bit bucket that uses buf as its backing storage, preserving any existing data in the byte slice. Any subsequent writes to the bloom filter will mutate buf. The layout of the byte buffer must match the layout used by the WriteTo method on an equivalent bit bucket.

func (*BitBucket) Count

func (b *BitBucket) Count() int

Count returns the number of buckets.

func (*BitBucket) CountN

func (b *BitBucket) CountN(v uint8) int

CountN returns the number of buckets that have the value v. TODO: optimize CountN by iterating through raw byte slice

func (*BitBucket) Get

func (b *BitBucket) Get(i int) uint8

Get returns the value stored in bucket i

func (*BitBucket) IncN

func (b *BitBucket) IncN(i int, v uint8)

IncN increments the value stored in bucket i by v, capping the result by the maximum value allowed for the bucket size.

func (*BitBucket) Len

func (b *BitBucket) Len() int

Len returns the length of the buffer required to serialize the bit bucket.

func (*BitBucket) Max

func (b *BitBucket) Max() uint8

Max returns the maximum value that can be stored in a bucket.

func (*BitBucket) ReadFrom

func (b *BitBucket) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads a binary representation of the bit bucket from r overwriting any previous configuration. It adheres to the io.ReaderFrom interface protocol. It reads data from r until EOF or error. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned.

func (*BitBucket) Reset

func (b *BitBucket) Reset()

Reset zeroes all buckets in the bit bucket without reallocating the backing buffer.

func (*BitBucket) Set

func (b *BitBucket) Set(i int, v uint8)

Set sets the value stored in bucket i to v, capping it by the maximum value allowed for the bucket size.

func (*BitBucket) Width

func (b *BitBucket) Width() uint8

Width returns the bit width of the buckets.

func (*BitBucket) WriteTo

func (b *BitBucket) WriteTo(w io.Writer) (int64, error)

WriteTo writes a binary representation of the bit bucket to w. It adheres to the io.WriterTo interface protocol. The return value is the number of bytes written. Any error encountered during the write is also returned.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL