forked from Gullesnuffs/MaxCutInapproximability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.h
56 lines (42 loc) · 1.21 KB
/
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include "config.h"
#include <cstdint>
#include <cstdlib>
class Node {
uint32_t x;
public:
Node() {
static_assert(dimension <= 32,
"Hypercube dimensions greater than 32 aren't supported "
"because nodes are represented using only 32 bits");
x = 0;
}
Node(uint32_t x) : x(x) {
static_assert(dimension <= 32,
"Hypercube dimensions greater than 32 aren't supported "
"because nodes are represented using only 32 bits");
}
Node(const Node& other) { x = other.x; }
Node getNeighbour(unsigned direction) const {
return Node(getIndex() ^ (1u << direction));
}
uint32_t getIndex() const { return x; }
int operator[](int index) const {
if (x & (1u << index)) {
return -1;
} else {
return 1;
}
}
Node operator-() const {
uint32_t inv = uint32_t(n_nodes - 1 - x);
return Node(inv);
}
Node operator^(const Node& other) const { return Node(x ^ other.x); }
Node& operator^=(const Node& other) {
x ^= other.x;
return *this;
}
bool operator<(const Node& other) const { return x < other.x; }
bool operator==(const Node& other) const { return x == other.x; }
};