How do I find hash value of a 3D vector ?

Started by
13 comments, last by brainydexter 14 years ago
@theFries: Which I think makes up a candidate for a good hash key :) ?
Advertisement
I can't really comment on whether your approach gives good hash values. However, the primary concern when generating hashes should be to minimize hash collisions. This is usually accomplished with a uniform distribution of hash values, e.g. as suggested by thefries.
You guys are blowing this out of proportion. Minimize collisions? Give me a break. The only time you will get a collision with the presented method is when you have two of the same coordinates, or you try to mix and match different grids together.
I'll agree the method I provided isn't a typical hashing function. I did infact say that it is just a method of converting a 3D index into a 1D index.

The reason I suggested it as a solution is because the only time you will get a hash collision is when two objects are in the same grid cell, which is what I understood was wanted. Using this you could now iterate over your hash table and only check for collisions between objects which have the same hash value. Depending on how the hash table is structured it could end up being faster than iterating over all grid cells and testing collisions or iterating over each object, getting the grid cell it is in and then iterating over those.

Of course if this isn't what you wanted to use the hash value for, then you should probably ignore my idea and go for something similar to thefries method. [smile]
@diablos: Nope, this is exactly what I wanted and it is proving out to be quite useful. I've got it working with players already! Time to get the bullets also integrated!!

Thanks for all the comments guys.

This topic is closed to new replies.

Advertisement