souffle  2.0.2-371-g6315b36
Public Member Functions | Data Fields | Private Attributes
souffle::tuple Class Reference

Defines a tuple for the OO interface such that relations with varying columns can be accessed. More...

#include <SouffleInterface.h>

Collaboration diagram for souffle::tuple:
Collaboration graph

Public Member Functions

decltype(array) ::iterator begin ()
 Iterator for direct access to tuple's data. More...
 
const RelationgetRelation () const
 Get the reference to the relation to which the tuple belongs. More...
 
tupleoperator<< (const std::string &str)
 Set the "current element" of the tuple to the given string, then increment the index giving the current element. More...
 
tupleoperator<< (RamFloat ramFloat)
 Set the "current element" of the tuple to the given float, then increment the index giving the current element. More...
 
tupleoperator<< (RamSigned integer)
 Set the "current element" of the tuple to the given int, then increment the index giving the current element. More...
 
tupleoperator<< (RamUnsigned uint)
 Set the "current element" of the tuple to the given uint, then increment the index giving the current element. More...
 
tupleoperator>> (RamFloat &ramFloat)
 Get the "current element" of the tuple as a float, then increment the index giving the current element. More...
 
tupleoperator>> (RamSigned &integer)
 Get the "current element" of the tuple as a int, then increment the index giving the current element. More...
 
tupleoperator>> (RamUnsigned &uint)
 Get the "current element" of the tuple as a unsigned, then increment the index giving the current element. More...
 
tupleoperator>> (std::string &str)
 Get the "current element" of the tuple as a string, then increment the index giving the current element. More...
 
RamDomainoperator[] (size_t idx)
 Overload the operator []. More...
 
const RamDomainoperator[] (size_t idx) const
 Overload the operator []. More...
 
void rewind ()
 Reset the index giving the "current element" of the tuple to zero. More...
 
Relation::arity_type size () const
 Return the number of elements in the tuple. More...
 
 tuple (const Relation *r)
 Constructor. More...
 
 tuple (const Relation *relation, std::initializer_list< RamDomain > tupleList)
 Construct using initialisation list. More...
 
 tuple (const tuple &t)
 Constructor. More...
 

Data Fields

const RamDomaindata = nullptr
 Allows printing using WriteStream. More...
 

Private Attributes

std::vector< RamDomainarray
 Dynamic array used to store the elements in a tuple. More...
 
size_t pos
 pos shows what the current position of a tuple is. More...
 
const Relationrelation
 The relation to which the tuple belongs. More...
 

Detailed Description

Defines a tuple for the OO interface such that relations with varying columns can be accessed.

Tuples are stored in relations. In Souffle, one row of data to be stored into a relation is represented as a tuple. For example if we have a relation called dog with attributes name, colour and age which are string, string and interger type respectively. One row of data a relation to be stored can be (mydog, black, 3). However, this is not directly stored as a tuple. There will be a symbol table storing the actual content and associate them with numbers (For example, |1|mydog| |2|black| |3|3|). And when this row of data is stored as a tuple, (1, 2, 3) will be stored.

Definition at line 443 of file SouffleInterface.h.

Constructor & Destructor Documentation

◆ tuple() [1/3]

souffle::tuple::tuple ( const Relation r)
inline

Constructor.

Tuples are constructed here by passing a relation, then may be subsequently inserted into that same passed relation. The passed relation pointer will be stored within the tuple instance, while the arity of the relation will be used to initialize the vector holding the elements of the tuple. Where such an element is of integer type, it will be stored directly within the vector. Otherwise, if the element is of a string type, the index of that string within the associated symbol table will be stored instead. The tuple also stores the index of some "current" element, referred to as its position. The constructor initially sets this position to the first (zeroth) element of the tuple, while subsequent methods of this class use that position for element access and modification.

Parameters
rRelation pointer pointing to a relation

Definition at line 480 of file SouffleInterface.h.

487 : relation(t.relation), array(t.array), pos(t.pos), data(array.data()) {}

