func (h *hashRing) AddNode(n string, s int) {
	tSpots := h.defaultSpots * s
	hash := sha1.New()
	for i := 1; i <= tSpots; i++ {
		hash.Write([]byte(n + ":" + strconv.Itoa(i)))
		hashBytes := hash.Sum(nil)
		n := &node{
			node: n,
			hash: uint(hashBytes[19]) | uint(hashBytes[18])<<8 | uint(hashBytes[17])<<16 | uint(hashBytes[16])<<24,
		}
		h.ticks = append(h.ticks, *n)
		hash.Reset()
	}
}
Adds a new node to a hash ring
n: name of the server
s: multiplier for default number of ticks (useful when one cache node has more resources, like RAM, than another)
package ketama
import (
	"crypto/sha1"
	"sort"
	"strconv"
)
type node struct {
	node string
	hash uint
}
type tickArray []node
func (p tickArray) Len() int           { return len(p) }
func (p tickArray) Less(i, j int) bool { return p[i].hash < p[j].hash }
func (p tickArray) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p tickArray) Sort()              { sort.Sort(p) }
type hashRing struct {
	defaultSpots int
	ticks        tickArray
	length       int
}
func NewRing(n int) (h *hashRing) {
	h = new(hashRing)
	h.defaultSpots = n
	return
}