#include <Relation.h>
Definition at line 154 of file Relation.h.
◆ EqrelRelation()
◆ computeIndices()
void souffle::synthesiser::EqrelRelation::computeIndices |
( |
| ) |
|
|
override |
Generate index set for a eqrel relation.
Definition at line 1143 of file Relation.cpp.
1144 assert(!isProvenance &&
"eqrel cannot be used with provenance");
1148 computedIndices = {{0, 1}};
◆ generateTypeStruct()
void souffle::synthesiser::EqrelRelation::generateTypeStruct |
( |
std::ostream & |
out | ) |
|
|
override |
Generate type struct of a eqrel relation.
Definition at line 1157 of file Relation.cpp.
1159 const auto& inds = getIndices();
1160 size_t numIndexes = inds.size();
1161 std::map<MinIndexSelection::LexOrder, int> indexToNumMap;
1165 out <<
"static constexpr Relation::arity_type Arity = " <<
arity <<
";\n";
1168 out <<
"using t_tuple = Tuple<RamDomain, " <<
arity <<
">;\n";
1169 out <<
"using t_ind_" << masterIndex <<
" = EquivalenceRelation<t_tuple>;\n";
1170 out <<
"t_ind_" << masterIndex <<
" ind_" << masterIndex <<
";\n";
1174 out <<
"class iterator_0 : public std::iterator<std::forward_iterator_tag, t_tuple> {\n";
1175 out <<
" using nested_iterator = typename t_ind_0::iterator;\n";
1176 out <<
" nested_iterator nested;\n";
1177 out <<
" t_tuple value;\n";
1180 out <<
" iterator_0() = default;\n";
1181 out <<
" iterator_0(const nested_iterator& iter) : nested(iter), value(orderOut_0(*iter)) {}\n";
1182 out <<
" iterator_0(const iterator_0& other) = default;\n";
1183 out <<
" iterator_0& operator=(const iterator_0& other) = default;\n";
1185 out <<
" bool operator==(const iterator_0& other) const {\n";
1186 out <<
" return nested == other.nested;\n";
1189 out <<
" bool operator!=(const iterator_0& other) const {\n";
1190 out <<
" return !(*this == other);\n";
1193 out <<
" const t_tuple& operator*() const {\n";
1194 out <<
" return value;\n";
1197 out <<
" const t_tuple* operator->() const {\n";
1198 out <<
" return &value;\n";
1201 out <<
" iterator_0& operator++() {\n";
1202 out <<
" ++nested;\n";
1203 out <<
" value = orderOut_0(*nested);\n";
1204 out <<
" return *this;\n";
1208 out <<
"using iterator = iterator_" << masterIndex <<
";\n";
1211 out <<
"struct context {\n";
1212 out <<
"t_ind_" << masterIndex <<
"::operation_hints hints_" << masterIndex <<
";\n";
1214 out <<
"context createContext() { return context(); }\n";
1217 out <<
"bool insert(const t_tuple& t) {\n";
1218 out <<
"return ind_" << masterIndex <<
".insert(t[0], t[1]);\n";
1221 out <<
"bool insert(const t_tuple& t, context& h) {\n";
1222 out <<
"return ind_" << masterIndex <<
".insert(t[0], t[1], h.hints_" << masterIndex <<
");\n";
1225 out <<
"bool insert(const RamDomain* ramDomain) {\n";
1226 out <<
"RamDomain data[2];\n";
1227 out <<
"std::copy(ramDomain, ramDomain + 2, data);\n";
1228 out <<
"const t_tuple& tuple = reinterpret_cast<const t_tuple&>(data);\n";
1229 out <<
"context h;\n";
1230 out <<
"return insert(tuple, h);\n";
1233 out <<
"bool insert(RamDomain a1, RamDomain a2) {\n";
1234 out <<
"RamDomain data[2] = {a1, a2};\n";
1235 out <<
"return insert(data);\n";
1241 out <<
"void extend(const " <<
getTypeName() <<
"& other) {\n";
1242 out <<
"ind_" << masterIndex <<
".extend(other.ind_" << masterIndex <<
");\n";
1246 out <<
"bool contains(const t_tuple& t) const {\n";
1247 out <<
"return ind_" << masterIndex <<
".contains(t[0], t[1]);\n";
1250 out <<
"bool contains(const t_tuple& t, context& h) const {\n";
1251 out <<
"return ind_" << masterIndex <<
".contains(t[0], t[1]);\n";
1255 out <<
"std::size_t size() const {\n";
1256 out <<
"return ind_" << masterIndex <<
".size();\n";
1260 out <<
"iterator find(const t_tuple& t) const {\n";
1261 out <<
"return ind_" << masterIndex <<
".find(orderIn_" << masterIndex <<
"(t));\n";
1264 out <<
"iterator find(const t_tuple& t, context& h) const {\n";
1265 out <<
"return ind_" << masterIndex <<
".find(orderIn_" << masterIndex <<
"(t));\n";
1269 for (
int i = 1;
i < 4;
i++) {
1270 SearchSignature s(
arity);
1272 for (
size_t j = 0;
j <
arity;
j++) {
1274 s[
j] = analysis::AttributeConstraint::Equal;
1278 out <<
"range<iterator> lowerUpperRange_" << s;
1279 out <<
"(const t_tuple& lower, const t_tuple& upper, context& h) const {\n";
1282 for (
size_t column = 0; column < 2; column++) {
1283 if (((
i >> column) & 1) != 0) {
1287 out <<
"auto r = ind_" << masterIndex <<
".template getBoundaries<" << indSize <<
">(orderIn_"
1288 << masterIndex <<
"(lower), h.hints_" << masterIndex <<
");\n";
1289 out <<
"return make_range(iterator(r.begin()), iterator(r.end()));\n";
1292 out <<
"range<iterator> lowerUpperRange_" << s;
1293 out <<
"(const t_tuple& lower, const t_tuple& upper) const {\n";
1294 out <<
"context h; return lowerUpperRange_" << s <<
"(lower, upper, h);\n";
1299 out <<
"bool empty() const {\n";
1300 out <<
"return ind_" << masterIndex <<
".size() == 0;\n";
1304 out <<
"std::vector<range<iterator>> partition() const {\n";
1305 out <<
"std::vector<range<iterator>> res;\n";
1306 out <<
"for (const auto& cur : ind_" << masterIndex <<
".partition(10000)) {\n";
1307 out <<
" res.push_back(make_range(iterator(cur.begin()), iterator(cur.end())));\n";
1309 out <<
"return res;\n";
1313 out <<
"void purge() {\n";
1314 for (
size_t i = 0;
i < numIndexes;
i++) {
1315 out <<
"ind_" <<
i <<
".clear();\n";
1320 out <<
"iterator begin() const {\n";
1321 out <<
"return iterator_" << masterIndex <<
"(ind_" << masterIndex <<
".begin());\n";
1324 out <<
"iterator end() const {\n";
1325 out <<
"return iterator_" << masterIndex <<
"(ind_" << masterIndex <<
".end());\n";
1329 out <<
"void printStatistics(std::ostream& o) const {\n";
1330 out <<
"o << \" eqrel index: no hint statistics supported\\n\";\n";
1335 for (
size_t i = 0;
i < numIndexes;
i++) {
1337 out <<
"static t_tuple orderIn_" <<
i <<
"(const t_tuple& t) {\n";
1338 out <<
"t_tuple res;\n";
1339 for (
size_t j = 0;
j < ind.size();
j++) {
1340 out <<
"res[" <<
j <<
"] = t[" << ind[
j] <<
"];\n";
1342 out <<
"return res;\n";
1345 out <<
"static t_tuple orderOut_" <<
i <<
"(const t_tuple& t) {\n";
1346 out <<
"t_tuple res;\n";
1347 for (
size_t j = 0;
j < ind.size();
j++) {
1348 out <<
"res[" << ind[
j] <<
"] = t[" <<
j <<
"];\n";
1350 out <<
"return res;\n";
References i, and j.
◆ getTypeName()
std::string souffle::synthesiser::EqrelRelation::getTypeName |
( |
| ) |
|
|
override |
Generate type name of a eqrel relation.
Definition at line 1152 of file Relation.cpp.
The documentation for this class was generated from the following files:
Relation(std::string name, size_t arity, size_t auxiliaryArity, std::vector< std::string > attributeNames, std::vector< std::string > attributeTypes, RelationRepresentation representation)