◆ tuple() [2/3]

souffle::tuple::tuple ( const tuple t)
inline

Constructor.

Tuples are constructed here by passing a tuple. The relation to which the passed tuple belongs to will be stored. The array of the passed tuple, which stores the elements will be stroed. The pos will be set to be the same as the pos of passed tuple. belongs to.

Parameters
Referenceto a tuple object.

Definition at line 493 of file SouffleInterface.h.

499 {

◆ tuple() [3/3]

souffle::tuple::tuple ( const Relation relation,
std::initializer_list< RamDomain tupleList 
)
inline

Construct using initialisation list.

Definition at line 684 of file SouffleInterface.h.

687  {

Member Function Documentation

◆ begin()

decltype(array) ::iterator souffle::tuple::begin ( )
inline

Iterator for direct access to tuple's data.

See also
Relation::iteraor::begin()

Definition at line 677 of file SouffleInterface.h.

679  : relation(*relation), array(tupleList), pos(tupleList.size()), data(array.data()) {

References souffle::Relation::getArity(), and relation.

Here is the call graph for this function:

◆ getRelation()

const Relation& souffle::tuple::getRelation ( ) const
inline

Get the reference to the relation to which the tuple belongs.

Returns
Reference to a relation.

Definition at line 505 of file SouffleInterface.h.

◆ operator<<() [1/4]

tuple& souffle::tuple::operator<< ( const std::string &  str)
inline

Set the "current element" of the tuple to the given string, then increment the index giving the current element.

Parameters
strSymbol to be added (std::string)
Returns
Reference to the tuple

Definition at line 565 of file SouffleInterface.h.

573  {

References souffle::Relation::getAttrType(), pos, relation, and size().

Here is the call graph for this function:

◆ operator<<() [2/4]

tuple& souffle::tuple::operator<< ( RamFloat  ramFloat)
inline

Set the "current element" of the tuple to the given float, then increment the index giving the current element.

Parameters
floatfloat to be added
Returns
Reference to the tuple

Definition at line 608 of file SouffleInterface.h.

References souffle::Relation::getAttrType(), souffle::Relation::getSymbolTable(), pos, relation, souffle::SymbolTable::resolve(), size(), and str.

Here is the call graph for this function:

◆ operator<<() [3/4]

tuple& souffle::tuple::operator<< ( RamSigned  integer)
inline

Set the "current element" of the tuple to the given int, then increment the index giving the current element.

Parameters
integerInteger to be added
Returns
Reference to the tuple

Definition at line 579 of file SouffleInterface.h.

588  {

◆ operator<<() [4/4]

tuple& souffle::tuple::operator<< ( RamUnsigned  uint)
inline

Set the "current element" of the tuple to the given uint, then increment the index giving the current element.

Parameters
uintUnsigned number to be added
Returns
Reference to the tuple

Definition at line 594 of file SouffleInterface.h.

602  {

References souffle::Relation::getAttrType(), pos, souffle::ramBitCast(), relation, and size().

Here is the call graph for this function:

◆ operator>>() [1/4]

tuple& souffle::tuple::operator>> ( RamFloat ramFloat)
inline

Get the "current element" of the tuple as a float, then increment the index giving the current element.

Parameters
ramFloatFloat to be loaded from the tuple
Returns
Reference to the tuple

Definition at line 665 of file SouffleInterface.h.

◆ operator>>() [2/4]

tuple& souffle::tuple::operator>> ( RamSigned integer)
inline

Get the "current element" of the tuple as a int, then increment the index giving the current element.

Parameters
integerInteger to be loaded from the tuple
Returns
Reference to the tuple

Definition at line 636 of file SouffleInterface.h.

645  {

◆ operator>>() [3/4]

tuple& souffle::tuple::operator>> ( RamUnsigned uint)
inline

Get the "current element" of the tuple as a unsigned, then increment the index giving the current element.

Parameters
uintUnsigned number to be loaded from the tuple
Returns
Reference to the tuple

Definition at line 651 of file SouffleInterface.h.

659  {

References souffle::Relation::getAttrType(), pos, relation, and size().

Here is the call graph for this function:

◆ operator>>() [4/4]

tuple& souffle::tuple::operator>> ( std::string &  str)
inline

Get the "current element" of the tuple as a string, then increment the index giving the current element.

Parameters
strSymbol to be loaded from the tuple(std::string)
Returns
Reference to the tuple

Definition at line 622 of file SouffleInterface.h.

630  {

References souffle::Relation::getAttrType(), pos, relation, and size().

Here is the call graph for this function:

◆ operator[]() [1/2]

RamDomain& souffle::tuple::operator[] ( size_t  idx)
inline

Overload the operator [].

Direct access to tuple elements via index and return the element in idx position of a tuple.

TODO (Honghyw) : This interface should be hidden and only be used by friendly classes such as iterators; users should not use this interface.

Parameters
idxThis is the idx of element in a tuple (size_t).

Definition at line 531 of file SouffleInterface.h.

535  : This interface should be hidden and

◆ operator[]() [2/2]

const RamDomain& souffle::tuple::operator[] ( size_t  idx) const
inline

Overload the operator [].

Direct access to tuple elements via index and Return the element in idx position of a tuple. The returned element can not be changed.

TODO (Honghyw) : This interface should be hidden and only be used by friendly classes such as iterators; users should not use this interface.

Parameters
idxThis is the idx of element in a tuple (size_t).

Definition at line 547 of file SouffleInterface.h.

548  {
549  pos = 0;

References pos.

◆ rewind()

void souffle::tuple::rewind ( )
inline

Reset the index giving the "current element" of the tuple to zero.

Definition at line 554 of file SouffleInterface.h.

References souffle::Relation::getAttrType(), souffle::Relation::getSymbolTable(), souffle::SymbolTable::lookup(), pos, relation, size(), and str.

Here is the call graph for this function:

◆ size()

Relation::arity_type souffle::tuple::size ( ) const
inline

Return the number of elements in the tuple.

Returns
the number of elements in the tuple (size_t).

Definition at line 514 of file SouffleInterface.h.

519  : This interface should be hidden and

Referenced by operator<<(), operator>>(), and rewind().

Field Documentation

◆ array

std::vector<RamDomain> souffle::tuple::array
private

Dynamic array used to store the elements in a tuple.

Definition at line 452 of file SouffleInterface.h.

◆ data

const RamDomain* souffle::tuple::data = nullptr

◆ pos

size_t souffle::tuple::pos
private

pos shows what the current position of a tuple is.

Initially, pos is 0 meaning we are at the head of the tuple. If we have an empty tuple and try to insert things, pos lets us know where to insert the element. After the element is inserted, pos will be incremented by 1. If we have a tuple with content, pos lets us know where to read the element. After we have read one element, pos will be incremented by 1. pos also helps to make sure we access an insert a tuple within the bound by making sure pos never exceeds the arity of the relation.

Definition at line 463 of file SouffleInterface.h.

Referenced by operator<<(), operator>>(), operator[](), and rewind().

◆ relation

const Relation& souffle::tuple::relation
private

The relation to which the tuple belongs.

Definition at line 447 of file SouffleInterface.h.

Referenced by begin(), operator<<(), operator>>(), and rewind().


The documentation for this class was generated from the following file:
souffle::tuple::relation
const Relation & relation
The relation to which the tuple belongs.
Definition: SouffleInterface.h:447
souffle::tuple::pos
size_t pos
pos shows what the current position of a tuple is.
Definition: SouffleInterface.h:463
array
souffle::tuple::data
const RamDomain * data
Allows printing using WriteStream.
Definition: SouffleInterface.h:498
souffle::tuple::array
std::vector< RamDomain > array
Dynamic array used to store the elements in a tuple.
Definition: SouffleInterface.h:452