• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

How can I implement my custom HashMap

 
Kousik Majumder
Ranch Hand
Posts: 244
  • 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: 43016
76
  • 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: 244
  • 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
Marshal
Posts: 26128
77
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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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: 12489
269
  • 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.
 
Why fit in when you were born to stand out? - Seuss. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic