【发布时间】:2014-11-28 20:11:52
【问题描述】:
我正在尝试实现空间散列,并且正在使用来自Optimized Spatial Hashing for Collision Detection of Deformable Objects、hash(x, y, z) = (x p1 xor y p2 xor z p3) mod n 的散列函数,其中 n 是散列表中的桶数。
我的哈希函数代码是:
int SpatialHash::hash(int x, int y, int z)
{
return (((x * P1) ^ (y * P2) ^ (z * P3)) % TABLE_SIZE);
}
有定义:
#define P1 73856093
#define P2 19349663
#define P3 83492791
#define TABLE_SIZE 2000
我只是尝试遍历元素列表,当我尝试将顶点 1、-1、0 放入表中时,它给了我一个 -196 的索引。我的哈希函数是不是在某个地方搞砸了?
【问题讨论】:
标签: c++ hashtable collision-detection