util

package
v0.0.0-...-e060e7e Latest Latest
Warning

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

Go to latest
Published: May 25, 2015 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checksum32

func Checksum32(b []byte) uint32

Checksum returns the CRC-32 checksum of data

func SharedPrefix

func SharedPrefix(a, b []byte) int

Returns the largest pos such that a[:pos] equals b[:pos].

Types

type BloomFilter

type BloomFilter []byte

A Bloom Filter is an encoded set of []byte keys.

func (BloomFilter) KeyMayMatch

func (f BloomFilter) KeyMayMatch(key []byte) bool

func (BloomFilter) Name

func (f BloomFilter) Name() string

type BytewiseComparator

type BytewiseComparator struct{}

func (BytewiseComparator) Compare

func (BytewiseComparator) Compare(a, b []byte) int

func (BytewiseComparator) Name

func (BytewiseComparator) Name() string

type Comparator

type Comparator interface {
	// Three-way comparison.  Returns value:
	//   < 0 iff "a" < "b",
	//   == 0 iff "a" == "b",
	//   > 0 iff "a" > "b"
	Compare(a, b []byte) int

	// Name returns the name of the comparator.
	//
	// The Level-DB on-disk format stores the comparator name, and opening a
	// database with a different comparator from the one it was created with
	// will result in an error.
	Name() string
}

Provides a total order across slices that are used as keys in an sstable or a database. A Comparator implementation must be thread-safe since it may be invoked concurrently from multiple threads.

type QueryFilter

type QueryFilter interface {
	// Name of the query filter
	Name() string

	// KeyMayMatch returns whether the filter may contain given key. False positives
	// are possible, where it returns true for keys not in the original set.
	KeyMayMatch(key []byte) bool
}

func NewBloomFilter

func NewBloomFilter(buf []byte, keys [][]byte, bitsPerKey int) QueryFilter

NewBloomFilter returns a new Bloom filter that encodes a set of []byte keys with the given number of bits per key. The returned Filter may be a sub-slice of buf[:cap(buf)] if it is large enough, otherwise the Filter will be allocated separately.

A good value for bits per key is 10, which yields a filter with ~ 1% false positive rate.

Jump to

Keyboard shortcuts

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