32 #include <type_traits>
35 namespace energybased {
38 template<
typename IntType,
int Dim>
40 const IntType a[Dim],
const IntType b[Dim]) {
42 for (
int d = Dim - 1; d >= 0; d--) {
52 template<
typename IntType,
int Dim>
54 const IntType b[Dim]) {
59 template<
typename IntType,
int Dim>
61 const IntType b[Dim]) {
62 return a[0] == b[0] && a[1] == b[1];
65 template<
typename IntType,
int Dim>
67 const IntType a[Dim],
const IntType b[Dim]) {
69 for (
int d = Dim - 1; d >= 0; d--) {
79 template<
typename IntType,
int Dim>
81 const unsigned int b[Dim]) {
86 template<
typename IntType,
int Dim>
88 const unsigned int b[Dim]) {
89 return (a[1] == b[1]) ? a[0] < b[0] : a[1] < b[1];
92 template<
typename IntType,
int Dim>
94 const IntType coords[Dim], IntType mnr[Dim]) {
96 const int BitLength =
sizeof(IntType) << 3;
99 for (
int d = 0; d < Dim; d++) {
108 for (
int i = 0; i < BitLength; ++i) {
110 for (
int d = 0; d < Dim; d++) {
112 mnr[k / BitLength] |= ((coords[d] >> i) & 0x1) << (k % BitLength);
120 template<
typename IntType,
int Dim>
122 unsigned int mnr[Dim]) {
126 template<
typename IntType,
int Dim>
128 unsigned int mnr[Dim]) {
130 const size_t HalfBitLength =
sizeof(
unsigned int) << 2;
138 unsigned int x_lo[2] = {coords[0], coords[1]};
141 unsigned int x_hi[2] = {coords[0] >> HalfBitLength, coords[1] >> HalfBitLength};
144 unsigned int mask = ~0x0;
146 for (
unsigned int i = (HalfBitLength); i > 0; i = i >> 1) {
149 mask = mask ^ (mask << i);
152 x_lo[0] = (x_lo[0] | (x_lo[0] << i)) & mask;
153 x_lo[1] = (x_lo[1] | (x_lo[1] << i)) & mask;
155 x_hi[0] = (x_hi[0] | (x_hi[0] << i)) & mask;
156 x_hi[1] = (x_hi[1] | (x_hi[1] << i)) & mask;
160 mnr[0] = x_lo[0] | (x_lo[1] << 1);
163 mnr[1] = x_hi[0] | (x_hi[1] << 1);
166 template<
typename IntType>
169 const size_t BitLength =
sizeof(IntType) << 3;
175 for (
unsigned int i = (BitLength >> 1); i > 0; i = i >> 1) {
190 template<
typename IntType,
int Dim>
192 const IntType b[Dim]) {
194 const size_t BitLength =
sizeof(IntType) << 3;
197 for (
int d = Dim - 1; d >= 0; d--) {
200 int msb = (mostSignificantBit<IntType>(a[d] ^ b[d]) + (d * BitLength));
210 template<
typename IntType,
int Dim>
212 const unsigned int a[Dim],
const unsigned int b[Dim]) {
213 return mostSignificantBit<unsigned int>(a[0] ^ b[0]);