Как я могу написать хэш-функцию для 2D?C#

Место общения программистов C#
Anonymous
Как я могу написать хэш-функцию для 2D?

Сообщение Anonymous »

В книге Кристера Эриксона Обнаружение столкновений в реальном времени, стр. 288, рассказывается об 1D-хешировании.

Код: Выделить всё

// 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;
}
Мне нужна хеш-функция, которая будет принимать любую координату (x, y) и преобразовывать индекс двумерной сетки (i, j)
где i, j : >= 0 &&

Подробнее здесь: https://stackoverflow.com/questions/784 ... ion-for-2d

Вернуться в «C#»