id hash分桶
1、tensorflow
tf.string_to_hash_bucket()
https://blog.csdn.net/pearl8899/article/details/107958334
2、python
import hashlib
id='test'
bucket_size=4096
id_hash = id.encode('utf-8')
id_hash = int(hashlib.md5(id_hash).hexdigest(), 16) % bucket_size
https://blog.csdn.net/qq_14997473/article/details/81085186
3、java
package chease_base;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class TestMain {
public static String getMD5Str(String str) {
byte[] digest = null;
try {
MessageDigest md5 = MessageDigest.getInstance("md5");
digest = md5.digest(str.getBytes("utf-8"));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 转换为10进制整数
System.out.println(new BigInteger(1, digest));
// 转换为10进制整数字符串
String md5Str = new BigInteger(1, digest).toString(10);
System.out.println("md5Str=" + md5Str);
// 转换为16进制整数字符串
// String md5Str2 = new BigInteger(1, digest).toString(16);
// System.out.println(md5Str2);
// 取mod
BigInteger num = new BigInteger(1, digest);
BigInteger bucket = new BigInteger("7");
System.out.println(String.valueOf(num.mod(bucket)));
return md5Str;
}
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
System.out.println(getMD5Str("awbc"));
}
}