6 #ifndef TURI_SGRAPH_HILBERT_CURVE_HPP 7 #define TURI_SGRAPH_HILBERT_CURVE_HPP 11 #include <core/logging/assertions.hpp> 12 #include <core/util/bitops.hpp> 32 if (s == 0 && n == 1)
return {0, 0};
37 size_t comp, swap, cs, t, sr;
39 s = s | (0x55555555 << 2*n);
40 sr = (s >> 1) & 0x55555555;
41 cs = ((s & 0x55555555) + sr)
54 swap = cs & 0x55555555;
55 comp = (cs >> 1) & 0x55555555;
57 t = (s & swap) ^ comp;
58 s = s ^ sr ^ t ^ (t << 1);
60 s = s & ((1 << 2*n) - 1);
65 t = (s ^ (s >> 1)) & 0x22222222; s = s ^ t ^ (t << 1);
66 t = (s ^ (s >> 2)) & 0x0C0C0C0C; s = s ^ t ^ (t << 2);
67 t = (s ^ (s >> 4)) & 0x00F000F0; s = s ^ t ^ (t << 4);
68 t = (s ^ (s >> 8)) & 0x0000FF00; s = s ^ t ^ (t << 8);
69 return {s >> 16, s & 0xFFFF};
81 if ((n == 1) && (coord.first == 0) && (coord.second = 0))
return 0;
85 ASSERT_LT(coord.first, n);
86 ASSERT_LT(coord.second, n);
91 size_t x = coord.first;
92 size_t y = coord.second;
96 for (i = n - 1; i >= 0; i--) {
97 row = 4*state | 2*((x >> i) & 1) | ((y >> i) & 1);
98 s = (s << 2) | ((0x361E9CB4 >> 2*row) & 3);
99 state = (0x8FE65831 >> 2*row) & 3;
106 #endif // TURI_SGRAPH_ZORDER_HPP static unsigned int n_trailing_zeros(T v, _ENABLE_IF_UINT(T))
#define ASSERT_TRUE(cond)
static bool is_power_of_2(const T &x, _ENABLE_IF_UINT(T))
size_t coordinate_to_hilbert_index(std::pair< size_t, size_t > coord, size_t n)
std::pair< size_t, size_t > hilbert_index_to_coordinate(size_t s, size_t n)