| Author |
overriding hashCode() for 3d point sets
|
Graham Cole
Greenhorn
Joined: Sep 14, 2005
Posts: 4
|
|
This is my first post on this site. I hope it is in the right category. If it is not, please tell me where I should be posting. Anyways, I am working on a project in which I am storing massive amounts of 3d points as objects that I call "Position." Keep in mind, this is my first forey (sp?) into the world of Java. So as part of storing these points, I am hoping to find a way to generate unique hash codes for them so I can have random access into the array which holds them. I need this because as I store new points I have to look through the list to see if it has already been created and set my pointers accordingly if it has or hasn't been. I'm not sure if this makes sense, or if I'm completely barking up the wrong tree with this hashcode business, but any help that anyone can give me would be awesome. In short, it would be nice to create a new point in 3d space, calculate its hashCode() and then look up that place in my Map or List and create the proper references if it exists, or add it to the end if it doesn't. thank you all for the help, graham
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Graham Cole: ...I am hoping to find a way to generate unique hash codes...
Note that hashCodes are not necessarily unique. Unequal objects can return the same hashCode, although efficient hashing keeps these "collisions" to a minimum. With that in mind, you could do something like... x*10000 + y*100 + z Then, for example, if you have a point 39, 3, 17, its hashCode would be 390317. If your coordinates cover a larger range, you can scale them... (x%100)*10000 + (y%100)*100 + (z%100) PS: Welcome to JavaRanch! [ September 14, 2005: Message edited by: marc weber ]
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Rick O'Shay
Ranch Hand
Joined: Sep 19, 2004
Posts: 531
|
|
You have several competing statements there. You mention arrays, then fixing up pointers which implies a linked list, then lookups based on hash values which implies a map. I think you really need to design your data structure then select the best fit from the Java collections package. You are putting the cart before the horse with hash codes. Define your data structure (e.g., triples with floating point coordinates in a linked list) then describe the operations you want to perform. [ September 14, 2005: Message edited by: Rick O'Shay ]
|
 |
Graham Cole
Greenhorn
Joined: Sep 14, 2005
Posts: 4
|
|
|
When I say "pointers" its for lack of a better way to describe the unsightly way that java throws references around like they're condoms at a sex party. I would give my right arm is C could have the cross platform compatability that java has. Anyways, thank you guys very much for the help, I think that the linear combination of the coordinates combined with a map may do it.
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Graham Cole: ...the unsightly way that java throws references around like they're condoms at a sex party...
What's a "sex party"? Does it support multiple inheritance?
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: overriding hashCode() for 3d point sets
|
|
|