github.com/searKing/golang/go@v1.2.117/container/hashring/hashring.options.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  func WithNumberNodeRepetitions(n int) NodeLocatorOption {
     8  	return KetamaNodeLocatorOptionFunc(func(l *NodeLocator) {
     9  		l.numReps = n
    10  	})
    11  }
    12  
    13  func WithHashAlg(hashAlg HashAlgorithm) NodeLocatorOption {
    14  	return KetamaNodeLocatorOptionFunc(func(l *NodeLocator) {
    15  		l.hashAlg = hashAlg
    16  	})
    17  }
    18  
    19  func WithFormatter(formatter *KetamaNodeKeyFormatter) NodeLocatorOption {
    20  	return KetamaNodeLocatorOptionFunc(func(l *NodeLocator) {
    21  		l.nodeKeyFormatter = formatter
    22  	})
    23  }
    24  
    25  func WithWeights(weights map[Node]int) NodeLocatorOption {
    26  	return KetamaNodeLocatorOptionFunc(func(l *NodeLocator) {
    27  		l.weightByNode = weights
    28  		l.isWeighted = len(weights) > 0
    29  	})
    30  }