souffle  2.0.2-371-g6315b36
Data Structures | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends
souffle::SparseArray< T, BITS, merge_op, copy_op > Class Template Reference

A sparse array simulates an array associating to every element of uint32_t an element of a generic type T. More...

#include <Brie.h>

Collaboration diagram for souffle::SparseArray< T, BITS, merge_op, copy_op >:
Collaboration graph

Data Structures

union  Cell
 The value stored in a single cell of a inner or leaf node. More...
 
struct  FirstInfoSnapshot
 A struct summarizing the state of the first node reference. More...
 
struct  Node
 The node type of the internally maintained tree. More...
 
struct  op_context
 A struct to be utilized as a local, temporal context by client code to speed up the execution of various operations (optional parameter). More...
 
struct  RootInfo
 A struct describing all the information required by the container class to manage the wrapped up tree. More...
 
struct  RootInfoSnapshot
 A struct to cover a snapshot of the root node state. More...
 

Public Types

using atomic_value_type = std::atomic< value_type >
 
using index_type = key_type
 
using iterator = SparseArrayIter< this_t >
 
using value_type = T
 

Public Member Functions

void addAll (const SparseArray &other)
 Adds all the values stored in the given array to this array. More...
 
iterator begin () const
 Obtains an iterator referencing the first non-default element or end in case there are no such elements. More...
 
void clear ()
 Resets the content of this array to default values for each contained element. More...
 
void dump (bool detail=false, std::ostream &out=std::cout) const
 A debug utility printing the internal structure of this sparse array to the given output stream. More...
 
bool empty () const
 Tests whether this sparse array is empty, thus it only contains default-values, or not. More...
 
iterator end () const
 An iterator referencing the position after the last non-default element. More...
 
iterator find (index_type i) const
 An operation to obtain an iterator referencing an element addressed by the given index. More...
 
iterator find (index_type i, op_context &ctxt) const
 An operation to obtain an iterator referencing an element addressed by the given index. More...
 
value_typeget (index_type i)
 Obtains a mutable reference to the value addressed by the given index. More...
 
value_typeget (index_type i, op_context &ctxt)
 Obtains a mutable reference to the value addressed by the given index. More...
 
atomic_value_typegetAtomic (index_type i)
 Obtains a mutable reference to the atomic value addressed by the given index. More...
 
atomic_value_typegetAtomic (index_type i, op_context &ctxt)
 Obtains a mutable reference to the atomic value addressed by the given index. More...
 
std::size_t getMemoryUsage () const
 Computes the total memory usage of this data structure. More...
 
value_type lookup (index_type i) const
 Obtains the value associated to index i – which might be the default value of the covered type if the value hasn't been defined previously. More...
 
value_type lookup (index_type i, op_context &ctxt) const
 Obtains the value associated to index i – which might be the default value of the covered type if the value hasn't been defined previously. More...
 
iterator lowerBound (index_type i) const
 An operation obtaining the smallest non-default element such that it's index is >= the given index. More...
 
iterator lowerBound (index_type i, op_context &) const
 An operation obtaining the smallest non-default element such that it's index is >= the given index. More...
 
SparseArrayoperator= (const SparseArray &other)
 An assignment creating a deep copy of the handed in array structure (utilizing the copy functor provided as a template parameter). More...
 
SparseArrayoperator= (SparseArray &&other)
 An assignment operation taking over ownership from a r-value reference to a sparse array. More...
 
value_type operator[] (index_type i) const
 Obtains the value associated to index i – which might be the default value of the covered type if the value hasn't been defined previously. More...
 
std::size_t size () const
 Computes the number of non-empty elements within this sparse array. More...
 
 SparseArray ()
 A default constructor creating an empty sparse array. More...
 
 SparseArray (const SparseArray &other)
 A copy constructor for sparse arrays. More...
 
 SparseArray (SparseArray &&other)
 A r-value based copy constructor for sparse arrays. More...
 
void update (index_type i, const value_type &val)
 Updates the value stored in cell i by the given value. More...
 
void update (index_type i, const value_type &val, op_context &ctxt)
 Updates the value stored in cell i by the given value. More...
 
iterator upperBound (index_type i) const
 An operation obtaining the smallest non-default element such that it's index is greater the given index. More...
 
iterator upperBound (index_type i, op_context &ctxt) const
 An operation obtaining the smallest non-default element such that it's index is greater the given index. More...
 
 ~SparseArray ()
 A destructor for sparse arrays clearing up the internally maintained data structure. More...
 

Private Types

using key_type = uint64_t
 
using this_t = SparseArray< T, BITS, merge_op, copy_op >
 

Private Member Functions

void clean ()
 Conducts a cleanup of the internal tree structure. More...
 
void dump (bool detailed, std::ostream &out, const Node &node, int level, index_type offset, int indent=0) const
 An internal debug utility printing the internal structure of this sparse array to the given output stream. More...
 
FirstInfoSnapshot getFirstInfo () const
 Obtains a snapshot of the current first-node information. More...
 
uint64_t getFirstVersion () const
 Obtains the current version number of the first node information. More...
 
CellgetLeaf (index_type i, op_context &ctxt)
 An internal function capable of navigating to a given leaf node entry. More...
 
RootInfoSnapshot getRootInfo () const
 Obtains a snapshot of the current root information. More...
 
uint64_t getRootVersion () const
 Obtains the current version of the root. More...
 
bool inBoundaries (index_type a) const
 Tests whether the given index is covered by the boundaries defined by the hight and offset of the internally maintained tree. More...
 
void raiseLevel ()
 Raises the level of this tree by one level. More...
 
void raiseLevel (RootInfoSnapshot &info)
 Attempts to raise the height of this tree based on the given root node information and updates the root-info snapshot correspondingly. More...
 
bool tryUpdateFirstInfo (const FirstInfoSnapshot &info)
 Updates the information stored regarding the first node in a concurrent setting utilizing a optimistic locking approach. More...
 
bool tryUpdateRootInfo (const RootInfoSnapshot &info)
 Updates the current root information based on the handed in modified snapshot instance if the version number of the snapshot still corresponds to the current version. More...
 

