J
j1mb0jay
I am currently trying to improve up-on my own implementation of a hash
table. Using Java 1.6.
At the moment I am setting the size of the hash table to be the next
prime number which is double the value of the expected number of items to
be added. (Using the Sieve of Atkin prime test)
Each item(Object) that is added has a unique String as a form of ID. I
use the String.hashCode() method on this ID and then Mod this 32bit
integer, so that I then can use this number as an index into the array of
linked lists, that represents the hash table. ( The array of linked lists
is so the hash table can handle collisions ).
I was wondering if instead of using the String.hashCode() method I used a
secure hash, like SHA512 or MD5. Then converted this 512bit / 128bit
number into base10, so that i could parse it as a String into the
constructor of java.math.BigInteger class, then Mod then number by the
size of the hash table so it could be used an index into the array.
Would this mean there would be no collisions thus keeping the time
complexity of the search method down to O(1). In turn meaning the hash
table could be an array of Key Value pairs rather than a array of linked
lists.
Regards j1mb0jay
table. Using Java 1.6.
At the moment I am setting the size of the hash table to be the next
prime number which is double the value of the expected number of items to
be added. (Using the Sieve of Atkin prime test)
Each item(Object) that is added has a unique String as a form of ID. I
use the String.hashCode() method on this ID and then Mod this 32bit
integer, so that I then can use this number as an index into the array of
linked lists, that represents the hash table. ( The array of linked lists
is so the hash table can handle collisions ).
I was wondering if instead of using the String.hashCode() method I used a
secure hash, like SHA512 or MD5. Then converted this 512bit / 128bit
number into base10, so that i could parse it as a String into the
constructor of java.math.BigInteger class, then Mod then number by the
size of the hash table so it could be used an index into the array.
Would this mean there would be no collisions thus keeping the time
complexity of the search method down to O(1). In turn meaning the hash
table could be an array of Key Value pairs rather than a array of linked
lists.
Regards j1mb0jay