souffle  2.0.2-371-g6315b36
Public Types | Public Member Functions | Private Attributes | Friends
souffle::detail::brie::SparseArrayIter< SparseArray > Struct Template Reference

Iterator type for souffle::SparseArray. More...

#include <Brie.h>

Collaboration diagram for souffle::detail::brie::SparseArrayIter< SparseArray >:
Collaboration graph

Public Types

using array_value_type = typename SparseArray::value_type
 
using index_type = typename SparseArray::index_type
 
using Node = typename SparseArray::Node
 
using value_type = std::pair< index_type, array_value_type >
 

Public Member Functions

bool isEnd () const
 
bool operator!= (const SparseArrayIter &other) const
 
const value_typeoperator* () const
 
SparseArrayIteroperator++ ()
 
SparseArrayIter operator++ (int)
 
const value_typeoperator-> () const
 
SparseArrayIteroperator= (const SparseArrayIter &)=default
 
bool operator== (const SparseArrayIter &other) const
 
void print (std::ostream &out) const
 
 SparseArrayIter ()=default
 
 SparseArrayIter (const Node *first, index_type firstOffset)
 
 SparseArrayIter (const Node *node, value_type value)
 
 SparseArrayIter (const SparseArrayIter &)=default
 

Private Attributes

const Nodenode {}
 
value_type value
 

Friends

std::ostream & operator<< (std::ostream &out, const SparseArrayIter &iter)
 

Detailed Description

template<typename SparseArray>
struct souffle::detail::brie::SparseArrayIter< SparseArray >

Iterator type for souffle::SparseArray.

Definition at line 155 of file Brie.h.

Member Typedef Documentation

◆ array_value_type

Definition at line 158 of file Brie.h.

◆ index_type

template<typename SparseArray >
using souffle::detail::brie::SparseArrayIter< SparseArray >::index_type = typename SparseArray::index_type

Definition at line 157 of file Brie.h.

◆ Node

template<typename SparseArray >
using souffle::detail::brie::SparseArrayIter< SparseArray >::Node = typename SparseArray::Node

Definition at line 156 of file Brie.h.

◆ value_type

template<typename SparseArray >
using souffle::detail::brie::SparseArrayIter< SparseArray >::value_type = std::pair<index_type, array_value_type>

Definition at line 160 of file Brie.h.

Constructor & Destructor Documentation

◆ SparseArrayIter() [1/4]

template<typename SparseArray >
souffle::detail::brie::SparseArrayIter< SparseArray >::SparseArrayIter ( )
default

◆ SparseArrayIter() [2/4]

template<typename SparseArray >
souffle::detail::brie::SparseArrayIter< SparseArray >::SparseArrayIter ( const SparseArrayIter< SparseArray > &  )
default

◆ SparseArrayIter() [3/4]

template<typename SparseArray >
souffle::detail::brie::SparseArrayIter< SparseArray >::SparseArrayIter ( const Node node,
value_type  value 
)
inline

Definition at line 166 of file Brie.h.

