Created
July 23, 2023 16:54
-
-
Save normen662/0d312d1424adb70f274d95bb16734aac to your computer and use it in GitHub Desktop.
changes to HilberCurve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static BigInteger toIndex(int bits, long... transposedIndex) { | |
int length = bits * transposedIndex.length; | |
byte[] b = new byte[length / 8 + 1]; | |
int bIndex = length - 1; | |
long mask = 1L << (bits - 1); | |
for (int i = 0; i < bits; i++) { | |
for (int j = 0; j < transposedIndex.length; j++) { | |
if ((transposedIndex[j] & mask) != 0) { | |
b[b.length - 1 - bIndex / 8] |= 1 << (bIndex % 8); | |
} | |
bIndex--; | |
} | |
mask >>>= 1; | |
} | |
// b is expected to be BigEndian | |
return new BigInteger(1, b); | |
} | |
static long[] transposedIndex(int bits, long... unsignedPoint) { | |
final long M = 1L << (bits - 1); | |
final int n = unsignedPoint.length; // n: Number of dimensions | |
final long[] x = Arrays.copyOf(unsignedPoint, n); | |
long p; | |
long q; | |
long t; | |
int i; | |
// Inverse undo | |
for (q = M; q != 1; q >>>= 1) { | |
p = q - 1; | |
for (i = 0; i < n; i++) { | |
if ((x[i] & q) != 0) { | |
x[0] ^= p; // invert | |
} else { | |
t = (x[0] ^ x[i]) & p; | |
x[0] ^= t; | |
x[i] ^= t; | |
} | |
} | |
} // exchange | |
// Gray encode | |
for (i = 1; i < n; i++) { | |
x[i] ^= x[i - 1]; | |
} | |
t = 0; | |
for (q = M; q != 1; q >>>= 1) { | |
if ((x[n - 1] & q) != 0) { | |
t ^= q - 1; | |
} | |
} | |
for (i = 0; i < n; i++) { | |
x[i] ^= t; | |
} | |
return x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment