github.com/searKing/golang/go@v1.2.74/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  //          (0 is the first repetition)
    12  // @return The key that represents the specific repetition of the node, such as “127.0.0.1:11311-0”
    13  func (c *NodeLocator) getIterateKeyForNode(node Node, repetition int) string {
    14  	return c.nodeKeyFormatter.getKeyForNode(node, repetition)
    15  }
    16  
    17  func (c *NodeLocator) getIterateHashKeyForNode(node Node, repetition int) []uint32 {
    18  	return c.hashAlg.Hash(c.getIterateKeyForNode(node, repetition))
    19  }
    20  
    21  // 127.0.0.1:11311-0 -> 1122334455
    22  // IterateKey -> IterateHashKey
    23  func (c *NodeLocator) getHashKey(iterateKey string) uint32 {
    24  	return c.hashAlg.Hash(iterateKey)[0]
    25  }