Last active
February 14, 2025 21:29
-
-
Save apangin/5f9de9c03d4b785b7ff082ecac6e792a to your computer and use it in GitHub Desktop.
Objects.hash alternative capable of allocation elimination
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
public static int hash(String... args) { | |
if (args != null) { | |
switch (args.length) { | |
case 1: | |
return 31 + Objects.hashCode(args[0]); | |
case 2: | |
return 961 + Objects.hashCode(args[0]) * 31 | |
+ Objects.hashCode(args[1]); | |
case 3: | |
return 29791 + Objects.hashCode(args[0]) * 961 | |
+ Objects.hashCode(args[1]) * 31 | |
+ Objects.hashCode(args[2]); | |
} | |
} | |
return Arrays.hashCode(args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment