sharding

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2021 License: MIT Imports: 2 Imported by: 0

README

github.com/gbkr-com/sharding

Sharding implements a scheme to map a key into its equivalent shard index. The key may be a byte slice or an already computed uint64 hash.

Documentation

Index

Constants

View Source
const BadScheme = "sharding: uninitialised scheme"

BadScheme is the panic message for a Scheme that was not created with the New function.

Variables

View Source
var ErrBadSchemeParameter = errors.New("sharding: bad scheme parameter")

ErrBadSchemeParameter is returned when a scheme is badly defined.

Functions

This section is empty.

Types

type Scheme

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

Scheme is a sharding scheme for a specific number of shards, N. A scheme returns the index, [0, N), to a shard given a byte slice (see WithBytes) or a raw hash value (see WithHash). The implementation uses bit masking, so the number of shards must be a power of two.

func New

func New(n uint64) (*Scheme, error)

New returns a sharding scheme for the given number of shards. That number must be a power of two.

func (*Scheme) WithBytes

func (s *Scheme) WithBytes(key []byte) (i int)

WithBytes returns the shard index for the given bytes.

func (*Scheme) WithHash

func (s *Scheme) WithHash(key uint64) int

WithHash returns the shard index for the given hash key.

Jump to

Keyboard shortcuts

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