Created
August 21, 2019 10:09
-
-
Save codethereforam/d5df20c8b6554c937fd1bd69c2f9b98d to your computer and use it in GitHub Desktop.
字符串哈希取余
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
/** | |
* 哈希取余 | |
* | |
* @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