Static Private Member Functions

static Nodeclone (const Node *node, int level)
 Clones the given node and all its sub-nodes. More...
 
static NodefindFirst (Node *node, int level)
 Obtains the left-most leaf-node of the tree rooted by the given node with the given level. More...
 
static void freeNodes (Node *node, int level)
 Destroys a node and all its sub-nodes recursively. More...
 
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 maintained tree. More...
 
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. More...
 
static std::size_t getMemoryUsage (const Node *node, int level)
 Computes the memory usage of the given sub-tree. More...
 
static bool inBoundaries (index_type a, uint32_t levels, index_type offset)
 Tests whether the given index is within the boundaries defined by the given tree hight and offset. More...
 
static void merge (const Node *parent, Node *&trg, const Node *src, int levels)
 A static operation utilized internally for merging sub-trees recursively. More...
 
static NodenewNode ()
 Creates new nodes and initializes them with 0. More...
 

Private Attributes

union {
   volatile RootInfo   synced
 
   RootInfo   unsynced
 
}; 
 

Static Private Attributes

static constexpr int BIT_PER_STEP = BITS
 
static constexpr key_type INDEX_MASK = NUM_CELLS - 1
 
static constexpr int NUM_CELLS = 1 << BIT_PER_STEP
 

Friends

template<typename A >
struct detail::brie::SparseArrayIter
 

Detailed Description

template<typename T, unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
class souffle::SparseArray< T, BITS, merge_op, copy_op >

A sparse array simulates an array associating to every element of uint32_t an element of a generic type T.

Any non-defined element will be default-initialized utilizing the detail::brie::default_factory functor.

Internally the array is organized as a balanced tree. The leaf level of the tree corresponds to the elements of the represented array. Inner nodes utilize individual bits of the indices to reference sub-trees. For efficiency reasons, only the minimal sub-tree required to cover all non-null / non-default values stored in the array is maintained. Furthermore, several levels of nodes are aggreated in a B-tree like fashion to inprove cache utilization and reduce the number of steps required for lookup and insert operations.

Template Parameters
Tthe type of the stored elements
BITSthe number of bits consumed per node-level e.g. if it is set to 3, the resulting tree will be of a degree of 2^3=8, and thus 8 child-pointers will be stored in each inner node and as many values will be stored in each leaf node.
merge_opthe functor to be utilized when merging the content of two instances of this type.
copy_opa functor to be applied to each stored value when copying an instance of this array. For instance, this is utilized by the trie implementation to create a clone of each sub-tree instead of preserving the original pointer.

Definition at line 339 of file Brie.h.

Member Typedef Documentation

◆ atomic_value_type

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
using souffle::SparseArray< T, BITS, merge_op, copy_op >::atomic_value_type = std::atomic<value_type>

Definition at line 359 of file Brie.h.

◆ index_type

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
using souffle::SparseArray< T, BITS, merge_op, copy_op >::index_type = key_type

Definition at line 353 of file Brie.h.

◆ iterator

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
using souffle::SparseArray< T, BITS, merge_op, copy_op >::iterator = SparseArrayIter<this_t>

Definition at line 1096 of file Brie.h.

◆ key_type

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
using souffle::SparseArray< T, BITS, merge_op, copy_op >::key_type = uint64_t
private

Definition at line 344 of file Brie.h.

◆ this_t

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
using souffle::SparseArray< T, BITS, merge_op, copy_op >::this_t = SparseArray<T, BITS, merge_op, copy_op>
private

Definition at line 343 of file Brie.h.

◆ value_type

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
using souffle::SparseArray< T, BITS, merge_op, copy_op >::value_type = T

Definition at line 356 of file Brie.h.

Constructor & Destructor Documentation

◆ SparseArray() [1/3]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
souffle::SparseArray< T, BITS, merge_op, copy_op >::SparseArray ( )
inline

A default constructor creating an empty sparse array.

Definition at line 419 of file Brie.h.

