github.com/searKing/golang/go@v1.2.117/container/hashring/hashring.key.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package hashring 6 7 // Returns a uniquely identifying key, suitable for hashing by the 8 // NodeLocator algorithm. 9 // @param node The Node to use to form the unique identifier 10 // @param repetition The repetition number for the particular node in question 11 // 12 // (0 is the first repetition) 13 // 14 // @return The key that represents the specific repetition of the node, such as “127.0.0.1:11311-0” 15 func (c *NodeLocator) getIterateKeyForNode(node Node, repetition int) string { 16 return c.nodeKeyFormatter.getKeyForNode(node, repetition) 17 } 18 19 func (c *NodeLocator) getIterateHashKeyForNode(node Node, repetition int) []uint32 { 20 return c.hashAlg.Hash(c.getIterateKeyForNode(node, repetition)) 21 } 22 23 // 127.0.0.1:11311-0 -> 1122334455 24 // IterateKey -> IterateHashKey 25 func (c *NodeLocator) getHashKey(iterateKey string) uint32 { 26 return c.hashAlg.Hash(iterateKey)[0] 27 }