souffle  2.0.2-371-g6315b36
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes
souffle::interpreter::Relation< _Arity, Structure > Class Template Reference

A relation, composed of a collection of indexes. More...

#include <Relation.h>

Inheritance diagram for souffle::interpreter::Relation< _Arity, Structure >:
Inheritance graph
Collaboration diagram for souffle::interpreter::Relation< _Arity, Structure >:
Collaboration graph

Data Structures

class  iterator_base
 

Public Types

using Attribute = uint32_t
 
using AttributeSet = std::set< Attribute >
 
using Index = interpreter::Index< Arity, Structure >
 
using iterator = typename Index::iterator
 
using Tuple = souffle::Tuple< RamDomain, Arity >
 
using View = typename Index::View
 
- Public Types inherited from souffle::interpreter::RelationWrapper
using arity_type = souffle::Relation::arity_type
 
using IndexViewPtr = Own< ViewWrapper >
 

Public Member Functions

void __purge ()
 Clear all indexes. More...
 
size_t __size () const
 Return number of tuples in relation (full-order) More...
 
Iterator begin () const override
 
bool contains (const RamDomain *data) const override
 
bool contains (const size_t &indexPos, const Tuple &low, const Tuple &high) const
 Tests whether this relation contains any element between the given boundaries. More...
 
bool contains (const Tuple &tuple) const
 Tests whether this relation contains the given tuple. More...
 
IndexViewPtr createView (const size_t &indexPos) const override
 Obtains a view on an index of this relation, facilitating hint-supported accesses. More...
 
bool empty () const
 Check if the relation is empty. More...
 
Iterator end () const override
 
bool exists (const Tuple &tuple) const
 Check if a tuple exists in relation. More...
 
IndexgetIndex (size_t idx)
 
Order getIndexOrder (size_t idx) const override
 Return the order of an index. More...
 
void insert (const RamDomain *data) override
 
void insert (const Relation< Arity, Structure > &other)
 Add all entries of the given relation to this relation. More...
 
bool insert (const Tuple &tuple)
 Add the given tuple to this relation. More...
 
std::vector< souffle::range< iterator > > partitionRange (const size_t &indexPos, const Tuple &low, const Tuple &high, size_t partitionCount) const
 Returns a partitioned list of iterators coving elements in range [low, high]. More...
 
std::vector< souffle::range< iterator > > partitionScan (size_t partitionCount) const
 Returns a partitioned list of iterators for parallel computation. More...
 
void purge () override
 
souffle::range< iteratorrange (const size_t &indexPos, const Tuple &low, const Tuple &high) const
 Obtains a pair of iterators covering the interval between the two given entries. More...
 
 Relation (Relation &other)=delete
 
 Relation (size_t auxiliaryArity, std::string name, const ram::analysis::MinIndexSelection &orderSet)
 Creates a relation, build all necessary indexes. More...
 
souffle::range< iteratorscan () const
 Obtains a pair of iterators to scan the entire relation. More...
 
size_t size () const override
 
void swap (Relation< Arity, Structure > &other)
 Swaps the content of this and the given relation, including the installed indexes. More...
 
- Public Member Functions inherited from souffle::interpreter::RelationWrapper
arity_type getArity () const
 
arity_type getAuxiliaryArity () const
 
const std::string & getName () const
 
 RelationWrapper (arity_type arity, arity_type auxiliaryArity, std::string relName)
 
virtual ~RelationWrapper ()=default
 

Static Public Member Functions

static ViewcastView (ViewWrapper *view)
 Cast an abstract view into a view of Index::View type. More...
 
static Tuple constructTuple (const RamDomain *data)
 Construct a typed tuple from a raw data. More...
 

Static Public Attributes

static constexpr size_t Arity = _Arity
 

Protected Attributes

size_t auxiliaryArity
 
VecOwn< Indexindexes
 
Indexmain
 
- Protected Attributes inherited from souffle::interpreter::RelationWrapper
arity_type arity
 
arity_type auxiliaryArity
 
std::string relName
 

Detailed Description

template<size_t _Arity, template< size_t > typename Structure>
class souffle::interpreter::Relation< _Arity, Structure >

A relation, composed of a collection of indexes.

Definition at line 160 of file Relation.h.

Member Typedef Documentation

◆ Attribute

template<size_t _Arity, template< size_t > typename Structure>
using souffle::interpreter::Relation< _Arity, Structure >::Attribute = uint32_t