172 {

◆ SparseArrayIter() [4/4]

template<typename SparseArray >
souffle::detail::brie::SparseArrayIter< SparseArray >::SparseArrayIter ( const Node first,
index_type  firstOffset 
)
inline

Definition at line 168 of file Brie.h.

172  {
173  return !(*this == other);
174  }
175 
176  // the deref operator as required by the iterator concept
177  const value_type& operator*() const {
178  return value;

Member Function Documentation

◆ isEnd()

template<typename SparseArray >
bool souffle::detail::brie::SparseArrayIter< SparseArray >::isEnd ( ) const
inline

Definition at line 283 of file Brie.h.

283  :
284  // a pointer to the leaf node currently processed or null (end)
285  const Node* node{};

◆ operator!=()

template<typename SparseArray >
bool souffle::detail::brie::SparseArrayIter< SparseArray >::operator!= ( const SparseArrayIter< SparseArray > &  other) const
inline

Definition at line 188 of file Brie.h.

193  {

◆ operator*()

template<typename SparseArray >
const value_type& souffle::detail::brie::SparseArrayIter< SparseArray >::operator* ( ) const
inline

Definition at line 193 of file Brie.h.

193  {
194  x++;
195  } while (x < SparseArray::NUM_CELLS && node->cell[x].value == array_value_type());

◆ operator++() [1/2]

template<typename SparseArray >
SparseArrayIter& souffle::detail::brie::SparseArrayIter< SparseArray >::operator++ ( )
inline

Definition at line 203 of file Brie.h.

213  {
214  // search for next child
215  while (x < SparseArray::NUM_CELLS) {
216  if (node->cell[x].ptr != nullptr) {
217  break;
218  }
219  x++;
220  }
221 
222  // pick next step
223  if (x < SparseArray::NUM_CELLS) {
224  // going down
225  node = node->cell[x].ptr;
226  value.first &= SparseArray::getLevelMask(level + 1);
227  value.first |= x << (SparseArray::BIT_PER_STEP * level);
228  level--;
229  x = 0;
230  } else {
231  // going up
232  node = node->parent;
233  level++;
234 
235  // get current index on this level
236  x = SparseArray::getIndex(brie_element_type(value.first), level);
237  x++; // go one step further
238  }
239  }
240 
241  // check whether it is the end of range
242  if (node == nullptr) {
243  return *this;
244  }
245 
246  // search the first value in this node
247  x = 0;
248  while (node->cell[x].value == array_value_type()) {
249  x++;
250  }
251 
252  // update value
253  value.first |= x;
254  value.second = node->cell[x].value;
255 
256  // done
257  return *this;
258  }
259 
261  auto cpy = *this;
262  ++(*this);
263  return cpy;
264  }
265 
266  // True if this iterator is passed the last element.
267  bool isEnd() const {
268  return node == nullptr;
269  }
270 
271  // enables this iterator core to be printed (for debugging)
272  void print(std::ostream& out) const {
273  // `StreamUtil.h` defines an overload for `pair`, but we can't rely on it b/c
274  // it's disabled if `__EMBEDDED__` is defined.

◆ operator++() [2/2]

template<typename SparseArray >
SparseArrayIter souffle::detail::brie::SparseArrayIter< SparseArray >::operator++ ( int  )
inline

Definition at line 276 of file Brie.h.

278  {
279  iter.print(out);
280  return out;

◆ operator->()

template<typename SparseArray >
const value_type* souffle::detail::brie::SparseArrayIter< SparseArray >::operator-> ( ) const
inline

Definition at line 198 of file Brie.h.

198  {
199  // update value and be done
200  value.first = (value.first & ~SparseArray::INDEX_MASK) | x;

References souffle::detail::brie::SparseArrayIter< SparseArray >::node, and souffle::detail::brie::SparseArrayIter< SparseArray >::value.

◆ operator=()

template<typename SparseArray >
SparseArrayIter& souffle::detail::brie::SparseArrayIter< SparseArray >::operator= ( const SparseArrayIter< SparseArray > &  )
default

◆ operator==()

template<typename SparseArray >
bool souffle::detail::brie::SparseArrayIter< SparseArray >::operator== ( const SparseArrayIter< SparseArray > &  other) const
inline

Definition at line 181 of file Brie.h.

182  {
183  return &value;
184  }
185 

References souffle::detail::brie::SparseArrayIter< SparseArray >::value.

◆ print()

template<typename SparseArray >
void souffle::detail::brie::SparseArrayIter< SparseArray >::print ( std::ostream &  out) const
inline

Definition at line 288 of file Brie.h.

Friends And Related Function Documentation

◆ operator<<

template<typename SparseArray >
std::ostream& operator<< ( std::ostream &  out,
const SparseArrayIter< SparseArray > &  iter 
)
friend

Definition at line 294 of file Brie.h.

323  {

Field Documentation

◆ node

template<typename SparseArray >
const Node* souffle::detail::brie::SparseArrayIter< SparseArray >::node {}
private

◆ value

template<typename SparseArray >
value_type souffle::detail::brie::SparseArrayIter< SparseArray >::value
private

The documentation for this struct was generated from the following file:
souffle::SparseArray::getIndex
static index_type getIndex(brie_element_type a, unsigned level)
Obtains the index within the arrays of cells of a given index on a given level of the internally main...
Definition: Brie.h:1498
souffle::SparseArray::getLevelMask
static index_type getLevelMask(unsigned level)
Computes the bit-mask to be applicable to obtain the offset of a node on a given tree level.
Definition: Brie.h:1506
souffle::detail::brie::SparseArrayIter::isEnd
bool isEnd() const
Definition: Brie.h:283
souffle::detail::brie::SparseArrayIter::SparseArrayIter
SparseArrayIter()=default
souffle::detail::brie::SparseArrayIter::value
value_type value
Definition: Brie.h:304
souffle::detail::brie::brie_element_type
RamDomain brie_element_type
Definition: Brie.h:84
souffle::detail::brie::SparseArrayIter::Node
typename SparseArray::Node Node
Definition: Brie.h:156
souffle::detail::brie::SparseArrayIter::array_value_type
typename SparseArray::value_type array_value_type
Definition: Brie.h:158
souffle::detail::brie::SparseArrayIter::value_type
std::pair< index_type, array_value_type > value_type
Definition: Brie.h:160
souffle::SparseArray::BIT_PER_STEP
static constexpr int BIT_PER_STEP
Definition: Brie.h:347
souffle::SparseArray::NUM_CELLS
static constexpr int NUM_CELLS
Definition: Brie.h:348
souffle::detail::brie::SparseArrayIter::operator++
SparseArrayIter & operator++()
Definition: Brie.h:203
souffle::detail::brie::SparseArrayIter::print
void print(std::ostream &out) const
Definition: Brie.h:288
souffle::detail::brie::SparseArrayIter::operator*
const value_type & operator*() const
Definition: Brie.h:193
souffle::detail::brie::SparseArrayIter::node
const Node * node
Definition: Brie.h:301