• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I implement my custom HashMap  RSS feed

 
Kousik Majumder
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can somebody tell me (with code) how can I implement my custom HashMap assuming that JDK has NO HashMap.
I have gone through the HashMap implementation itself , but it is too complex.
Please help.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a simpler HashMap you'll have to leave out features. So: what do you consider superfluous for your implementation?
 
Kousik Majumder
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I implement it using 2D array?
If so how to implement hashcode and bucket etc.?
Need some code reference.
Thanks for your quick reply.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kousik Majumder wrote:Can I implement it using 2D array?

That wouldn't be my choice, unless one of the requirements was that there would be a fixed number of entries in the map.
If so how to implement hashcode and bucket etc.?

Normally it's the object being used as the key which implements hashCode(). Were you considering this as one of the "complexities" which you planned to remove? As for how to implement buckets, you would do that by writing some kind of Java code. I certainly wouldn't think a 2-dimensional array would be at all helpful there.
Need some code reference.

Code for what? You don't have any requirements yet. At least not that we can see... the single word "custom" doesn't tell us much about what you plan to do.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, make sure you understand how hash tables work. If you understand that, then reading the source code of HashMap or implementing your own should not be too complex. (That Wikipedia article contains a lot of details - if you want something less elaborate I'm sure you can find easier tutorials about hash tables on the web).
 
nithin chinni
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well I doubt if you can create your own hashcode because its related to pointers and I am afraid that we can not explicity handle pointers as java is pass by value.
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hash tables are completely unrelated to pointers. You don't need direct access to memory to implement one.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!