Reputation: 4731
I have an array of 6 ints that I am interested in getting a hash value for (an int). I am wondering if there is a relatively strong and fast hash function for this case which is implemented in Java.
I am almost tempted to convert the 6 ints to a String (as if each int is a unicode character or something like that, not by representing each int as an actual number) and use "hashcode", but it sounds very inefficient to me, I think want something faster. Any ideas?
Thanks.
Upvotes: 0
Views: 5233
Reputation:
int[] myIntArray = {1, 2, 3, 4, 5};
int myHashCode = Arrays.hashCode(myIntArray);
Note: Arrays has hashCode()
implemented for arrays of all primitive types, not just ints.
Also, something tells me you're going to use a sequence of 6 numbers as a passcode, and its hash to match it against. In this case, you're going to want a really, really long hash. Something at least 24 bytes long, instead of the 4 that an int will give you. (having a larger hash space than your input space will reduce collisions.)
I'd go for SHA-384 or higher. And don't forget to salt.
Upvotes: 5