Add adds keys to the ring.
(keys ...string)
| 68 | |
| 69 | // Add adds keys to the ring. |
| 70 | func (ring *Ring) Add(keys ...string) { |
| 71 | for _, key := range keys { |
| 72 | for i := range ring.replicas { |
| 73 | ring.keys = append(ring.keys, elem{ |
| 74 | hash: ring.hashfunc([]byte(strconv.Itoa(i) + key)), |
| 75 | key: key}) |
| 76 | } |
| 77 | } |
| 78 | sort.Sort(sortable(ring.keys)) |
| 79 | |
| 80 | // Calculate signature |
| 81 | hash := fnv.New128a() |
| 82 | b := make([]byte, 4) |
| 83 | for _, key := range ring.keys { |
| 84 | b[0] = byte(key.hash) |
| 85 | b[1] = byte(key.hash >> 8) |
| 86 | b[2] = byte(key.hash >> 16) |
| 87 | b[3] = byte(key.hash >> 24) |
| 88 | hash.Write(b) |
| 89 | hash.Write([]byte(key.key)) |
| 90 | } |
| 91 | |
| 92 | b = []byte{} |
| 93 | b = hash.Sum(b) |
| 94 | dst := make([]byte, ascii85.MaxEncodedLen(len(b))) |
| 95 | ascii85.Encode(dst, b) |
| 96 | ring.signature = string(dst) |
| 97 | } |
| 98 | |
| 99 | // Get returns the closest item in the ring to the provided key. |
| 100 | func (ring *Ring) Get(key string) string { |