chatgpt-4o-latest-20250326· OpenAI
LMArena Human Preference 140K
Write the JOAAT hash function in Java.
- User
Write the JOAAT hash function in Java.
- Assistant
Sure! The JOAAT hash (Jenkins One At A Time hash) is a non-cryptographic hash function designed by Bob Jenkins. It's simple and fast, making it useful for hash table lookups and similar use cases.
Here's how you can implement the JOAAT hash function in Java:
public class JoaatHash { public static int hash(String input) { byte[] bytes = input.getBytes(); int hash = 0; for (byte b : bytes) { hash += (b & 0xFF); hash += (hash << 10); hash ^= (hash >>> 6); } hash += (hash << 3); hash ^= (hash >>> 11); hash += (hash << 15); // Return as unsigned 32-bit integer representation (wrapped in signed int). return hash; } public static void main(String[] args) { String input = "Hello, world!"; int hashValue = hash(input); System.out.printf("JOAAT hash of \"%s\" is 0x%08X (%d)%n", input, hashValue, hashValue); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.