0
두 개의 double 값 (x, y)으로 표현되는 좌표 쌍을 Hilbert 값으로 변환하고 싶습니다.더블 좌표에서 힐버트 인덱스를 계산하는 방법은 무엇입니까?
/*****************************************************************
* hilbert_c2i
*
* Convert coordinates of a point on a Hilbert curve to its index.
* Inputs:
* nDims: Number of coordinates.
* nBits: Number of bits/coordinate.
* coord: Array of n nBits-bit coordinates.
* Outputs:
* index: Output index value. nDims*nBits bits.
* Assumptions:
* nDims*nBits <= (sizeof bitmask_t) * (bits_per_byte)
*/
bitmask_t
hilbert_c2i(unsigned nDims, unsigned nBits, bitmask_t const coord[])
{
if (nDims > 1)
{
unsigned const nDimsBits = nDims*nBits;
bitmask_t index;
unsigned d;
bitmask_t coords = 0;
for (d = nDims; d--;)
{
coords <<= nBits;
coords |= coord[d];
}
if (nBits > 1)
{
halfmask_t const ndOnes = ones(halfmask_t,nDims);
halfmask_t const nd1Ones= ndOnes >> 1; /* for adjust_rotation */
unsigned b = nDimsBits;
unsigned rotation = 0;
halfmask_t flipBit = 0;
bitmask_t const nthbits = ones(bitmask_t,nDimsBits)/ndOnes;
coords = bitTranspose(nDims, nBits, coords);
coords ^= coords >> nDims;
index = 0;
do
{
halfmask_t bits = (coords >> (b-=nDims)) & ndOnes;
bits = rotateRight(flipBit^bits, rotation, nDims);
index <<= nDims;
index |= bits;
flipBit = (halfmask_t)1 << rotation;
adjust_rotation(rotation,nDims,bits);
} while (b);
index ^= nthbits >> 1;
}
else
index = coords;
for (d = 1; d < nDimsBits; d *= 2)
index ^= index >> d;
return index;
}
else
return coord[0];
}
그러나,이 입력으로 정수 값이고 : I는 다음의 구현 (from this link)를 발견 하였다. 내 이중 값에 대한 적응은 어떻게 될 것입니까?
아키텍처가 [double]에 대해 [IEEE 754 Binary64] (https://en.wikipedia.org/wiki/IEEE_floating_point#Basic_and_change_formats) 유형을 사용하고 'double'에 대해 동일한 바이트 순서가 ' uint64_t' 정수형 - 이것은 예를 들어 x86-64 아키텍쳐 (64-bit Intel/AMD) - 그리고 여러분의'double '모두 유한 값을 가지고 있다면,'double'의 저장 공간을'uint64_t'에 복사하고, 266 = 9,223,372,036854775808, 결과를 부호없는 64 비트 정수로 사용하십시오. 이 맵핑은 모든 유한 값의 순서를 유지하며 역 (double)으로 되돌릴 수 있습니다. –
@NominalAnimal 제안 해 주셔서 감사합니다. 따라서이 변환을 제안하고 변경없이 함수를 호출 할 것입니다? 내 이중 값도 음수 일 수 있습니다. 또한, 나는 반환 값으로 이중 값을 얻을 필요가있다. –