Definition at line 163 of file Relation.h.

◆ AttributeSet

template<size_t _Arity, template< size_t > typename Structure>
using souffle::interpreter::Relation< _Arity, Structure >::AttributeSet = std::set<Attribute>

Definition at line 164 of file Relation.h.

◆ Index

template<size_t _Arity, template< size_t > typename Structure>
using souffle::interpreter::Relation< _Arity, Structure >::Index = interpreter::Index<Arity, Structure>

Definition at line 165 of file Relation.h.

◆ iterator

template<size_t _Arity, template< size_t > typename Structure>
using souffle::interpreter::Relation< _Arity, Structure >::iterator = typename Index::iterator

Definition at line 168 of file Relation.h.

◆ Tuple

template<size_t _Arity, template< size_t > typename Structure>
using souffle::interpreter::Relation< _Arity, Structure >::Tuple = souffle::Tuple<RamDomain, Arity>

Definition at line 166 of file Relation.h.

◆ View

template<size_t _Arity, template< size_t > typename Structure>
using souffle::interpreter::Relation< _Arity, Structure >::View = typename Index::View

Definition at line 167 of file Relation.h.

Constructor & Destructor Documentation

◆ Relation() [1/2]

template<size_t _Arity, template< size_t > typename Structure>
souffle::interpreter::Relation< _Arity, Structure >::Relation ( size_t  auxiliaryArity,
std::string  name,
const ram::analysis::MinIndexSelection orderSet 
)
inline

Creates a relation, build all necessary indexes.

Definition at line 189 of file Relation.h.

191  {
192  if (set.find(i) == set.end()) {
193  order.push_back(i);
194  }
195  }
196 
197  indexes.push_back(mk<Index>(order));
198  }
199 
200  // Use the first index as default main index
201  main = indexes[0].get();
202  }
203 
204  Relation(Relation& other) = delete;
205 
206  // -- Implement all virtual interface from Wrapper. --
207  // -- Operations defined in this section are not performance-oriented.
208 public:

◆ Relation() [2/2]

template<size_t _Arity, template< size_t > typename Structure>
souffle::interpreter::Relation< _Arity, Structure >::Relation ( Relation< _Arity, Structure > &  other)
delete

Member Function Documentation

◆ __purge()

template<size_t _Arity, template< size_t > typename Structure>
void souffle::interpreter::Relation< _Arity, Structure >::__purge ( )
inline

Clear all indexes.

Definition at line 381 of file Relation.h.

