func (r *Ring) UpdateLoad(node string, load int64) {
	r.mu.Lock()
	defer r.mu.Unlock()
	if _, ok := r.keyLoadMap[node]; !ok {
		return
	}
	r.totalLoad -= r.keyLoadMap[node].Load
	r.keyLoadMap[node].Load = load
	r.totalLoad += load
}
UpdateLoad sets load of the given node to the given load.
package ringhash
import (
	"errors"
	"hash/crc64"
	"io"
	"math"
	"sort"
	"strconv"
	"sync"
)
type (
	Hash func(key string) uint64
	Node struct {
		Name string
		Load int64
	}
	Ring struct {
		hashFn          Hash
		replicas        int
		balancingFactor float64
		hashKeyMap      map[uint64]string
		hashes          []uint64
		keyLoadMap      map[string]*Node
		totalLoad       int64
		mu sync.RWMutex
	}
	Config struct {
		HashFn          Hash
		Replicas        int
		BalancingFactor float64
	}
	Option = func(*Config) error
)
var (
	hashCRC64 = crc64.New(crc64.MakeTable(crc64.ECMA))
	ErrNoNode = errors.New("no node added")
	ErrNodeNotFound = errors.New("node not found in LoadMap")
	DefaultConfig = Config{
		HashFn:          hash,
		Replicas:        10,
		BalancingFactor: 1.25,
	}
)
func hash(key string) uint64 {
	hashCRC64.Reset()
	_, err := io.WriteString(hashCRC64, key)
	if err != nil {
		panic(err)
	}
	return hashCRC64.Sum64()
}
func New(options ...Option) *Ring {
	c := DefaultConfig
	setOption(&c, options...)
	r := &Ring{
		replicas:        c.Replicas,
		balancingFactor: c.BalancingFactor,
		hashFn:          c.HashFn,
		hashKeyMap:      make(map[uint64]string),
		hashes:          []uint64{},
		keyLoadMap:      map[string]*Node{},
	}
	return r
}
func (r *Ring) IsEmpty() bool {
	return len(r.hashKeyMap) == 0
}
func (r *Ring) AddNode(keys ...string) {
	r.mu.Lock()
	defer r.mu.Unlock()
	for _, key := range keys {
		if _, ok := r.keyLoadMap[key]; ok {
			continue
		}
		r.keyLoadMap[key] = &Node{Name: key, Load: 0}
		for i := 0; i < r.replicas; i++ {
			h := r.hashFn(key + strconv.Itoa(i))
			r.hashes = append(r.hashes, h)
			r.hashKeyMap[h] = key
		}
	}
	sort.Slice(r.hashes, func(i, j int) bool {
		if r.hashes[i] < r.hashes[j] {
			return true
		}
		return false
	})
}
func (r *Ring) GetNode(key string) (string, error) {
	r.mu.RLock()
	defer r.mu.RUnlock()
	if r.IsEmpty() {
		return "", ErrNoNode
	}
	h := r.hashFn(key)
	idx := r.search(h)
	return r.hashKeyMap[r.hashes[idx]], nil
}
func (r *Ring) GetLeastNode(key string) (string, error) {
	r.mu.RLock()
	defer r.mu.RUnlock()
	if r.IsEmpty() {
		return "", ErrNoNode
	}
	h := r.hashFn(key)
	idx := r.search(h)
	i := idx
	var count int
	for {
		count++
		if count >= len(r.hashes) {
			panic("not enough space to distribute load")
		}
		node := r.hashKeyMap[r.hashes[i]]
		if r.loadOK(node) {
			return node, nil
		}
		i++
		if i >= len(r.hashKeyMap) {
			i = 0
		}
	}
}