GoConsistentHash

package module
v0.0.0-...-4f38dfe Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

GoConsistentHash

Summary

GoConstHash is a Consistent Hashing Ring implementation.

https://en.wikipedia.org/wiki/Consistent_hashing

Groupcache

The code base was originally used as part of Google's Groupcache project. It was forked however, because the project had no intention of maintaining a full-blown consistent hashing library.

Documentation

Overview

Package GoConsistentHash provides an implementation of a ring hash.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptAny

func AcceptAny([]string, string) bool

Accepts any items when used as accept argument in GetN.

func AcceptUnique

func AcceptUnique(stack []string, found string) bool

Accepts only unique items when used as accept argument in GetN.

Types

type EntryValue

type EntryValue interface {
	HashRingId() string
}

type Hash

type Hash func(data []byte) uint32

type Map

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

func New

func New(defaultWeight int, fn Hash) *Map

func (*Map) AddString

func (m *Map) AddString(keys ...string) error

Adds some strings to the hash.

func (*Map) AddStringWithWeight

func (m *Map) AddStringWithWeight(key string, weight int) error

Adds some strings to the hash with a custom weight.

func (*Map) AddWithWeight

func (m *Map) AddWithWeight(entryValue EntryValue, weight int) error

Adds an item to the hash.

func (*Map) Del

func (m *Map) Del(key string) error

func (*Map) Get

func (m *Map) Get(key string) string

Gets the closest item in the hash to the provided key.

func (*Map) GetN

func (m *Map) GetN(key string, n int, accept func([]string, string) bool) []string

Gets the N closest items in the hash to the provided key, if they're permitted by the accept function. This can be used to implement placement strategies like storing items in different availability zones.

The accept function returns a bool to indicate whether the item is acceptable. Its first argument is the items that have already been accepted, the second argument is the item that is about to be selected (if accepted).

The AcceptAny and AcceptUnique functions are provided as utility functions that can be used as accept-callback.

func (*Map) IsEmpty

func (m *Map) IsEmpty() bool

Returns true if there are no items available.

type StringValue

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

func (*StringValue) HashRingId

func (e *StringValue) HashRingId() string

Jump to

Keyboard shortcuts

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