Based on the ID of the module shard, in the big data storage when used to,
The following is the modulo code:
public static void Main (string[] args) {
//modulo method one for
(int i = 0; i < 10000; i++) {
//Fetch hash
String key = String.valueof (i);
Long value = long.valueof (Key.hashcode ());
int hash= (int) (value ^ (value >>>));
int index=hash%10;
SYSTEM.OUT.PRINTLN (index);
}
Modulo method two for
(int i = 0; i < 10000; i++) {
//Fetch hash
String key = string.valueof (i);
A power square (2,8,16,32)
int queuesize = 8 with a quantity of 2;
int h;
int hash = (key = = null)? 0: (H = key.hashcode ()) ^ (h >>> +);
int index = (queueSize-1) & hash;
SYSTEM.OUT.PRINTLN (index);
}
}
PS: The above with two methods to take the mold, after testing can be used, the first method is divided into 10 parts according to the number of storage, the second method is divided into 8 parts according to the number of storage,
Index is the corresponding slice index, whether it is a database or queue, cache, etc., can be used.
The reason why Hashcode is taken in the above code is because the data type is not deterministic, so we take hashcode to calculate