souffle  2.0.2-371-g6315b36
Data Structures | Public Types | Public Member Functions | Static Public Attributes | Private Attributes
souffle::RelationWrapper< RelType > Class Template Reference

Relation wrapper used internally in the generated Datalog program. More...

#include <CompiledSouffle.h>

Inheritance diagram for souffle::RelationWrapper< RelType >:
Inheritance graph
Collaboration diagram for souffle::RelationWrapper< RelType >:
Collaboration graph

Data Structures

class  iterator_wrapper
 

Public Types

using AttrStrSeq = std::array< const char *, Arity >
 
using TupleType = Tuple< RamDomain, Arity >
 
- Public Types inherited from souffle::Relation
using arity_type = uint32_t
 

Public Member Functions

iterator begin () const override
 Return an iterator pointing to the first tuple of the relation. More...
 
bool contains (const tuple &arg) const override
 Check whether a tuple exists in a relation. More...
 
iterator end () const override
 Return an iterator pointing to next to the last tuple of the relation. More...
 
arity_type getArity () const override
 Return the arity of a relation. More...
 
const char * getAttrName (size_t arg) const override
 Get the attribute name of a relation at the column specified by the parameter. More...
 
const char * getAttrType (size_t arg) const override
 Get the attribute type of a relation at the column specified by the parameter. More...
 
arity_type getAuxiliaryArity () const override
 Return the number of auxiliary attributes. More...
 
std::string getName () const override
 Get the name of a relation. More...
 
SymbolTablegetSymbolTable () const override
 Get the symbol table of a relation. More...
 
void insert (const tuple &arg) override
 Insert a new tuple into the relation. More...
 
void purge () override
 Eliminate all the tuples in relation. More...
 
 RelationWrapper (uint32_t id, RelType &r, SouffleProgram &p, std::string name, const AttrStrSeq &t, const AttrStrSeq &n, arity_type numAuxAttribs)
 
std::size_t size () const override
 Get the number of tuples in a relation. More...
 
- Public Member Functions inherited from souffle::Relation
arity_type getPrimaryArity () const
 Return the number of non-auxiliary attributes. More...
 
std::string getSignature ()
 Get the signature of a relation. More...
 
virtual ~Relation ()=default
 Destructor. More...
 

Static Public Attributes

static constexpr arity_type Arity = RelType::Arity
 

Private Attributes

AttrStrSeq attrNames
 
AttrStrSeq attrTypes
 
const uint32_t id
 
std::string name
 
const arity_type numAuxAttribs
 
SouffleProgramprogram
 
RelType & relation
 

Detailed Description

template<class RelType>
class souffle::RelationWrapper< RelType >

Relation wrapper used internally in the generated Datalog program.

Definition at line 80 of file CompiledSouffle.h.

Member Typedef Documentation

◆ AttrStrSeq

template<class RelType >
using souffle::RelationWrapper< RelType >::AttrStrSeq = std::array<const char*, Arity>

Definition at line 84 of file CompiledSouffle.h.

◆ TupleType

template<class RelType >
using souffle::RelationWrapper< RelType >::TupleType = Tuple<RamDomain, Arity>

Definition at line 83 of file CompiledSouffle.h.

Constructor & Destructor Documentation

◆ RelationWrapper()

template<class RelType >
souffle::RelationWrapper< RelType >::RelationWrapper ( uint32_t  id,
RelType &  r,
SouffleProgram p,
std::string  name,
const AttrStrSeq t,
const AttrStrSeq n,
arity_type  numAuxAttribs 
)
inline

Definition at line 126 of file CompiledSouffle.h.

