Documentation ¶
Index ¶
- Variables
- type Consistent
- func (c *Consistent[M]) Add(elt M)
- func (c *Consistent[M]) Get(name string) (res M, err error)
- func (c *Consistent[M]) GetN(name string, n int) (res []M, err error)
- func (c *Consistent[M]) GetTwo(name string) (a M, b M, err error)
- func (c *Consistent[M]) Members() []string
- func (c *Consistent[M]) Remove(elt M)
- func (c *Consistent[M]) Set(elts []M)
- type Member
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyCircle = errors.New("empty circle")
ErrEmptyCircle is the error returned when trying to get an element when nothing has been added to hash.
Functions ¶
This section is empty.
Types ¶
type Consistent ¶
type Consistent[M Member] struct { NumberOfReplicas int UseFnv bool sync.RWMutex // contains filtered or unexported fields }
Consistent holds the information about the members of the consistent hash circle.
func New ¶
func New[M Member]() *Consistent[M]
New creates a new Consistent object with a default setting of 20 replicas for each entry.
To change the number of replicas, set NumberOfReplicas before adding entries.
func (*Consistent[M]) Add ¶
func (c *Consistent[M]) Add(elt M)
Add inserts a string element in the consistent hash.
func (*Consistent[M]) Get ¶
func (c *Consistent[M]) Get(name string) (res M, err error)
Get returns an element close to where name hashes to in the circle.
func (*Consistent[M]) GetN ¶
func (c *Consistent[M]) GetN(name string, n int) (res []M, err error)
GetN returns the N closest distinct elements to the name input in the circle.
func (*Consistent[M]) GetTwo ¶
func (c *Consistent[M]) GetTwo(name string) (a M, b M, err error)
GetTwo returns the two closest distinct elements to the name input in the circle.
func (*Consistent[M]) Members ¶
func (c *Consistent[M]) Members() []string
func (*Consistent[M]) Remove ¶
func (c *Consistent[M]) Remove(elt M)
Remove removes an element from the hash.
func (*Consistent[M]) Set ¶
func (c *Consistent[M]) Set(elts []M)
Set sets all the elements in the hash. If there are existing elements not present in elts, they will be removed.