384  {
385  return main->contains(tuple);

◆ __size()

template<size_t _Arity, template< size_t > typename Structure>
size_t souffle::interpreter::Relation< _Arity, Structure >::__size ( ) const
inline

Return number of tuples in relation (full-order)

Definition at line 367 of file Relation.h.

368  {
369  return main->empty();

◆ begin()

template<size_t _Arity, template< size_t > typename Structure>
Iterator souffle::interpreter::Relation< _Arity, Structure >::begin ( ) const
inlineoverridevirtual

Implements souffle::interpreter::RelationWrapper.

Definition at line 274 of file Relation.h.

282  :
283  /**

◆ castView()

template<size_t _Arity, template< size_t > typename Structure>
static View* souffle::interpreter::Relation< _Arity, Structure >::castView ( ViewWrapper view)
inlinestatic

Cast an abstract view into a view of Index::View type.

Definition at line 182 of file Relation.h.

184  : RelationWrapper(Arity, auxiliaryArity, std::move(name)) {

◆ constructTuple()

template<size_t _Arity, template< size_t > typename Structure>
static Tuple souffle::interpreter::Relation< _Arity, Structure >::constructTuple ( const RamDomain data)
inlinestatic

Construct a typed tuple from a raw data.

Definition at line 173 of file Relation.h.

176  {
177  return static_cast<View*>(view);

◆ contains() [1/3]

template<size_t _Arity, template< size_t > typename Structure>
bool souffle::interpreter::Relation< _Arity, Structure >::contains ( const RamDomain data) const
inlineoverridevirtual

Implements souffle::interpreter::RelationWrapper.

Definition at line 223 of file Relation.h.

225  {

◆ contains() [2/3]

template<size_t _Arity, template< size_t > typename Structure>
bool souffle::interpreter::Relation< _Arity, Structure >::contains ( const size_t &  indexPos,
const Tuple low,
const Tuple high 
) const
inline

Tests whether this relation contains any element between the given boundaries.

Definition at line 321 of file Relation.h.

◆ contains() [3/3]

template<size_t _Arity, template< size_t > typename Structure>
bool souffle::interpreter::Relation< _Arity, Structure >::contains ( const Tuple tuple) const
inline

Tests whether this relation contains the given tuple.

Definition at line 314 of file Relation.h.

315  {
316  return indexes[indexPos]->contains(low, high);

◆ createView()

template<size_t _Arity, template< size_t > typename Structure>
IndexViewPtr souffle::interpreter::Relation< _Arity, Structure >::createView ( const size_t &  ) const
inlineoverridevirtual

Obtains a view on an index of this relation, facilitating hint-supported accesses.

This function is virtual because view creation require at least one indirect dispatch.

Implements souffle::interpreter::RelationWrapper.

Definition at line 227 of file Relation.h.

229  {

◆ empty()

template<size_t _Arity, template< size_t > typename Structure>
bool souffle::interpreter::Relation< _Arity, Structure >::empty ( ) const
inline

Check if the relation is empty.

Definition at line 374 of file Relation.h.

375  {
376  for (auto& idx : indexes) {

◆ end()

template<size_t _Arity, template< size_t > typename Structure>
Iterator souffle::interpreter::Relation< _Arity, Structure >::end ( ) const
inlineoverridevirtual

Implements souffle::interpreter::RelationWrapper.

Definition at line 278 of file Relation.h.

282  :
283  /**

◆ exists()

template<size_t _Arity, template< size_t > typename Structure>
bool souffle::interpreter::Relation< _Arity, Structure >::exists ( const Tuple tuple) const
inline

Check if a tuple exists in relation.

Definition at line 390 of file Relation.h.

392  :
393  // Number of height parameters of relation

◆ getIndex()

template<size_t _Arity, template< size_t > typename Structure>
Index* souffle::interpreter::Relation< _Arity, Structure >::getIndex ( size_t  idx)
inline

Definition at line 394 of file Relation.h.

403  : public Relation<2, Eqrel> {

◆ getIndexOrder()

template<size_t _Arity, template< size_t > typename Structure>
Order souffle::interpreter::Relation< _Arity, Structure >::getIndexOrder ( size_t  ) const
inlineoverridevirtual

Return the order of an index.

Implements souffle::interpreter::RelationWrapper.

Definition at line 235 of file Relation.h.

238  :
239  iterator_base(typename Index::iterator iter, Order order)

◆ insert() [1/3]

template<size_t _Arity, template< size_t > typename Structure>
void souffle::interpreter::Relation< _Arity, Structure >::insert ( const RamDomain data)
inlineoverridevirtual

Implements souffle::interpreter::RelationWrapper.

Definition at line 219 of file Relation.h.

221  {

◆ insert() [2/3]

template<size_t _Arity, template< size_t > typename Structure>
void souffle::interpreter::Relation< _Arity, Structure >::insert ( const Relation< Arity, Structure > &  other)
inline

Add all entries of the given relation to this relation.

Definition at line 305 of file Relation.h.

308  {
309  return main->contains(tuple);

◆ insert() [3/3]

template<size_t _Arity, template< size_t > typename Structure>
bool souffle::interpreter::Relation< _Arity, Structure >::insert ( const Tuple tuple)
inline

Add the given tuple to this relation.

Definition at line 292 of file Relation.h.

299  {
300  for (const auto& tuple : other.scan()) {

◆ partitionRange()

template<size_t _Arity, template< size_t > typename Structure>
std::vector<souffle::range<iterator> > souffle::interpreter::Relation< _Arity, Structure >::partitionRange ( const size_t &  indexPos,
const Tuple low,
const Tuple high,
size_t  partitionCount 
) const
inline

Returns a partitioned list of iterators coving elements in range [low, high].

Definition at line 351 of file Relation.h.

354  {

◆ partitionScan()

template<size_t _Arity, template< size_t > typename Structure>
std::vector<souffle::range<iterator> > souffle::interpreter::Relation< _Arity, Structure >::partitionScan ( size_t  partitionCount) const
inline

Returns a partitioned list of iterators for parallel computation.

Definition at line 337 of file Relation.h.

338  {
339  return indexes[indexPos]->range(low, high);

◆ purge()

template<size_t _Arity, template< size_t > typename Structure>
void souffle::interpreter::Relation< _Arity, Structure >::purge ( )
inlineoverridevirtual

Implements souffle::interpreter::RelationWrapper.

Definition at line 215 of file Relation.h.

217  {

◆ range()

template<size_t _Arity, template< size_t > typename Structure>
souffle::range<iterator> souffle::interpreter::Relation< _Arity, Structure >::range ( const size_t &  indexPos,
const Tuple low,
const Tuple high 
) const
inline

Obtains a pair of iterators covering the interval between the two given entries.

Definition at line 344 of file Relation.h.

346  {

◆ scan()

template<size_t _Arity, template< size_t > typename Structure>
souffle::range<iterator> souffle::interpreter::Relation< _Arity, Structure >::scan ( ) const
inline

Obtains a pair of iterators to scan the entire relation.

Return 'raw iterator' that returns tuples in undecoded form.

Definition at line 330 of file Relation.h.

331  {
332  return main->partitionScan(partitionCount);

◆ size()

template<size_t _Arity, template< size_t > typename Structure>
size_t souffle::interpreter::Relation< _Arity, Structure >::size ( ) const
inlineoverridevirtual

Implements souffle::interpreter::RelationWrapper.

Definition at line 231 of file Relation.h.

233  : public RelationWrapper::iterator_base {

◆ swap()

template<size_t _Arity, template< size_t > typename Structure>
void souffle::interpreter::Relation< _Arity, Structure >::swap ( Relation< Arity, Structure > &  other)
inline

Swaps the content of this and the given relation, including the installed indexes.

Definition at line 360 of file Relation.h.

361  {
362  return main->size();

Field Documentation

◆ Arity

template<size_t _Arity, template< size_t > typename Structure>
constexpr size_t souffle::interpreter::Relation< _Arity, Structure >::Arity = _Arity
staticconstexpr

Definition at line 162 of file Relation.h.

◆ auxiliaryArity

template<size_t _Arity, template< size_t > typename Structure>
size_t souffle::interpreter::Relation< _Arity, Structure >::auxiliaryArity
protected

Definition at line 400 of file Relation.h.

◆ indexes

template<size_t _Arity, template< size_t > typename Structure>
VecOwn<Index> souffle::interpreter::Relation< _Arity, Structure >::indexes
protected

◆ main

template<size_t _Arity, template< size_t > typename Structure>
Index* souffle::interpreter::Relation< _Arity, Structure >::main
protected

The documentation for this class was generated from the following file:
souffle::interpreter::Relation::Relation
Relation(size_t auxiliaryArity, std::string name, const ram::analysis::MinIndexSelection &orderSet)
Creates a relation, build all necessary indexes.
Definition: Relation.h:189
souffle::interpreter::Index::empty
bool empty() const
Tests whether this index is empty or not.
Definition: Index.h:221
low
d d low
Definition: htmlJsChartistMin.h:15
high
d high
Definition: htmlJsChartistMin.h:15
souffle::interpreter::Index::contains
bool contains(const Tuple &tuple) const
Tests whether the given tuple is present in this index or not.
Definition: Index.h:251
i
size_t i
Definition: json11.h:663
souffle::interpreter::Relation::View
typename Index::View View
Definition: Relation.h:167
souffle::interpreter::Relation::main
Index * main
Definition: Relation.h:406
iterator_base
souffle::interpreter::Relation::auxiliaryArity
size_t auxiliaryArity
Definition: Relation.h:400
souffle::interpreter::Index::iterator
typename Data::iterator iterator
Definition: Index.h:157
souffle::interpreter::Index::size
size_t size() const
Obtains the number of elements stored in this index.
Definition: Index.h:228
souffle::interpreter::Index::partitionScan
std::vector< souffle::range< iterator > > partitionScan(int partitionCount) const
Retruns a partitioned list of iterators for parallel computation.
Definition: Index.h:279
souffle::interpreter::RelationWrapper::RelationWrapper
RelationWrapper(arity_type arity, arity_type auxiliaryArity, std::string relName)
Definition: Relation.h:58
souffle::interpreter::Relation::indexes
VecOwn< Index > indexes
Definition: Relation.h:403
souffle::interpreter::Relation::Arity
static constexpr size_t Arity
Definition: Relation.h:162