Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: hash question
|
Posted: Jun 1, 2004 5:42 PM
|
|
|
Your bin could be an array of Lists of the size specified as the bin size. So a bin size of 7 would be an array of 7 Lists. You could get the hashCode() of the key object, modulo by the bin size (7) and store the key and its value object (in an Item object of your own making, probably) in the List[/i] at that index. Only if it's not already in the list, of course. Naturally, you should make the bin size a variable, rather than hard-coded to 7. You'll find that "real" implementations of hash tables will adjust the size of the bin, based on the size of the collection -- as it grows, they'll create a new, bigger bin and move all the objects into the new bin. You'll want to have your hash table implement ][i]java.util.Dictio[/b] interface, which will provide additional guidance as to how to proceed.
|
|