425 : unsynced(RootInfo{other.unsynced.root, other.unsynced.levels, other.unsynced.offset,

◆ SparseArray() [2/3]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
souffle::SparseArray< T, BITS, merge_op, copy_op >::SparseArray ( const SparseArray< T, BITS, merge_op, copy_op > &  other)
inline

A copy constructor for sparse arrays.

It creates a deep copy of the data structure maintained by the handed in array instance.

Definition at line 426 of file Brie.h.

426  {
427  other.unsynced.root = nullptr;
428  other.unsynced.levels = 0;
429  other.unsynced.first = nullptr;
430  }
431 
432  /**
433  * A destructor for sparse arrays clearing up the internally

◆ SparseArray() [3/3]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
souffle::SparseArray< T, BITS, merge_op, copy_op >::SparseArray ( SparseArray< T, BITS, merge_op, copy_op > &&  other)
inline

A r-value based copy constructor for sparse arrays.

It takes over ownership of the structure maintained by the handed in array.

Definition at line 440 of file Brie.h.

445  {
446  if (this == &other) return *this;

◆ ~SparseArray()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
souffle::SparseArray< T, BITS, merge_op, copy_op >::~SparseArray ( )
inline

A destructor for sparse arrays clearing up the internally maintained data structure.

Definition at line 452 of file Brie.h.

454  {

Member Function Documentation

◆ addAll()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::addAll ( const SparseArray< T, BITS, merge_op, copy_op > &  other)
inline

Adds all the values stored in the given array to this array.

Definition at line 1042 of file Brie.h.

1047  {
1048  // get X coordinate
1049  auto x = getIndex(brie_element_type(other.unsynced.offset), level);
1050 
1051  // decrease level counter
1052  --level;
1053 
1054  // check next node
1055  Node*& next = (*node)->cell[x].ptr;
1056  if (!next) {
1057  // create new sub-tree
1058  next = newNode();
1059  next->parent = *node;
1060  }
1061 
1062  // continue one level below
1063  node = &next;
1064  }
1065 
1066  // merge sub-branches from here
1067  merge((*node)->parent, *node, other.unsynced.root, level);
1068 
1069  // update first
1070  if (unsynced.firstOffset > other.unsynced.firstOffset) {
1071  unsynced.first = findFirst(*node, level);
1072  unsynced.firstOffset = other.unsynced.firstOffset;
1073  }
1074  }
1075 
1076  // ---------------------------------------------------------------------
1077  // Iterator
1078  // ---------------------------------------------------------------------
1079 
1080  using iterator = SparseArrayIter<this_t>;
1081 
1082  /**
1083  * Obtains an iterator referencing the first non-default element or end in
1084  * case there are no such elements.
1085  */
1086  iterator begin() const {
1088  }
1089 
1090  /**

Referenced by souffle::SparseBitMap< BITS >::size().

◆ begin()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::begin ( ) const
inline

Obtains an iterator referencing the first non-default element or end in case there are no such elements.

Definition at line 1102 of file Brie.h.

1102  {
1103  op_context ctxt;
1104  return find(i, ctxt);

Referenced by souffle::SparseBitMap< BITS >::addAll().

◆ clean()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::clean ( )
inlineprivate

Conducts a cleanup of the internal tree structure.

Definition at line 1352 of file Brie.h.

1355  {
1356  copy_op copy;

◆ clear()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::clear ( )
inline

Resets the content of this array to default values for each contained element.

Definition at line 572 of file Brie.h.

574  :
575  // ---------------------------------------------------------------------
576  // Optimistic Locking of Root-Level Infos
577  // ---------------------------------------------------------------------
578 

◆ clone()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static Node* souffle::SparseArray< T, BITS, merge_op, copy_op >::clone ( const Node node,
int  level 
)
inlinestaticprivate

Clones the given node and all its sub-nodes.

Definition at line 1361 of file Brie.h.

1364  {
1365  auto cur = clone(node->cell[i].ptr, level - 1);
1366  if (cur != nullptr) {
1367  cur->parent = res;
1368  }
1369  res->cell[i].ptr = cur;
1370  }
1371 
1372  // done
1373  return res;
1374  }
1375 
1376  /**
1377  * Obtains the left-most leaf-node of the tree rooted by the given node
1378  * with the given level.
1379  */
1380  static Node* findFirst(Node* node, int level) {
1381  while (level > 0) {
1382  bool found = false;
1383  for (int i = 0; i < NUM_CELLS; i++) {
1384  Node* cur = node->cell[i].ptr;
1385  if (cur) {
1386  node = cur;
1387  --level;
1388  found = true;
1389  break;
1390  }

◆ dump() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::dump ( bool  detail = false,
std::ostream &  out = std::cout 
) const
inline

A debug utility printing the internal structure of this sparse array to the given output stream.

Definition at line 1312 of file Brie.h.

1316  {
1317  return new Node();
1318  }
1319 
1320  /**
1321  * Destroys a node and all its sub-nodes recursively.
1322  */

◆ dump() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::dump ( bool  detailed,
std::ostream &  out,
const Node node,
int  level,
index_type  offset,
int  indent = 0 
) const
inlineprivate

An internal debug utility printing the internal structure of this sparse array to the given output stream.

Definition at line 1279 of file Brie.h.

1279  {
1280  dump(detailed, out, *node.cell[i].ptr, level - 1,
1281  offset + (i * (index_type(1) << (level * BIT_PER_STEP))), indent + 1);
1282  } else if (detailed) {
1283  auto low = offset + (i * (1 << (level * BIT_PER_STEP)));
1284  auto hig = low + ~getLevelMask(level);
1285  out << times("\t", indent + 1) << i << ": empty range " << low << " - " << hig << "\n";
1286  }
1287  }
1288  }
1289  out << "\n";
1290  }
1291 
1292 public:
1293  /**
1294  * A debug utility printing the internal structure of this sparse array to the given output stream.
1295  */
1296  void dump(bool detail = false, std::ostream& out = std::cout) const {
1297  if (!unsynced.root) {
1298  out << " - empty - \n";
1299  return;
1300  }
1301  out << "root: " << unsynced.root << "\n";
1302  out << "offset: " << unsynced.offset << "\n";
1303  out << "first: " << unsynced.first << "\n";
1304  out << "fist offset: " << unsynced.firstOffset << "\n";
1305  dump(detail, out, *unsynced.root, unsynced.levels, unsynced.offset);
1306  }

◆ empty()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
bool souffle::SparseArray< T, BITS, merge_op, copy_op >::empty ( ) const
inline

Tests whether this sparse array is empty, thus it only contains default-values, or not.

Definition at line 509 of file Brie.h.

513  :
514  /**

◆ end()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::end ( ) const
inline

An iterator referencing the position after the last non-default element.

Definition at line 1109 of file Brie.h.

1113  {

◆ find() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::find ( index_type  i) const
inline

An operation to obtain an iterator referencing an element addressed by the given index.

If the corresponding element is a non-default value, a corresponding iterator will be returned. Otherwise end() will be returned.

Definition at line 1118 of file Brie.h.

1121  {

Referenced by souffle::SparseBitMap< BITS >::end().

◆ find() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::find ( index_type  i,
op_context ctxt 
) const
inline

An operation to obtain an iterator referencing an element addressed by the given index.

If the corresponding element is a non-default value, a corresponding iterator will be returned. Otherwise end() will be returned. A operation context can be provided for exploiting temporal locality.

Definition at line 1129 of file Brie.h.

1136  {
1137  // get X coordinate
1138  auto x = getIndex(i, level);
1139 
1140  // decrease level counter
1141  --level;
1142 
1143  // check next node
1144  Node* next = node->cell[x].ptr;
1145 
1146  // check next step
1147  if (!next) return end();
1148 
1149  // continue one level below
1150  node = next;
1151  }
1152 
1153  // register in context
1154  ctxt.lastNode = node;
1155  ctxt.lastIndex = (i & ~INDEX_MASK);
1156 
1157  // check whether there is a proper entry
1158  value_type value = node->cell[i & INDEX_MASK].value;
1159  if (value == value_type{}) {
1160  return end();
1161  }
1162 
1163  // return iterator pointing to cell
1164  return iterator(node, std::make_pair(i, value));
1165  }
1166 
1167  /**
1168  * An operation obtaining the smallest non-default element such that it's index is >=
1169  * the given index.
1170  */
1171  iterator lowerBound(index_type i) const {
1172  op_context ctxt;
1173  return lowerBound(i, ctxt);
1174  }
1175 
1176  /**
1177  * An operation obtaining the smallest non-default element such that it's index is >=
1178  * the given index. A operation context can be provided for exploiting temporal locality.
1179  */
1180  iterator lowerBound(index_type i, op_context&) const {
1181  // check whether it is empty

◆ findFirst()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static Node* souffle::SparseArray< T, BITS, merge_op, copy_op >::findFirst ( Node node,
int  level 
)
inlinestaticprivate

Obtains the left-most leaf-node of the tree rooted by the given node with the given level.

Definition at line 1396 of file Brie.h.

1402  {
1403  // something went wrong when we pass that line
1404  assert(unsynced.levels < (sizeof(index_type) * 8 / BITS) + 1);
1405 
1406  // create new root
1407  Node* node = newNode();
1408  node->parent = nullptr;
1409 
1410  // insert existing root as child
1412  node->cell[x].ptr = unsynced.root;

◆ freeNodes()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static void souffle::SparseArray< T, BITS, merge_op, copy_op >::freeNodes ( Node node,
int  level 
)
inlinestaticprivate

Destroys a node and all its sub-nodes recursively.

Definition at line 1339 of file Brie.h.

1345  {
1346  // support null-pointers
1347  if (node == nullptr) {

◆ get() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
value_type& souffle::SparseArray< T, BITS, merge_op, copy_op >::get ( index_type  i)
inline

Obtains a mutable reference to the value addressed by the given index.

Parameters
ithe index of the element to be addressed
Returns
a mutable reference to the corresponding element

Definition at line 744 of file Brie.h.

750  {

◆ get() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
value_type& souffle::SparseArray< T, BITS, merge_op, copy_op >::get ( index_type  i,
op_context ctxt 
)
inline

Obtains a mutable reference to the value addressed by the given index.

Parameters
ithe index of the element to be addressed
ctxta operation context to exploit state-less temporal locality
Returns
a mutable reference to the corresponding element

Definition at line 756 of file Brie.h.

762  {

◆ getAtomic() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
atomic_value_type& souffle::SparseArray< T, BITS, merge_op, copy_op >::getAtomic ( index_type  i)
inline

Obtains a mutable reference to the atomic value addressed by the given index.

Parameters
ithe index of the element to be addressed
Returns
a mutable reference to the corresponding element

Definition at line 766 of file Brie.h.

766  :
767  /**
768  * An internal function capable of navigating to a given leaf node entry.
769  * If the cell does not exist yet it will be created as a side-effect.

Referenced by souffle::SparseBitMap< BITS >::empty().

◆ getAtomic() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
atomic_value_type& souffle::SparseArray< T, BITS, merge_op, copy_op >::getAtomic ( index_type  i,
op_context ctxt 
)
inline

Obtains a mutable reference to the atomic value addressed by the given index.

Parameters
ithe index of the element to be addressed
ctxta operation context to exploit state-less temporal locality
Returns
a mutable reference to the corresponding element

Definition at line 778 of file Brie.h.

786  {

◆ getFirstInfo()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
FirstInfoSnapshot souffle::SparseArray< T, BITS, merge_op, copy_op >::getFirstInfo ( ) const
inlineprivate

Obtains a snapshot of the current first-node information.

Definition at line 694 of file Brie.h.

701  {
702  // check mod counter
703  uintptr_t version = info.version;
704 
705  // temporary update first pointer to point to uneven value (lock-out)
706  if (!__sync_bool_compare_and_swap(&synced.first, (Node*)version, (Node*)(version + 1))) {
707  return false;
708  }
709 
710  // conduct update

◆ getFirstVersion()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
uint64_t souffle::SparseArray< T, BITS, merge_op, copy_op >::getFirstVersion ( ) const
inlineprivate

Obtains the current version number of the first node information.

Definition at line 686 of file Brie.h.

701  {

◆ getIndex()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static index_type souffle::SparseArray< T, BITS, merge_op, copy_op >::getIndex ( brie_element_type  a,
unsigned  level 
)
inlinestaticprivate

Obtains the index within the arrays of cells of a given index on a given level of the internally maintained tree.

Definition at line 1498 of file Brie.h.

1502  {

◆ getLeaf()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
Cell& souffle::SparseArray< T, BITS, merge_op, copy_op >::getLeaf ( index_type  i,
op_context ctxt 
)
inlineprivate

An internal function capable of navigating to a given leaf node entry.

If the cell does not exist yet it will be created as a side-effect.

Parameters
ithe index of the requested cell
ctxta operation context to exploit state-less temporal locality
Returns
a reference to the requested cell

Definition at line 791 of file Brie.h.

795  {
796  // success -- finish get call
797 
798  // update first
799  auto firstInfo = getFirstInfo();
800  while (info.offset < firstInfo.offset) {
801  firstInfo.node = info.root;
802  firstInfo.offset = info.offset;
803  if (!tryUpdateFirstInfo(firstInfo)) {
804  // there was some concurrent update => check again
805  firstInfo = getFirstInfo();
806  }
807  }
808 
809  // return reference to proper cell
810  return info.root->cell[i & INDEX_MASK];
811  }
812 
813  // somebody else was faster => use standard insertion procedure
814  delete info.root;
815 
816  // retrieve new root info
817  info = getRootInfo();
818 
819  // make sure there is a root
820  assert(info.root);
821  }
822 
823  // for all other inserts
824  // - check boundary
825  // - navigate to node
826  // - insert value
827 
828  // check boundaries
829  while (!inBoundaries(i, info.levels, info.offset)) {
830  // boundaries need to be expanded by growing upwards
831  raiseLevel(info); // try raising level unless someone else did already
832  // update root info
833  info = getRootInfo();
834  }
835 
836  // navigate to node
837  Node* node = info.root;
838  unsigned level = info.levels;
839  while (level != 0) {
840  // get X coordinate
841  auto x = getIndex(brie_element_type(i), level);
842 
843  // decrease level counter
844  --level;
845 
846  // check next node
847  std::atomic<Node*>& aNext = node->cell[x].aptr;
848  Node* next = aNext;
849  if (!next) {
850  // create new sub-tree
851  Node* newNext = newNode();
852  newNext->parent = node;
853 
854  // try to update next
855  if (!aNext.compare_exchange_strong(next, newNext)) {
856  // some other thread was faster => use updated next
857  delete newNext;
858  } else {
859  // the locally created next is the new next
860  next = newNext;
861 
862  // update first
863  if (level == 0) {
864  // compute offset of this node
865  auto off = i & ~INDEX_MASK;
866 
867  // fast over-approximation of whether a update is necessary
868  if (off < unsynced.firstOffset) {
869  // update first reference if this one is the smallest
870  auto first_info = getFirstInfo();
871  while (off < first_info.offset) {
872  first_info.node = next;
873  first_info.offset = off;
874  if (!tryUpdateFirstInfo(first_info)) {
875  // there was some concurrent update => check again
876  first_info = getFirstInfo();
877  }
878  }
879  }
880  }
881  }
882 
883  // now next should be defined
884  assert(next);
885  }
886 
887  // continue one level below
888  node = next;
889  }
890 
891  // update context
892  ctxt.lastIndex = (i & ~INDEX_MASK);
893  ctxt.lastNode = node;
894 
895  // return reference to cell
896  return node->cell[i & INDEX_MASK];
897  }
898 
899 public:
900  /**
901  * Updates the value stored in cell i by the given value.
902  */
903  void update(index_type i, const value_type& val) {
904  op_context ctxt;
905  update(i, val, ctxt);
906  }
907 
908  /**
909  * Updates the value stored in cell i by the given value. A operation
910  * context can be provided for exploiting temporal locality.
911  */
912  void update(index_type i, const value_type& val, op_context& ctxt) {
913  get(i, ctxt) = val;

◆ getLevelMask()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static index_type souffle::SparseArray< T, BITS, merge_op, copy_op >::getLevelMask ( unsigned  level)
inlinestaticprivate

Computes the bit-mask to be applicable to obtain the offset of a node on a given tree level.

Definition at line 1506 of file Brie.h.

1515  {};

◆ getMemoryUsage() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
std::size_t souffle::SparseArray< T, BITS, merge_op, copy_op >::getMemoryUsage ( ) const
inline

Computes the total memory usage of this data structure.

Definition at line 555 of file Brie.h.

556  {
557  clean();
558  unsynced.root = nullptr;
559  unsynced.levels = 0;
560  unsynced.first = nullptr;
561  unsynced.firstOffset = std::numeric_limits<index_type>::max();
562  }
563 
564  /**
565  * A struct to be utilized as a local, temporal context by client code
566  * to speed up the execution of various operations (optional parameter).

◆ getMemoryUsage() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static std::size_t souffle::SparseArray< T, BITS, merge_op, copy_op >::getMemoryUsage ( const Node node,
int  level 
)
inlinestaticprivate

Computes the memory usage of the given sub-tree.

Definition at line 533 of file Brie.h.

535  :
536  /**
537  * Computes the total memory usage of this data structure.
538  */
539  std::size_t getMemoryUsage() const {
540  // the memory of the wrapper class
541  std::size_t res = sizeof(*this);
542 
543  // add nodes
544  if (unsynced.root) {
546  }
547 
548  // done
549  return res;

Referenced by souffle::SparseBitMap< BITS >::clear().

◆ getRootInfo()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
RootInfoSnapshot souffle::SparseArray< T, BITS, merge_op, copy_op >::getRootInfo ( ) const
inlineprivate

Obtains a snapshot of the current root information.

Definition at line 620 of file Brie.h.

634  {
635  // check mod counter
636  uintptr_t version = info.version;
637 
638  // update root to invalid pointer (ending with 1)
639  if (!__sync_bool_compare_and_swap(&synced.root, (Node*)version, (Node*)(version + 1))) {

◆ getRootVersion()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
uint64_t souffle::SparseArray< T, BITS, merge_op, copy_op >::getRootVersion ( ) const
inlineprivate

Obtains the current version of the root.

Definition at line 612 of file Brie.h.

634  {

◆ inBoundaries() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
bool souffle::SparseArray< T, BITS, merge_op, copy_op >::inBoundaries ( index_type  a) const
inlineprivate

Tests whether the given index is covered by the boundaries defined by the hight and offset of the internally maintained tree.

Definition at line 1481 of file Brie.h.

1482  {
1483  return (a & (INDEX_MASK << (level * BIT_PER_STEP))) >> (level * BIT_PER_STEP);

◆ inBoundaries() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static bool souffle::SparseArray< T, BITS, merge_op, copy_op >::inBoundaries ( index_type  a,
uint32_t  levels,
index_type  offset 
)
inlinestaticprivate

Tests whether the given index is within the boundaries defined by the given tree hight and offset.

Definition at line 1489 of file Brie.h.

1490  {
1491  if (level > (sizeof(index_type) * 8 / BITS)) return 0;
1492  return (~(index_type(0)) << (level * BIT_PER_STEP));

◆ lookup() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
value_type souffle::SparseArray< T, BITS, merge_op, copy_op >::lookup ( index_type  i) const
inline

Obtains the value associated to index i – which might be the default value of the covered type if the value hasn't been defined previously.

Definition at line 946 of file Brie.h.

949  {

◆ lookup() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
value_type souffle::SparseArray< T, BITS, merge_op, copy_op >::lookup ( index_type  i,
op_context ctxt 
) const
inline

Obtains the value associated to index i – which might be the default value of the covered type if the value hasn't been defined previously.

A operation context can be provided for exploiting temporal locality.

Definition at line 957 of file Brie.h.

981  :
982  /**
983  * A static operation utilized internally for merging sub-trees recursively.
984  *
985  * @param parent the parent node of the current merge operation
986  * @param trg a reference to the pointer the cloned node should be stored to
987  * @param src the node to be cloned
988  * @param levels the height of the cloned node
989  */
990  static void merge(const Node* parent, Node*& trg, const Node* src, int levels) {
991  // if other side is null => done
992  if (src == nullptr) {
993  return;
994  }
995 

◆ lowerBound() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::lowerBound ( index_type  i) const
inline

An operation obtaining the smallest non-default element such that it's index is >= the given index.

Definition at line 1187 of file Brie.h.

1187  {
1188  const auto& value = unsynced.first->cell[0].value;
1189  auto res = iterator(unsynced.first, std::make_pair(unsynced.offset, value));
1190  if (value == value_type()) {

Referenced by souffle::SparseBitMap< BITS >::find().

◆ lowerBound() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::lowerBound ( index_type  i,
op_context  
) const
inline

An operation obtaining the smallest non-default element such that it's index is >= the given index.

A operation context can be provided for exploiting temporal locality.

Definition at line 1196 of file Brie.h.

1202  {
1203  // get X coordinate
1204  auto x = getIndex(brie_element_type(i), level);
1205 
1206  // check next node
1207  Node* next = node->cell[x].ptr;
1208 
1209  // check next step
1210  if (!next) {
1211  if (x == NUM_CELLS - 1) {
1212  ++level;
1213  node = const_cast<Node*>(node->parent);
1214  if (!node) return end();
1215  }
1216 
1217  // continue search
1218  i = i & getLevelMask(level);
1219 
1220  // find next higher value
1221  i += 1ull << (BITS * level);
1222 
1223  } else {
1224  if (level == 0) {
1225  // found boundary
1226  return iterator(node, std::make_pair(i, node->cell[x].value));
1227  }
1228 
1229  // decrease level counter
1230  --level;
1231 
1232  // continue one level below
1233  node = next;
1234  }
1235  }
1236  }
1237 
1238  /**
1239  * An operation obtaining the smallest non-default element such that it's index is greater
1240  * the given index.
1241  */
1242  iterator upperBound(index_type i) const {
1243  op_context ctxt;
1244  return upperBound(i, ctxt);
1245  }
1246 
1247  /**
1248  * An operation obtaining the smallest non-default element such that it's index is greater
1249  * the given index. A operation context can be provided for exploiting temporal locality.
1250  */
1251  iterator upperBound(index_type i, op_context& ctxt) const {
1252  if (i == std::numeric_limits<index_type>::max()) {

◆ merge()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static void souffle::SparseArray< T, BITS, merge_op, copy_op >::merge ( const Node parent,
Node *&  trg,
const Node src,
int  levels 
)
inlinestaticprivate

A static operation utilized internally for merging sub-trees recursively.

Parameters
parentthe parent node of the current merge operation
trga reference to the pointer the cloned node should be stored to
srcthe node to be cloned
levelsthe height of the cloned node

Definition at line 1006 of file Brie.h.

1008  {
1009  merge_op merg;
1010  for (int i = 0; i < NUM_CELLS; ++i) {
1011  trg->cell[i].value = merg(trg->cell[i].value, src->cell[i].value);
1012  }
1013  return;
1014  }
1015 
1016  // the recursive step
1017  for (int i = 0; i < NUM_CELLS; ++i) {
1018  merge(trg, trg->cell[i].ptr, src->cell[i].ptr, levels - 1);
1019  }
1020  }
1021 
1022 public:
1023  /**
1024  * Adds all the values stored in the given array to this array.
1025  */
1026  void addAll(const SparseArray& other) {
1027  // skip if other is empty
1028  if (other.empty()) {
1029  return;
1030  }
1031 
1032  // special case: emptiness
1033  if (empty()) {
1034  // use assignment operator
1035  *this = other;
1036  return;

◆ newNode()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
static Node* souffle::SparseArray< T, BITS, merge_op, copy_op >::newNode ( )
inlinestaticprivate

Creates new nodes and initializes them with 0.

Definition at line 1332 of file Brie.h.

1336  {

◆ operator=() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
SparseArray& souffle::SparseArray< T, BITS, merge_op, copy_op >::operator= ( const SparseArray< T, BITS, merge_op, copy_op > &  other)
inline

An assignment creating a deep copy of the handed in array structure (utilizing the copy functor provided as a template parameter).

Definition at line 461 of file Brie.h.

469  {
470  // clean this one
471  clean();
472 
473  // harvest content
474  unsynced.root = other.unsynced.root;
475  unsynced.levels = other.unsynced.levels;
476  unsynced.offset = other.unsynced.offset;
477  unsynced.first = other.unsynced.first;
478  unsynced.firstOffset = other.unsynced.firstOffset;
479 

◆ operator=() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
SparseArray& souffle::SparseArray< T, BITS, merge_op, copy_op >::operator= ( SparseArray< T, BITS, merge_op, copy_op > &&  other)
inline

An assignment operation taking over ownership from a r-value reference to a sparse array.

Definition at line 485 of file Brie.h.

493  {
494  return unsynced.root == nullptr;
495  }
496 
497  /**
498  * Computes the number of non-empty elements within this
499  * sparse array.
500  */
501  std::size_t size() const {
502  // quick one for the empty map
503  if (empty()) return 0;

◆ operator[]()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
value_type souffle::SparseArray< T, BITS, merge_op, copy_op >::operator[] ( index_type  i) const
inline

Obtains the value associated to index i – which might be the default value of the covered type if the value hasn't been defined previously.

Definition at line 937 of file Brie.h.

941  {

◆ raiseLevel() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::raiseLevel ( )
inlineprivate

Raises the level of this tree by one level.

It does so by introducing a new root node and inserting the current root node as a child node.

Definition at line 1418 of file Brie.h.

1429  {
1430  // something went wrong when we pass that line
1431  assert(info.levels < (sizeof(index_type) * 8 / BITS) + 1);
1432 
1433  // create new root
1434  Node* newRoot = newNode();
1435  newRoot->parent = nullptr;
1436 
1437  // insert existing root as child
1438  auto x = getIndex(brie_element_type(info.offset), info.levels + 1);
1439  newRoot->cell[x].ptr = info.root;

◆ raiseLevel() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::raiseLevel ( RootInfoSnapshot info)
inlineprivate

Attempts to raise the height of this tree based on the given root node information and updates the root-info snapshot correspondingly.

Definition at line 1445 of file Brie.h.

1452  {
1453  // success => final step, update parent of old root
1454  oldRoot->parent = info.root;
1455  } else {
1456  // throw away temporary new node
1457  delete newRoot;
1458  }
1459  }
1460 
1461  /**
1462  * Tests whether the given index is covered by the boundaries defined
1463  * by the hight and offset of the internally maintained tree.
1464  */
1465  bool inBoundaries(index_type a) const {
1467  }
1468 
1469  /**
1470  * Tests whether the given index is within the boundaries defined by the
1471  * given tree hight and offset.
1472  */
1473  static bool inBoundaries(index_type a, uint32_t levels, index_type offset) {
1474  auto mask = getLevelMask(levels + 1);
1475  return (a & mask) == offset;

◆ size()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
std::size_t souffle::SparseArray< T, BITS, merge_op, copy_op >::size ( ) const
inline

Computes the number of non-empty elements within this sparse array.

Definition at line 517 of file Brie.h.

517  {
518  // support null-nodes
519  if (!node) return 0;
520 
521  // add size of current node
522  std::size_t res = sizeof(Node);
523 
524  // sum up memory usage of child nodes
525  if (level > 0) {
526  for (int i = 0; i < NUM_CELLS; i++) {
527  res += getMemoryUsage(node->cell[i].ptr, level - 1);

◆ tryUpdateFirstInfo()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
bool souffle::SparseArray< T, BITS, merge_op, copy_op >::tryUpdateFirstInfo ( const FirstInfoSnapshot info)
inlineprivate

Updates the information stored regarding the first node in a concurrent setting utilizing a optimistic locking approach.

This is identical to the approach utilized for the root info.

Definition at line 717 of file Brie.h.

721  :
722  /**
723  * Obtains a mutable reference to the value addressed by the given index.
724  *
725  * @param i the index of the element to be addressed
726  * @return a mutable reference to the corresponding element
727  */
729  op_context ctxt;
730  return get(i, ctxt);
731  }
732 
733  /**
734  * Obtains a mutable reference to the value addressed by the given index.
735  *

◆ tryUpdateRootInfo()

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
bool souffle::SparseArray< T, BITS, merge_op, copy_op >::tryUpdateRootInfo ( const RootInfoSnapshot info)
inlineprivate

Updates the current root information based on the handed in modified snapshot instance if the version number of the snapshot still corresponds to the current version.

Otherwise a concurrent update took place and the operation is aborted.

Parameters
infothe updated information to be assigned to the active root-info data
Returns
true if successfully updated, false if aborted

Definition at line 650 of file Brie.h.

658  {
659  // the pointer to the first node
660  Node* node;
661  // the offset of the first node
662  index_type offset;
663  // the version number of the first node (for the optimistic locking)
664  uintptr_t version;
665  };
666 
667  /**
668  * Obtains the current version number of the first node information.
669  */

◆ update() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::update ( index_type  i,
const value_type val 
)
inline

Updates the value stored in cell i by the given value.

Definition at line 919 of file Brie.h.

921  {
922  return lookup(i);

◆ update() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
void souffle::SparseArray< T, BITS, merge_op, copy_op >::update ( index_type  i,
const value_type val,
op_context ctxt 
)
inline

Updates the value stored in cell i by the given value.

A operation context can be provided for exploiting temporal locality.

Definition at line 928 of file Brie.h.

930  {

◆ upperBound() [1/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::upperBound ( index_type  i) const
inline

An operation obtaining the smallest non-default element such that it's index is greater the given index.

Definition at line 1258 of file Brie.h.

1258  :
1259  /**
1260  * An internal debug utility printing the internal structure of this sparse array to the given output
1261  * stream.

◆ upperBound() [2/2]

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
iterator souffle::SparseArray< T, BITS, merge_op, copy_op >::upperBound ( index_type  i,
op_context ctxt 
) const
inline

An operation obtaining the smallest non-default element such that it's index is greater the given index.

A operation context can be provided for exploiting temporal locality.

Definition at line 1267 of file Brie.h.

1267  : " << node.parent << " -- range: " << offset << " - "
1268  << (offset + ~getLevelMask(level + 1)) << "\n";
1269 
1270  if (level == 0) {
1271  for (int i = 0; i < NUM_CELLS; i++) {
1272  if (detailed || node.cell[i].value != value_type()) {

Friends And Related Function Documentation

◆ detail::brie::SparseArrayIter

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
template<typename A >
friend struct detail::brie::SparseArrayIter
friend

Definition at line 341 of file Brie.h.

Field Documentation

◆ @1

union { ... }

◆ BIT_PER_STEP

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
constexpr int souffle::SparseArray< T, BITS, merge_op, copy_op >::BIT_PER_STEP = BITS
staticconstexprprivate

Definition at line 347 of file Brie.h.

◆ INDEX_MASK

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
constexpr key_type souffle::SparseArray< T, BITS, merge_op, copy_op >::INDEX_MASK = NUM_CELLS - 1
staticconstexprprivate

Definition at line 349 of file Brie.h.

◆ NUM_CELLS

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
constexpr int souffle::SparseArray< T, BITS, merge_op, copy_op >::NUM_CELLS = 1 << BIT_PER_STEP
staticconstexprprivate

Definition at line 348 of file Brie.h.

◆ synced

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
volatile RootInfo souffle::SparseArray< T, BITS, merge_op, copy_op >::synced

Definition at line 412 of file Brie.h.

◆ unsynced

template<typename T , unsigned BITS = 6, typename merge_op = default_merge<T>, typename copy_op = identity<T>>
RootInfo souffle::SparseArray< T, BITS, merge_op, copy_op >::unsynced

Definition at line 411 of file Brie.h.


The documentation for this class was generated from the following file:
souffle::SparseArray::clone
static Node * clone(const Node *node, int level)
Clones the given node and all its sub-nodes.
Definition: Brie.h:1361
souffle::SparseArray::unsynced
RootInfo unsynced
Definition: Brie.h:411
souffle::SparseArray::find
iterator find(index_type i) const
An operation to obtain an iterator referencing an element addressed by the given index.
Definition: Brie.h:1118
souffle::SparseArray::end
iterator end() const
An iterator referencing the position after the last non-default element.
Definition: Brie.h:1109
souffle::SparseArray::merge
static void merge(const Node *parent, Node *&trg, const Node *src, int levels)
A static operation utilized internally for merging sub-trees recursively.
Definition: Brie.h:1006
low
d d low
Definition: htmlJsChartistMin.h:15
souffle::SparseArray::update
void update(index_type i, const value_type &val)
Updates the value stored in cell i by the given value.
Definition: Brie.h:919
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::SparseArray
SparseArray()
A default constructor creating an empty sparse array.
Definition: Brie.h:419
souffle::SparseArray::findFirst
static Node * findFirst(Node *node, int level)
Obtains the left-most leaf-node of the tree rooted by the given node with the given level.
Definition: Brie.h:1396
souffle::SparseArray::lowerBound
iterator lowerBound(index_type i) const
An operation obtaining the smallest non-default element such that it's index is >= the given index.
Definition: Brie.h:1187
souffle::SparseArray::Cell::ptr
Node * ptr
Definition: Brie.h:373
souffle::SparseArray::iterator
SparseArrayIter< this_t > iterator
Definition: Brie.h:1096
souffle::SparseArray::get
value_type & get(index_type i)
Obtains a mutable reference to the value addressed by the given index.
Definition: Brie.h:744
souffle::SparseArray::RootInfo::levels
uint32_t levels
Definition: Brie.h:400
n
var n
Definition: htmlJsChartistMin.h:15
souffle::SparseArray::upperBound
iterator upperBound(index_type i) const
An operation obtaining the smallest non-default element such that it's index is greater the given ind...
Definition: Brie.h:1258
souffle::SparseArray::lookup
value_type lookup(index_type i) const
Obtains the value associated to index i – which might be the default value of the covered type if the...
Definition: Brie.h:946
souffle::SparseArray::RootInfo::first
Node * first
Definition: Brie.h:405
souffle::SparseArray::size
std::size_t size() const
Computes the number of non-empty elements within this sparse array.
Definition: Brie.h:517
souffle::SparseArray::RootInfo::offset
index_type offset
Definition: Brie.h:402
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
i
size_t i
Definition: json11.h:663
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::SparseArray::Cell::value
value_type value
Definition: Brie.h:379
souffle::SparseArray::addAll
void addAll(const SparseArray &other)
Adds all the values stored in the given array to this array.
Definition: Brie.h:1042
souffle::SparseArray::synced
volatile RootInfo synced
Definition: Brie.h:412
souffle::SparseArray::Node::cell
Cell cell[NUM_CELLS]
Definition: Brie.h:389
souffle::SparseArray::RootInfo::root
Node * root
Definition: Brie.h:398
souffle::SparseArray::newNode
static Node * newNode()
Creates new nodes and initializes them with 0.
Definition: Brie.h:1332
souffle::SparseArray::getFirstInfo
FirstInfoSnapshot getFirstInfo() const
Obtains a snapshot of the current first-node information.
Definition: Brie.h:694
souffle::detail::brie::brie_element_type
RamDomain brie_element_type
Definition: Brie.h:84
souffle::SparseArray::raiseLevel
void raiseLevel()
Raises the level of this tree by one level.
Definition: Brie.h:1418
souffle::SparseArray::value_type
T value_type
Definition: Brie.h:356
souffle::SparseArray::INDEX_MASK
static constexpr key_type INDEX_MASK
Definition: Brie.h:349
souffle::detail::brie::copy
auto copy(span< A, arity > s)
Definition: Brie.h:98
souffle::SparseArray::inBoundaries
bool inBoundaries(index_type a) const
Tests whether the given index is covered by the boundaries defined by the hight and offset of the int...
Definition: Brie.h:1481
souffle::SparseArray::getMemoryUsage
std::size_t getMemoryUsage() const
Computes the total memory usage of this data structure.
Definition: Brie.h:555
souffle::SparseArray::BIT_PER_STEP
static constexpr int BIT_PER_STEP
Definition: Brie.h:347
souffle::SparseArray::begin
iterator begin() const
Obtains an iterator referencing the first non-default element or end in case there are no such elemen...
Definition: Brie.h:1102
souffle::SparseArray::NUM_CELLS
static constexpr int NUM_CELLS
Definition: Brie.h:348
souffle::SparseArray::tryUpdateFirstInfo
bool tryUpdateFirstInfo(const FirstInfoSnapshot &info)
Updates the information stored regarding the first node in a concurrent setting utilizing a optimisti...
Definition: Brie.h:717
souffle::SparseArray::RootInfo::firstOffset
index_type firstOffset
Definition: Brie.h:407
souffle::SparseArray::clean
void clean()
Conducts a cleanup of the internal tree structure.
Definition: Brie.h:1352
souffle::SparseArray::getRootInfo
RootInfoSnapshot getRootInfo() const
Obtains a snapshot of the current root information.
Definition: Brie.h:620
souffle::SparseArray::empty
bool empty() const
Tests whether this sparse array is empty, thus it only contains default-values, or not.
Definition: Brie.h:509
souffle::SparseArray::dump
void dump(bool detailed, std::ostream &out, const Node &node, int level, index_type offset, int indent=0) const
An internal debug utility printing the internal structure of this sparse array to the given output st...
Definition: Brie.h:1279
souffle::SparseArray::index_type
key_type index_type
Definition: Brie.h:353