souffle  2.0.2-371-g6315b36
Public Member Functions
souffle::synthesiser::EqrelRelation Class Reference

#include <Relation.h>

Inheritance diagram for souffle::synthesiser::EqrelRelation:
Inheritance graph
Collaboration diagram for souffle::synthesiser::EqrelRelation:
Collaboration graph

Public Member Functions

void computeIndices () override
 Generate index set for a eqrel relation. More...
 
 EqrelRelation (const ram::Relation &ramRel, const MinIndexSelection &indexSet, bool isProvenance)
 
void generateTypeStruct (std::ostream &out) override
 Generate type struct of a eqrel relation. More...
 
std::string getTypeName () override
 Generate type name of a eqrel relation. More...
 
- Public Member Functions inherited from souffle::ram::Relation
Relationclone () const override
 Create a clone (i.e. More...
 
unsigned getArity () const
 Get arity of relation. More...
 
const std::vector< std::string > & getAttributeNames () const
 Get attribute names. More...
 
const std::vector< std::string > & getAttributeTypes () const
 Get attribute types. More...
 
unsigned getAuxiliaryArity () const
 Get number of auxiliary attributes. More...
 
const std::string & getName () const
 Get name. More...
 
RelationRepresentation getRepresentation () const
 Relation representation type. More...
 
bool isNullary () const
 Is nullary relation. More...
 
bool isTemp () const
 Is temporary relation (for semi-naive evaluation) More...
 
bool operator< (const Relation &other) const
 Compare two relations via their name. More...
 
 Relation (std::string name, size_t arity, size_t auxiliaryArity, std::vector< std::string > attributeNames, std::vector< std::string > attributeTypes, RelationRepresentation representation)
 
- Public Member Functions inherited from souffle::ram::Node
virtual void apply (const NodeMapper &)
 Apply the mapper to all child nodes. More...
 
virtual std::vector< const Node * > getChildNodes () const
 Obtain list of all embedded child nodes. More...
 
bool operator!= (const Node &other) const
 Inequality check for two RAM nodes. More...
 
bool operator== (const Node &other) const
 Equivalence check for two RAM nodes. More...
 
virtual void rewrite (const Node *oldNode, Own< Node > newNode)
 Rewrite a child node. More...
 
virtual ~Node ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from souffle::ram::Relation
bool equal (const Node &node) const override
 Equality check for two RAM nodes. More...
 
void print (std::ostream &out) const override
 Print RAM node. More...
 
- Protected Attributes inherited from souffle::ram::Relation
const size_t arity
 Arity, i.e., number of attributes. More...
 
const std::vector< std::string > attributeNames
 Name of attributes. More...
 
const std::vector< std::string > attributeTypes
 Type of attributes. More...
 
const size_t auxiliaryArity
 Number of auxiliary attributes (e.g. More...
 
const std::string name
 Name of relation. More...
 
const RelationRepresentation representation
 Data-structure representation. More...
 

Detailed Description

Definition at line 154 of file Relation.h.

Constructor & Destructor Documentation

◆ EqrelRelation()

souffle::synthesiser::EqrelRelation::EqrelRelation ( const ram::Relation ramRel,
const MinIndexSelection indexSet,
bool  isProvenance 
)
inline

Definition at line 156 of file Relation.h.

157  : Relation(ramRel, indexSet, isProvenance) {}

Member Function Documentation

◆ computeIndices()

void souffle::synthesiser::EqrelRelation::computeIndices ( )
override

Generate index set for a eqrel relation.

Definition at line 1143 of file Relation.cpp.

1143  {
1144  assert(!isProvenance && "eqrel cannot be used with provenance");
1145 
1146  masterIndex = 0;
1147  // {1, 0} is equivalent for an eqrel
1148  computedIndices = {{0, 1}};
1149 }

◆ 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.

1157  {
1158  constexpr souffle::Relation::arity_type arity = 2;
1159  const auto& inds = getIndices();
1160  size_t numIndexes = inds.size();
1161  std::map<MinIndexSelection::LexOrder, int> indexToNumMap;
1162 
1163  // struct definition
1164  out << "struct " << getTypeName() << " {\n";
1165  out << "static constexpr Relation::arity_type Arity = " << arity << ";\n";
1166 
1167  // eqrel is only for binary relations
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";
1171 
1172  // generate auxiliary iterators that reorder tuples according to index orders
1173  // generate auxiliary iterators which orderOut
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";
1178 
1179  out << "public:\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";
1184 
1185  out << " bool operator==(const iterator_0& other) const {\n";
1186  out << " return nested == other.nested;\n";
1187  out << " }\n";
1188 
1189  out << " bool operator!=(const iterator_0& other) const {\n";
1190  out << " return !(*this == other);\n";
1191  out << " }\n";
1192 
1193  out << " const t_tuple& operator*() const {\n";
1194  out << " return value;\n";
1195  out << " }\n";
1196 
1197  out << " const t_tuple* operator->() const {\n";
1198  out << " return &value;\n";
1199  out << " }\n";
1200 
1201  out << " iterator_0& operator++() {\n";
1202  out << " ++nested;\n";
1203  out << " value = orderOut_0(*nested);\n";
1204  out << " return *this;\n";
1205  out << " }\n";
1206  out << "};\n";
1207 
1208  out << "using iterator = iterator_" << masterIndex << ";\n";
1209 
1210  // Create a struct storing the context hints for each index
1211  out << "struct context {\n";
1212  out << "t_ind_" << masterIndex << "::operation_hints hints_" << masterIndex << ";\n";
1213  out << "};\n";
1214  out << "context createContext() { return context(); }\n";
1215 
1216  // insert methods
1217  out << "bool insert(const t_tuple& t) {\n";
1218  out << "return ind_" << masterIndex << ".insert(t[0], t[1]);\n";
1219  out << "}\n";
1220 
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";
1223  out << "}\n";
1224 
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";
1231  out << "}\n";
1232 
1233  out << "bool insert(RamDomain a1, RamDomain a2) {\n";
1234  out << "RamDomain data[2] = {a1, a2};\n";
1235  out << "return insert(data);\n";
1236  out << "}\n";
1237 
1238  // extends method for eqrel
1239  // performs a delta extension, where we union the sets that share elements between this and other.
1240  // i.e. if a in this, and a in other, union(set(this->a), set(other->a))
1241  out << "void extend(const " << getTypeName() << "& other) {\n";
1242  out << "ind_" << masterIndex << ".extend(other.ind_" << masterIndex << ");\n";
1243  out << "}\n";
1244 
1245  // contains methods
1246  out << "bool contains(const t_tuple& t) const {\n";
1247  out << "return ind_" << masterIndex << ".contains(t[0], t[1]);\n";
1248  out << "}\n";
1249 
1250  out << "bool contains(const t_tuple& t, context& h) const {\n";
1251  out << "return ind_" << masterIndex << ".contains(t[0], t[1]);\n";
1252  out << "}\n";
1253 
1254  // size method
1255  out << "std::size_t size() const {\n";
1256  out << "return ind_" << masterIndex << ".size();\n";
1257  out << "}\n";
1258 
1259  // find methods
1260  out << "iterator find(const t_tuple& t) const {\n";
1261  out << "return ind_" << masterIndex << ".find(orderIn_" << masterIndex << "(t));\n";
1262  out << "}\n";
1263 
1264  out << "iterator find(const t_tuple& t, context& h) const {\n";
1265  out << "return ind_" << masterIndex << ".find(orderIn_" << masterIndex << "(t));\n";
1266  out << "}\n";
1267 
1268  // lowerUpperRange methods, one for each of the 4 possible search patterns
1269  for (int i = 1; i < 4; i++) {
1270  SearchSignature s(arity);
1271  // if the bit is set then set it in the search signature
1272  for (size_t j = 0; j < arity; j++) {
1273  if (i & (1 << j)) {
1274  s[j] = analysis::AttributeConstraint::Equal;
1275  }
1276  }
1277 
1278  out << "range<iterator> lowerUpperRange_" << s;
1279  out << "(const t_tuple& lower, const t_tuple& upper, context& h) const {\n";
1280  // compute size of sub-index
1281  size_t indSize = 0;
1282  for (size_t column = 0; column < 2; column++) {
1283  if (((i >> column) & 1) != 0) {
1284  indSize++;
1285  }
1286  }
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";
1290  out << "}\n";
1291 
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";
1295  out << "}\n";
1296  }
1297 
1298  // empty method
1299  out << "bool empty() const {\n";
1300  out << "return ind_" << masterIndex << ".size() == 0;\n";
1301  out << "}\n";
1302 
1303  // partition method
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";
1308  out << "}\n";
1309  out << "return res;\n";
1310  out << "}\n";
1311 
1312  // purge method
1313  out << "void purge() {\n";
1314  for (size_t i = 0; i < numIndexes; i++) {
1315  out << "ind_" << i << ".clear();\n";
1316  }
1317  out << "}\n";
1318 
1319  // begin and end iterators
1320  out << "iterator begin() const {\n";
1321  out << "return iterator_" << masterIndex << "(ind_" << masterIndex << ".begin());\n";
1322  out << "}\n";
1323 
1324  out << "iterator end() const {\n";
1325  out << "return iterator_" << masterIndex << "(ind_" << masterIndex << ".end());\n";
1326  out << "}\n";
1327 
1328  // printStatistics method
1329  out << "void printStatistics(std::ostream& o) const {\n";
1330  out << "o << \" eqrel index: no hint statistics supported\\n\";\n";
1331  out << "}\n";
1332 
1333  // generate orderIn and orderOut methods which reorder tuples
1334  // according to index orders
1335  for (size_t i = 0; i < numIndexes; i++) {
1336  auto ind = inds[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";
1341  }
1342  out << "return res;\n";
1343  out << "}\n";
1344 
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";
1349  }
1350  out << "return res;\n";
1351  out << "}\n";
1352  }
1353 
1354  // end class
1355  out << "};\n";
1356 }

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.

1152  {
1153  return "t_eqrel";
1154 }

The documentation for this class was generated from the following files:
souffle::ram::Relation::arity
const size_t arity
Arity, i.e., number of attributes.
Definition: Relation.h:139
souffle::ram::Relation::Relation
Relation(std::string name, size_t arity, size_t auxiliaryArity, std::vector< std::string > attributeNames, std::vector< std::string > attributeTypes, RelationRepresentation representation)
Definition: Relation.h:42
j
var j
Definition: htmlJsChartistMin.h:15
i
size_t i
Definition: json11.h:663
souffle::synthesiser::EqrelRelation::getTypeName
std::string getTypeName() override
Generate type name of a eqrel relation.
Definition: Relation.cpp:1152
souffle::Relation::arity_type
uint32_t arity_type
Definition: SouffleInterface.h:51