128  {
129  return iterator(mk<iterator_wrapper>(id, this, relation.end()));

Member Function Documentation

◆ begin()

template<class RelType >
iterator souffle::RelationWrapper< RelType >::begin ( ) const
inlineoverridevirtual

Return an iterator pointing to the first tuple of the relation.

This iterator is used to access the tuples of the relation.

Returns
Iterator

Implements souffle::Relation.

Definition at line 131 of file CompiledSouffle.h.

132  {
133  TupleType t;

◆ contains()

template<class RelType >
bool souffle::RelationWrapper< RelType >::contains ( const tuple t) const
inlineoverridevirtual

Check whether a tuple exists in a relation.

The definition of contains has to be defined by the child class of relation class.

Parameters
tReference to a tuple object
Returns
Boolean. True, if the tuple exists. False, otherwise

Implements souffle::Relation.

Definition at line 147 of file CompiledSouffle.h.

149  {
150  return relation.size();
151  }
152  std::string getName() const override {
153  return name;
154  }

◆ end()

template<class RelType >
iterator souffle::RelationWrapper< RelType >::end ( ) const
inlineoverridevirtual

Return an iterator pointing to next to the last tuple of the relation.

Returns
Iterator

Implements souffle::Relation.

Definition at line 134 of file CompiledSouffle.h.

136  {

◆ getArity()

template<class RelType >
arity_type souffle::RelationWrapper< RelType >::getArity ( ) const
inlineoverridevirtual

Return the arity of a relation.

For example for a tuple (1 2) the arity is 2 and for a tuple (1 2 3) the arity is 3.

Returns
Arity of a relation (arity_type)

Implements souffle::Relation.

Definition at line 169 of file CompiledSouffle.h.

169  {
170  return program.getSymbolTable();
171  }

References souffle::SouffleProgram::getSymbolTable(), and souffle::RelationWrapper< RelType >::program.

Here is the call graph for this function:

◆ getAttrName()

template<class RelType >
const char* souffle::RelationWrapper< RelType >::getAttrName ( size_t  ) const
inlineoverridevirtual

Get the attribute name of a relation at the column specified by the parameter.

The attribute name is the name given to the type by the user in the .decl statement. For example, for ".decl edge (node1:Node, node2:Node)", the attribute names are node1 and node2.

Parameters
Theindex of the column starting starting from 0 (size_t)
Returns
The constant string of the attribute name

Implements souffle::Relation.

Definition at line 165 of file CompiledSouffle.h.

166  {
167  return numAuxAttribs;
168  }

◆ getAttrType()

template<class RelType >
const char* souffle::RelationWrapper< RelType >::getAttrType ( size_t  ) const
inlineoverridevirtual

Get the attribute type of a relation at the column specified by the parameter.

The attribute type is in the form "<primitive type>:<type name>". <primitive type> can be s, f, u, or i standing for symbol, float, unsigned, and integer respectively, which are the primitive types in Souffle. <type name> is the name given by the user in the Souffle program

Parameters
Theindex of the column starting starting from 0 (size_t)
Returns
The constant string of the attribute type

Implements souffle::Relation.

Definition at line 161 of file CompiledSouffle.h.

163  {
164  return Arity;

◆ getAuxiliaryArity()

template<class RelType >
arity_type souffle::RelationWrapper< RelType >::getAuxiliaryArity ( ) const
inlineoverridevirtual

Return the number of auxiliary attributes.

Auxiliary attributes are used for provenance and and other alternative evaluation strategies. They are stored as the last attributes of a tuple.

Returns
Number of auxiliary attributes of a relation (arity_type)

Implements souffle::Relation.

Definition at line 172 of file CompiledSouffle.h.

174  {

◆ getName()

template<class RelType >
std::string souffle::RelationWrapper< RelType >::getName ( ) const
inlineoverridevirtual

Get the name of a relation.

Returns
The name of a relation (std::string)

Implements souffle::Relation.

Definition at line 158 of file CompiledSouffle.h.

159  {
160  assert(arg < Arity && "attribute out of bound");

◆ getSymbolTable()

template<class RelType >
SymbolTable& souffle::RelationWrapper< RelType >::getSymbolTable ( ) const
inlineoverridevirtual

Get the symbol table of a relation.

The symbols in a tuple to be stored into a relation are stored and assigned with a number in a table called symbol table. For example, to insert ("John","Student") to a relation, "John" and "Student" are stored in symbol table and they are assigned with number say 0 and 1. After this, instead of inserting ("John","Student"), (0, 1) is inserted. When accessing this tuple, 0 and 1 will be looked up in the table and replaced by "John" and "Student". This is done so to save memory space if same symbols are inserted many times. Symbol table has many rows where each row contains a symbol and its corresponding assigned number.

Returns
Reference to a symbolTable object

Implements souffle::Relation.

Definition at line 175 of file CompiledSouffle.h.

180  {

◆ insert()

template<class RelType >
void souffle::RelationWrapper< RelType >::insert ( const tuple t)
inlineoverridevirtual

Insert a new tuple into the relation.

The definition of insert function has to be defined by the child class of relation class.

Parameters
tReference to a tuple class object

Implements souffle::Relation.

Definition at line 138 of file CompiledSouffle.h.

141  {
142  TupleType t;
143  assert(arg.size() == Arity && "wrong tuple arity");
144  for (size_t i = 0; i < Arity; i++) {
145  t[i] = arg[i];
146  }

◆ purge()

template<class RelType >
void souffle::RelationWrapper< RelType >::purge ( )
inlineoverridevirtual

Eliminate all the tuples in relation.

Implements souffle::Relation.

Definition at line 180 of file CompiledSouffle.h.

180  {
181 private:
182  std::atomic<bool> data{false};

References souffle::t_nullaries::Arity, and souffle::t_nullaries::data.

◆ size()

template<class RelType >
std::size_t souffle::RelationWrapper< RelType >::size ( ) const
inlineoverridevirtual

Get the number of tuples in a relation.

Returns
The number of tuples in a relation (std::size_t)

Implements souffle::Relation.

Definition at line 155 of file CompiledSouffle.h.

155  {
156  assert(arg < Arity && "attribute out of bound");
157  return attrTypes[arg];

References souffle::RelationWrapper< RelType >::Arity, and souffle::RelationWrapper< RelType >::attrTypes.

Field Documentation

◆ Arity

template<class RelType >
constexpr arity_type souffle::RelationWrapper< RelType >::Arity = RelType::Arity
staticconstexpr

◆ attrNames

template<class RelType >
AttrStrSeq souffle::RelationWrapper< RelType >::attrNames
private

Definition at line 91 of file CompiledSouffle.h.

◆ attrTypes

template<class RelType >
AttrStrSeq souffle::RelationWrapper< RelType >::attrTypes
private

Definition at line 90 of file CompiledSouffle.h.

Referenced by souffle::RelationWrapper< RelType >::size().

◆ id

template<class RelType >
const uint32_t souffle::RelationWrapper< RelType >::id
private

Definition at line 92 of file CompiledSouffle.h.

◆ name

template<class RelType >
std::string souffle::RelationWrapper< RelType >::name
private

Definition at line 89 of file CompiledSouffle.h.

◆ numAuxAttribs

template<class RelType >
const arity_type souffle::RelationWrapper< RelType >::numAuxAttribs
private

Definition at line 93 of file CompiledSouffle.h.

◆ program

template<class RelType >
SouffleProgram& souffle::RelationWrapper< RelType >::program
private

Definition at line 88 of file CompiledSouffle.h.

Referenced by souffle::RelationWrapper< RelType >::getArity().

◆ relation

template<class RelType >
RelType& souffle::RelationWrapper< RelType >::relation
private

Definition at line 87 of file CompiledSouffle.h.


The documentation for this class was generated from the following file:
souffle::RelationWrapper::attrTypes
AttrStrSeq attrTypes
Definition: CompiledSouffle.h:90
souffle::RelationWrapper::program
SouffleProgram & program
Definition: CompiledSouffle.h:88
souffle::RelationWrapper::Arity
static constexpr arity_type Arity
Definition: CompiledSouffle.h:82
souffle::RelationWrapper::getName
std::string getName() const override
Get the name of a relation.
Definition: CompiledSouffle.h:158
i
size_t i
Definition: json11.h:663
souffle::RelationWrapper::numAuxAttribs
const arity_type numAuxAttribs
Definition: CompiledSouffle.h:93
souffle::RelationWrapper::name
std::string name
Definition: CompiledSouffle.h:89
souffle::RelationWrapper::TupleType
Tuple< RamDomain, Arity > TupleType
Definition: CompiledSouffle.h:83
TCB_SPAN_NAMESPACE_NAME::detail::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: span.h:210
souffle::SouffleProgram::getSymbolTable
virtual SymbolTable & getSymbolTable()=0
Get the symbol table of the program.
souffle::RelationWrapper::relation
RelType & relation
Definition: CompiledSouffle.h:87