-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use doublejump to replace google jump algorithm
- Loading branch information
Showing
4 changed files
with
30 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,14 +36,18 @@ type HashServiceAndArgs func(len int, options ...interface{}) int | |
// Return service address, like "[email protected]:8970" | ||
type ConsistentAddrStrFunction func(options ...interface{}) string | ||
|
||
// JumpConsistentHash selects a server by serviceMethod and args | ||
func JumpConsistentHash(len int, options ...interface{}) int { | ||
func genKey(options ...interface{}) uint64 { | ||
keyString := "" | ||
for _, opt := range options { | ||
keyString = keyString + "/" + toString(opt) | ||
} | ||
key := HashString(keyString) | ||
return int(Hash(key, int32(len))) | ||
|
||
return HashString(keyString) | ||
} | ||
|
||
// JumpConsistentHash selects a server by serviceMethod and args | ||
func JumpConsistentHash(len int, options ...interface{}) int { | ||
return int(Hash(genKey(options...), int32(len))) | ||
} | ||
|
||
func toString(obj interface{}) string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters