blob: 6c3e586c6fe90ec233ef48c3ce87d0b96cfe13a8 (
plain)
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
|
#include <tuple>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include "ts_lib.h"
void Structure::AddFact(const Triplet &fact) {
assert(!IsTrue(fact));
Triplet key(fact);
for (uint8_t i = 0; i < 8; i++) {
for (uint8_t j = 0; j < 3; j++) {
if ((i >> j) & 0b1) {
key[j] = fact[j];
} else {
key[j] = Node(0);
}
}
facts_[key].push_back(fact);
}
}
void Structure::RemoveFact(const Triplet &fact) {
assert(IsTrue(fact));
Triplet key(fact);
for (uint8_t i = 0; i < 8; i++) {
for (uint8_t j = 0; j < 3; j++) {
if ((i >> j) & 0b1) {
key[j] = fact[j];
} else {
key[j] = Node(0);
}
}
auto it = std::find(facts_[key].begin(), facts_[key].end(), fact);
assert(it != facts_[key].end());
facts_[key].erase(it);
}
}
void Structure::AddFactPy(Node i, Node j, Node k) {
AddFact(Triplet(i, j, k));
}
void Structure::RemoveFactPy(Node i, Node j, Node k) {
RemoveFact(Triplet(i, j, k));
}
const std::vector<Triplet> &Structure::Lookup(const Triplet &fact) const {
try {
return facts_.at(fact);
} catch (std::out_of_range &) {
// TODO(masotoud): Maybe not?
return empty_;
}
}
bool Structure::AllTrue(const std::vector<Triplet> &facts) const {
for (auto &fact : facts) {
if (!IsTrue(fact)) {
return false;
}
}
return true;
}
bool Structure::IsTrue(const Triplet &fact) const {
return facts_.count(fact) > 0 && !facts_.at(fact).empty();
}
|