- #1
- 1,231
- 0
I need a hashtable, but I can't seem to figure out how Java's Hashtable or HashMap classes are supposed to work. The keys in these classes are objects, not numbers. How does that even work? The only thing I can think is that the addresses of the keys (which are objects) are mapped to integer hash keys, which is not what I want at all. The problem is that I have a load of Comparable objects and I want to check to see if I've already used one of them, based on the compareTo method for the objects. What I optimally want is something like this:
--I associate a number to each of my objects, which are equal iff one object equals() the other. I do not worry about the suitability of such numbers for hash keys--in particular I don't want to worry about the range of keys.
--something in the Java library produces good hash keys based on these numbers (not on the addresses of Integers containing the numbers) and uses those keys to index my objects in a hash table
I would like to just feed the hash table Integers containing the essential information about the objects and have it do the rest for me, but since the hash table accepts general objects, I'm worried that it won't index the Integers by their contents.
--I associate a number to each of my objects, which are equal iff one object equals() the other. I do not worry about the suitability of such numbers for hash keys--in particular I don't want to worry about the range of keys.
--something in the Java library produces good hash keys based on these numbers (not on the addresses of Integers containing the numbers) and uses those keys to index my objects in a hash table
I would like to just feed the hash table Integers containing the essential information about the objects and have it do the rest for me, but since the hash table accepts general objects, I'm worried that it won't index the Integers by their contents.