Powered by the "other" java.
Did they really mention Hashtable? They are behind the times. Nobody uses that class any more; they use HashMap instead.Andrew Linton Bradford wrote:. . . implement a bucket hash table structure without using Hashtable.
Yes, algorithms course people like making you build things from scratch (Mwaahaahaahaahaahaahaahaahaahaa!) because it proves you have understood the structure. In twenty years you will still remember how to create a hash table and will understand what has gone wrong with your latest hash table‑using app.They basically want us to build it from scratch . . .
On line 27 you know that list[hash] is populated, it also may have its next reference set. You need to extend the linked list without clobbering any existing links.
Did they really mention Hashtable? They are behind the times. Nobody uses that class any more; they use HashMap instead.
Powered by the "other" java.
Powered by the "other" java.
There are three kinds of actuaries: those who can count, and those who can't.
Powered by the "other" java.
It is easier to implement as an assignment in a data structures course, however.shivkumar singh wrote:. . . It is old method of using Bucket Hash Table .
Powered by the "other" java.
If your "remove()" method is the one called "delete" in the code you posted, then it calls lookup() at line 38 and then (possibly) again at line 40.
And inside your lookup() method...
Why are you using 13 buckets?
Why are you using bytes for the hash code?
Why are you hard‑coding the % operator in the hash code method?...
Why are you using toLowerCase()?
Welcome to the Ranch
Powered by the "other" java.
No. I can't remember what the parameters are, but you should avoid ==. Good summary here.Andrew Linton Bradford wrote:. . .Should I be checking for both == and equals() in the if() parameter list?
Use ints just as you would for any other arithmetic. Presumably you have to calculate a hash code yourself rather than using the method already existing in String. You know you can get the chars out of a String as an array: iterate that array and add each char and multiply each intermediate sum by 31. That will actually give the same result as String#hashCode(). I presume your assignment will permit that technique?. . .
It was my attempt at quickly converting the String to a numerical value. Any suggestions?Why are you using bytes for the hash code?
Breach of the single responsibility principle. The object calculates its hash code; the hash table wants the remainder after division by 13. It is therefore the hash table's responsibility to work out that remainder. Otherwise you will create hash codes which work beautifully for thirteen buckets but won't work at all well when confronted with the more common counts of sixteen/32/64/etc buckets.I was forcing the value to fit within one of the 13 buckets.Why are you hard‑coding the % operator in the hash code method?...
That's a pleasure. . .
Thank you! . . .Welcome to the Ranch
Powered by the "other" java.
That's all right.Andrew Linton Bradford wrote:Campbell,
Sorry for the taking so long to reply. . . .
Good; that sounds correct.I removed all instances of == in my code, except for my comparisons to null. . . . .
That's a pleasureI replaced the hashCode() method with: . . . Thanks again,
Andrew