sharder

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hasher added in v0.0.42

type Hasher interface {
	Hash(key string) uint32
}

Hasher is the common interface to hash a given key.

type Opt added in v0.0.42

type Opt func(*Sharder)

Opt is used to customer the Sharder's Hasher.

func WithHasher added in v0.0.42

func WithHasher(f Hasher) Opt

WithHasher allows for custom Hasher implementations.

func WithLockFreeHasher added in v0.0.42

func WithLockFreeHasher() Opt

WithLockFreeHasher implements the Hasher interface using lock-free fnv32.

func WithLockingHasher added in v0.0.42

func WithLockingHasher() Opt

WithLockingHasher is the default Hasher, implemented using a locking fnv32 algorithm.

type Sharder

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

Sharder determines the shard number for a key.

func New

func New(total int, opts ...Opt) *Sharder

New returns a new Sharder with the specified number of shards.

func (*Sharder) Index

func (s *Sharder) Index(key string) int

Index returns a shard index for the given key. The index is in the range 0..total exclusive.

Jump to

Keyboard shortcuts

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