10.4.3. Hash Code Calculation Rules for Clients
When clients receive the base hash code of a server, it must be normalized to locate the exact position on the hash wheel. This normalization process includes:
- Passing the base hash code to the hash function.
- Calculations to avoid negative values.
public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) {
return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE;
}
public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) {
return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE;
}
Each node represents N different virtual modes. Therefore, to calculate the hash code for each virtual node, use the numbers between 0 and N-1 and apply the following process:
Procedure 10.1. Hash Code Calculation with Virtual Nodes
- For the virtual node with the ID "0", use the following code to obtain the hash code:
public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) { return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE; }public static int getNormalizedHash(int nodeBaseHashCode, Hash hashFct) { return hashFct.hash(nodeBaseHashCode) & Integer.MAX_VALUE; }Copy to Clipboard Copied! Toggle word wrap Toggle overflow - For all subsequent virtual nodes (with IDs from "1" to "N-1"), execute the following code:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow