0
2つの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];
}
しかし、これは入力として整数値のためのものである:私は、次の実装(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ビットIntel/AMD)であり、すべての 'double'が有限の値を持つならば、' double'のストレージを 'uint64_t'にコピーし、2π³= 9,223,372,036,854,775,808、その結果を符号なし64ビット整数として使用します。このマッピングはすべての有限値の順序を保持し、逆転可能である(「double」に戻る)。 –
@NominalAnimal提案していただきありがとうございます。したがって、私はこの提案された変換を行い、変更することなく関数を呼び出すでしょうか?私の二重の値も負になります。また、私はリターンとしても二重価値を得る必要があります。 –