Skip to content

Instantly share code, notes, and snippets.

@codethereforam
Created August 21, 2019 10:09
Show Gist options
  • Save codethereforam/d5df20c8b6554c937fd1bd69c2f9b98d to your computer and use it in GitHub Desktop.
Save codethereforam/d5df20c8b6554c937fd1bd69c2f9b98d to your computer and use it in GitHub Desktop.
字符串哈希取余
/**
* 哈希取余
*
* @param key 要处理的字符串
* @param prime 质数
* @return 余数([0, prime - 1]中的整数)
* @author yanganyu
* @date 2019/7/17 10:02
*/
public static int hashcodeMod(String key, int prime) {
Objects.requireNonNull(key);
return Math.abs(key.hashCode() % prime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment