-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalg_impl.hpp
69 lines (50 loc) · 1.42 KB
/
alg_impl.hpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <iterator>
#include <cassert>
#include <iterator>
#include <queue>
#include <type_traits>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
//class PDB;
template<typename T> std::vector<uint8_t> PDB<T>::genPdb(T start, uint64_t const permuts) {
struct Node {
T elem;
uint8_t depth;
};
std::queue<Node> q;
//this single line is literally the entirety of korf's fabled pdb lmao
std::vector<uint8_t> pdb(permuts/2);
q.push(Node{start, 0});
uint64_t nodeCount = 0;
//int percentDone = 0;
//int iterCount = 0;
//std::array<uint32_t, 27> invalidRots;
while (!q.empty()) {
Node current = q.front();
q.pop();
for (T neighbor : current.elem.getNeighbors()) {
uint64_t idx = neighbor.getIdx();
if (!(pdb[idx/2] & ((idx%2) ? 0xf0 : 0x0f))) {
q.push(Node{neighbor, static_cast<uint8_t>(current.depth + 1)});
nodeCount++;
//if (nodeCount % 47900160 == 0) {
// percentDone++;
//std::cout << percentDone << "%" << std::endl;
//}
pdb[idx/2] |= (static_cast<uint8_t>(current.depth+1) << ((idx%2) ? 4 : 0));
}
}
//iterCount++;
}
std::cout << "Node count: " << nodeCount << std::endl;
pdb[start.getIdx()/2] &= ~((0b1111 << (start.getIdx()%2 ? 4 : 0)));
return pdb;
}
template<typename T> uint8_t PDB<T>::getDist(uint64_t idx) const {
return (data[idx/2] >> ((idx%2) ? 4 : 0))&0b1111;
}