Код: Выделить всё
// Cell position
struct Cell
{
Cell(int32 px, int32 py, int32 pz)
{
x = px; y = py; z = pz;
}
int32 x, y, z;
};
#define NUM_BUCKETS 1024
// Computes hash bucket index in range [0, NUM_BUCKETS-1]
int32 ComputeHashBucketIndex(Cell cellPos)
{
const int32 h1 = 0x8da6b343; // Large multiplicative constants;
const int32 h2 = 0xd8163841; // here arbitrarily chosen primes
const int32 h3 = 0xcb1ab31f;
int32 n = h1 * cellPos.x + h2 * cellPos.y + h3 * cellPos.z;
n = n % NUM_BUCKETS;
if (n < 0)
{
n += NUM_BUCKETS;
}
return n;
}
где i, j : >= 0 &&
Подробнее здесь: https://stackoverflow.com/questions/784 ... ion-for-2d
Мобильная версия