consistenthasing

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Copyright (c) 2017-2018 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNodeIDExists indicates a duplicated node was added to the ring
	ErrNodeIDExists = errors.New("Node with same id already exists")
)

Functions

This section is empty.

Types

type Node

type Node struct {
	ID     string
	HashID uint32
}

Node is a node in hash ring

func NewNode

func NewNode(id string) *Node

NewNode returns a new node

type Nodes

type Nodes []Node

Nodes is a slice of nodes

func (Nodes) Len

func (n Nodes) Len() int

Len is for sorting nodes

func (Nodes) Less

func (n Nodes) Less(i, j int) bool

Less is for sorting nodes

func (Nodes) Swap

func (n Nodes) Swap(i, j int)

Swap is for sorting nodes

type Ring

type Ring struct {
	Nodes Nodes
	// contains filtered or unexported fields
}

Ring is a hashring

func NewRing

func NewRing() *Ring

NewRing returns a new ring

func (*Ring) AddNode

func (r *Ring) AddNode(id string) error

AddNode adds a new node

func (*Ring) Get

func (r *Ring) Get(key string) (int, string)

Get node id given key

Jump to

Keyboard shortcuts

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