Construct version 5.3.9 An agent based modeling framework
Graph< link_type > Class Template Referenceabstract

Data structure for storing graphs/networks. More...

Inheritance diagram for Graph< link_type >:
Collaboration diagram for Graph< link_type >:

## Public Types

using graph_iterator = graph_utils::graph_iterator< link_type >

using sparse_graph_iterator = graph_utils::sparse_graph_iterator< link_type >

using row_graph_iterator = graph_utils::row_graph_iterator< link_type >

using col_graph_iterator = graph_utils::col_graph_iterator< link_type >

using const_full_row_iterator = graph_utils::const_full_row_iterator< link_type >

using full_row_iterator = graph_utils::full_row_iterator< link_type >

using const_sparse_row_iterator = graph_utils::const_sparse_row_iterator< link_type >

using sparse_row_iterator = graph_utils::sparse_row_iterator< link_type >

using const_full_col_iterator = graph_utils::const_full_col_iterator< link_type >

using full_col_iterator = graph_utils::full_col_iterator< link_type >

using const_sparse_col_iterator = graph_utils::const_sparse_col_iterator< link_type >

using sparse_col_iterator = graph_utils::sparse_col_iterator< link_type >

using const_row_begin_iterator = graph_utils::const_row_begin_iterator< link_type >

using row_begin_iterator = graph_utils::row_begin_iterator< link_type >

using const_col_begin_iterator = graph_utils::const_col_begin_iterator< link_type >

using col_begin_iterator = graph_utils::col_begin_iterator< link_type >

Public Types inherited from Typeless_Graph
enum class  edge_types : char {
dbool , dint , duint , dfloat ,
dstring , vbool , vint , vuint ,
vfloat , vstring , mbool , mint ,
muint , mfloat , mstring
}
Set of all edge types a Graph can have.

## Public Member Functions

virtual link_type & at (unsigned int row, unsigned int col)=0
Gets a reference to the specified link value. More...

void at (unsigned int row, unsigned int col, const link_type &data)
Takes a values and either sets the entry to that value or removes the entry if the submitted value is equal to the default value. More...

virtual const link_type & examine (unsigned int row, unsigned int col) const =0
Gets a constant reference to the specified element. More...

virtual void clear (const link_type &data) noexcept=0
Set all elements equal to the submitted value. More...

template<typename Callable >
void apply_operation (Callable lambda)
Applies a function pointer or lamda expression to all links in the Graph. More...

template<typename Callable >
void apply_row_operation (unsigned int row_index, Callable lambda)
Applies a function pointer or lamda expression to all links in the Graph's row. More...

template<typename Callable >
void apply_col_operation (unsigned int col_index, Callable lambda)
Applies a function pointer or lamda expression to all links in the Graph's column. More...

Adds a queued modification to the specified element. More...

void push_deltas (void) noexcept
Applies all queued modifications created by the add_delta function. More...

void get_data_state (std::ostream &out) const

virtual link_type & at (row_graph_iterator &it)=0
Gets a reference to link value the iterator points to. More...

virtual link_type & at (col_graph_iterator &it)=0
Gets a reference to link value the iterator points to. See Graph::at(full_row_iterator& it).

void at (row_graph_iterator &it, const link_type &data)
Takes a values and either sets the entry to that value or removes the entry if the submitted value is equal to the default value. More...

void at (col_graph_iterator &it, const link_type &data)
See Graph::at(row_graph_iterator&, const T&)

virtual full_row_iterator full_row_begin (unsigned int row_index)=0
Returns a full_row_iterator pointing to beginning of the specified row More...

virtual const_full_row_iterator full_row_begin (unsigned int row_index) const =0
Returns a const_full_row_iterator pointing to beginning of the specified row More...

const_full_row_iterator full_row_cbegin (unsigned int row_index) const
Function is identical to the const full_row_begin .

virtual sparse_row_iterator sparse_row_begin (unsigned int row_index, const link_type &skip_data)=0
Returns a Graph::sparse_row_iterator pointing to beginning of the specified row More...

virtual const_sparse_row_iterator sparse_row_begin (unsigned int row_index, const link_type &skip_data) const =0
Returns a Graph::const_sparse_row_iterator pointing to beginning of the specified row. More...

const_sparse_row_iterator sparse_row_cbegin (unsigned int row_index, const link_type &skip_data) const
Function is identical to the const sparse_row_begin .

virtual row_begin_iterator begin_rows (void) noexcept=0
Returns a row_begin_iterator pointing to the first row in the data structure. More...

virtual const_row_begin_iterator begin_rows (void) const noexcept=0
Returns a const_row_begin_iterator pointing to the first row in the data structure. More...

const_row_begin_iterator cbegin_rows (void) const noexcept
Function is identical to the const begin_rows .

virtual row_begin_iterator get_row (unsigned int row_index)=0
Returns a row_begin_iterator pointing to the specified row in the data structure. More...

virtual const_row_begin_iterator get_row (unsigned int row_index) const =0
Returns a const_row_begin_iterator pointing to the specified row in the data structure. More...

const_row_begin_iterator cget_row (unsigned int row_index) const
Function is identical to the const begin_rows .

const typeless_graph_iterator row_end (unsigned int row_index) const
Returns a typeless_graph_iterator pointing to the end of the specified row. More...

const typeless_graph_iterator end_rows (void) const noexcept
Returns a typeless_graph_iterator pointing to the beginning of the after the last row. More...

virtual full_col_iterator full_col_begin (unsigned int col_index)=0
Returns a full_col_iterator pointing to beginning of the specified column More...

virtual const_full_col_iterator full_col_begin (unsigned int col_index) const =0
Returns a const_full_col_iterator pointing to beginning of the specified column More...

const_full_col_iterator full_col_cbegin (unsigned int col_index) const
Function is identical to the const full_col_begin .

virtual sparse_col_iterator sparse_col_begin (unsigned int col_index, const link_type &skip_data)=0
Returns a Graph::sparse_col_iterator pointing to beginning of the specified column More...

virtual const_sparse_col_iterator sparse_col_begin (unsigned int col_index, const link_type &skip_data) const =0
Returns a Graph::const_sparse_col_iterator pointing to beginning of the specified column. More...

const_sparse_col_iterator sparse_col_cbegin (unsigned int col_index, const link_type &skip_data) const
Function is identical to the const sparse_col_begin .

virtual col_begin_iterator begin_cols (void) noexcept=0
Returns a col_begin_iterator pointing to the first column in the data structure. More...

virtual const_col_begin_iterator begin_cols (void) const noexcept=0
Returns a const_col_begin_iterator pointing to the first column in the data structure. More...

const_col_begin_iterator cbegin_cols (void) const noexcept
Function is identical to the const begin_cols .

virtual col_begin_iterator get_col (unsigned int col_index)=0
Returns a col_begin_iterator pointing to the specified column in the data structure. More...

virtual const_col_begin_iterator get_col (unsigned int col_index) const =0
Returns a const_col_begin_iterator pointing to the specified column in the data structure. More...

const_col_begin_iterator cget_col (unsigned int col_index) const
Function is identical to the const begin_cols .

const typeless_graph_iterator col_end (unsigned int col_index) const
Returns a typeless_graph_iterator pointing to the end of the specified column. More...

const typeless_graph_iterator end_cols (void) const noexcept
Returns a typeless_graph_iterator pointing to the beginning of the after the last column. More...

std::vector< link_type > get_dense_row (unsigned int row_index) const
Returns the link values of a row as a vector.

std::vector< link_type > get_dense_col (unsigned int col_index) const
Returns the link values of a column as a vector.

std::map< unsigned int, link_type > get_sparse_row (unsigned int row_index, const link_type &skip_value) const
Returns the link values of a row as a map.

std::map< unsigned int, link_type > get_sparse_col (unsigned int col_index, const link_type &skip_value) const
Returns the link values of a column as a map.

Returns the Transpose wrapper class for this Graph.

const Transpose< link_type > T (void) const
Returns the const Transpose wrapper class for this Graph.

template<typename input >
Graph< link_type > & operator= (const Temporary_Graph< input > &other)
Sets all links in the Graph to have the same values of the links of the Temporary_Graph

template<typename other >
Graph< link_type > & operator+= (const other &val)

template<typename other >
Graph< link_type > & operator-= (const other &val)
Subtracts the submitted value from all links.

template<typename other >
Graph< link_type > & operator*= (const other &val)
Muliplies all links by the submitted value.

template<typename other >
Graph< link_type > & operator/= (const other &val)
Divides all links by the submitted value.

output row_sum (unsigned int row_index) const
Adds up all values in a row together. More...

output col_sum (unsigned int col_index) const
Adds up all values in a column together. More...

virtual void push_deltas (void) noexcept=0
Virtual function that allows the deltas in a Graph to be pushed without needing to convert the Typeless_Graph into its child type. More...

virtual void get_data_state (std::ostream &out) const =0

## Public Attributes

The default value a entry will have if that entry is not stored in memory.

const bool col_dense
True if the column representation is dense, false if the representation is sparse.

const bool row_dense
True if the row representation is dense, false if the representation is sparse.

Public Attributes inherited from Typeless_Graph
const Nodeset *const source_nodeset
The nodeset in which each node corresponds to a row in the data structure.

const Nodeset *const target_nodeset
The nodeset in which each node corresponds to a column in the data structure.

const Nodeset *const slice_nodeset
The nodeset in which each node corresponds to a slice in the data structure.

const std::string name
The name of the network.

const unsigned int row_size
The number of rows in the data structure. Equalivilent to the size of the source nodeset.

const unsigned int col_size
The number of columns in the data structure. Equalivilent to the size of the target nodeset.

const edge_types edge_type
The edge's data type. Set by #dynet::get_type_name.

Static Public Member Functions inherited from Typeless_Graph
template<typename T >
static constexpr edge_types get_edge_type (void) noexcept

template<typename T >
static constexpr std::string get_type_name (void) noexcept

template<>
Typeless_Graph::edge_types get_edge_type (void) noexcept

template<>
Typeless_Graph::edge_types get_edge_type (void) noexcept

template<>
Typeless_Graph::edge_types get_edge_type (void) noexcept

template<>
Typeless_Graph::edge_types get_edge_type (void) noexcept

template<>
std::string get_type_name (void) noexcept

template<>
std::string get_type_name (void) noexcept

template<>
std::string get_type_name (void) noexcept

template<>
std::string get_type_name (void) noexcept

## Detailed Description

Data structure for storing graphs/networks.

Graphs/networks connect one node to another node using links/edges. In the case of 3d graphs, these edges can themselves be another dimension. Three dimensions are currently supported; source, target, and slice, with the last being used exclusively in 3d graphs. Edge types currently supported are bool, int, unsigned int, float, and string.

The source and target dimensions can be sparse or dense. This class has been constructed such that the source and target densities do not impact behaviour, only cpu and memory usage. From a developer's point of view, it is best to assume both dimensions are sparse as there is no complexity penalty if the dimensions are dense. The slice dimension density must match that requested by a model. When using a 3d graph with a slice dimension, a data type of vector<T> or map<unsigned int, T> is used for dense or sparse representation, respectively. The edge_type identifier in the parent class Typeless_Graph both indicates slice dimension density, and the data type used. By checking edge_type, conversion from 2d to 3d graphs is avoided as is conversion between two different data types such as float and string. The string used to define edge_type can be found using the function dynet::get_type_name.

The Graph structure itself is a collection of entries, which are not synonymous with links. When a link is examined using a soft examine, the entry's value is returned if the entry exists, otherwise the default value is returned. In a hard examine, an entry is allocated and the default value copied into it before returning the entry's value. Thus there can exist many links, with no entries with the correct default value. In a dense representation, every possible entry is allocated and default value is copied into each entry. In a sparse representation, entries are only allocated during a hard examine. Setting an entry with a hard examine to equal the default value is not recommended. While in a dense representation there is no consequence, excessive cpu and memory usage is wasted allocating a new entry.

Graphs can only be constructed or deconstructed by the GraphManager.

## Member Function Documentation

Adds a queued modification to the specified element.

The queued modification is not applied until push_deltas is called. At that time, the element is replaced with the specified data.

Parameters
 row Row index of the desired element. col Column index of the desired element. data Column index of the desired element.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
std::cout << "row 0 before pushing deltas:";
for (Graph<int>::full_row_iterator it = mygraph->full_row_begin(0); it != mygraph->row_end(0); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
mygraph->push_deltas();
std::cout << "row 0 after pushing deltas:";
for (Graph<int>::full_row_iterator it = mygraph->full_row_begin(0); it != mygraph->row_end(0); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
Data structure for storing graphs/networks.
Definition: Graph.h:1019
Adds a queued modification to the specified element.
void push_deltas(void) noexcept
Applies all queued modifications created by the add_delta function.
const typeless_graph_iterator row_end(unsigned int row_index) const
Returns a typeless_graph_iterator pointing to the end of the specified row.
virtual full_row_iterator full_row_begin(unsigned int row_index)=0
Returns a full_row_iterator pointing to beginning of the specified row
An iterator that iterates over every column at a constant row.
Definition: Graph.h:693

Output:

row 0 before pushing deltas: 0 1 4 2
row 0 after pushing deltas: 1 1 4 2

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

An assertion is raised if either row or col is out of bounds of the source and target nodeset, respectively.

Here is the caller graph for this function:

## ◆ apply_col_operation()

template<typename Callable >
 void Graph< link_type >::apply_col_operation ( unsigned int col_index, Callable lambda )
inline

Applies a function pointer or lamda expression to all links in the Graph's column.

The function pointer or lamda expression should take as an agrument Graph<link_type>::full_col_iterator and return a value convertable to link_type.

## ◆ apply_operation()

template<typename Callable >
 void Graph< link_type >::apply_operation ( Callable lambda )
inline

Applies a function pointer or lamda expression to all links in the Graph.

The function pointer or lamda expression should take as an agrument Graph<link_type>::full_row_iterator and return a value convertable to link_type.

## ◆ apply_row_operation()

template<typename Callable >
 void Graph< link_type >::apply_row_operation ( unsigned int row_index, Callable lambda )
inline

Applies a function pointer or lamda expression to all links in the Graph's row.

The function pointer or lamda expression should take as an agrument Graph<link_type>::full_row_iterator and return a value convertable to link_type.

## ◆ at() [1/4]

pure virtual

Gets a reference to link value the iterator points to.

A hard examine is done for the entry in which if there is not a physical entry present, an entry is added at that element and the default value is copied into it.

While the col_begin_iterator does inheriet from row_graph_iterator, using it as a parameter causes undefined behavior.

Parameters
 it Iterator that determines which element is accessed.
Returns
A reference to the element the iterator points to.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for(Graph<int>::full_row_iterator it = mygraph->full_row_begin(1); it != mygraph->end_row(1); ++it) {
mygraph->at(it) = it.col();
}
std::cout << "row 1:";
for(Graph<int>::full_row_iterator it = mygraph->full_row_begin(1); it != mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
virtual link_type & at(unsigned int row, unsigned int col)=0
Gets a reference to the specified link value.

Output:

row 1: 0 1 2 3

Complexity

Constant.

Iterator validity

The submitted iterator will always remain valid. Other iterators iterating over the same row or column may no longer be valid.

Exception Safety

An assertion is raised if typeless_graph_iterator::index is equal to typeless_graph_iterator::max.

## ◆ at() [2/4]

 void Graph< link_type >::at ( row_graph_iterator & it, const link_type & data )

Takes a values and either sets the entry to that value or removes the entry if the submitted value is equal to the default value.

If the submitted value does not equal the default value, a hard examine is done for the entry in which if there is not a physical entry present, an entry is added and the submitted value is coppied into that entry. If the submitted value does equal the default value, that entry is erased if it exists.

While the col_begin_iterator does inheriet from row_graph_iterator, using it as a parameter causes undefined behavior.

Parameters
 it Iterator that determines which element is accessed. data Data to be inserted in that element.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for(Graph<int>::full_row_iterator it = mygraph->full_row_begin(1); it != mygraph->end_row(1); ++it) {
mygraph->at(it, it.col());
}
std::cout << "row 1:";
for(Graph<int>::full_row_iterator it = mygraph->full_row_begin(1); it != mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}

Output:

row 1: 0 1 2 3

Complexity

Constant.

Iterator validity

The submitted iterator will always remain valid. Other iterators iterating over the same row or column may no longer be valid.

Exception Safety

An assertion is raised if typeless_graph_iterator::index is equal to typeless_graph_iterator::max.

## ◆ at() [3/4]

 virtual link_type & Graph< link_type >::at ( unsigned int row, unsigned int col )
pure virtual

Gets a reference to the specified link value.

A hard examine is done for the entry in which if there is not a physical entry present, an entry is added at that location and the default value is copied into it.

Parameters
 row Row index of the desired element. col Column index of the desired element.
Returns
A reference to the desired element.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1,1) = 4;
mygraph->at(1,2) = 9;
mygraph->at(1,3) = 3;
std::cout << "row 1:";
for(Graph<int>::full_row_iterator it = mygraph->full_row_begin(1); it != mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}

Output:

row 1: 1 4 9 3

Complexity

If both source and target dimension are dense, constant. If a dimension is sparse, a binary search is used to locate the correct row and/or column, which individual takes O(log n) based on the number of real rows/columns.

Iterator validity

If an entry was not inserted at the specified element, all iterators remain valid. Otherwise depending on user defined dimension density, iterators before or at the entry may not be valid.

Exception Safety

An assertion is raised if either row or col is out of bounds of the source and target nodeset, respectively.

Here is the caller graph for this function:

## ◆ at() [4/4]

 void Graph< link_type >::at ( unsigned int row, unsigned int col, const link_type & data )

Takes a values and either sets the entry to that value or removes the entry if the submitted value is equal to the default value.

If the submitted value does not equal the default value, a hard examine is done for the entry in which if there is not a physical entry present, an entry is added and the submitted value is coppied into that entry. If the submitted value does equal the default value, that entry is erased if it exists.

Parameters
 row Row index of the desired element. col Column index of the desired element. data Data to be inserted in that element.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1, 1, 4);
mygraph->at(1, 2, 9);
mygraph->at(1, 0, 0);
std::cout << "row 1:";
for(Graph<int>::full_row_iterator it = mygraph->full_row_begin(1); it != mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}

Output:

row 1: 0 4 9 0

Complexity

If both source and target dimension are dense, constant. If a dimension is sparse, a binary search is used to locate the correct row and/or column, which individually takes O(log n) based on the number of real rows/columns.

Iterator validity

If an entry was not inserted at the specified element, all iterators remain valid. Otherwise depending on user defined dimension density, iterators before or at the entry may not be valid.

Exception Safety

An assertion is raised if either row or col is out of bounds of the source and target nodeset, respectively.

## ◆ begin_cols() [1/2]

 virtual const_col_begin_iterator Graph< link_type >::begin_cols ( void ) const
pure virtualnoexcept

Returns a const_col_begin_iterator pointing to the first column in the data structure.

Returns
A const_col_begin_iterator pointing to the first column in the data structure.

Example

int main() {
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
const Graph<int>* const_mygraph = mygraph;
for (auto cols = const_mygraph->begin_cols(); cols != const_mygraph->end_cols(); ++cols) {
std::cout << "col " << cols.col() << ": ";
for(auto it = cols.begin(); it != cols.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}
const typeless_graph_iterator end_cols(void) const noexcept
Returns a typeless_graph_iterator pointing to the beginning of the after the last column.
virtual col_begin_iterator begin_cols(void) noexcept=0
Returns a col_begin_iterator pointing to the first column in the data structure.

Output:

col 0: 0 1 0 4
col 1: 1 0 0 5
col 2: 4 0 2 3
col 3: 2 0 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

Strong Guarantee: This function never throws exceptions.

## ◆ begin_cols() [2/2]

 virtual col_begin_iterator Graph< link_type >::begin_cols ( void )
pure virtualnoexcept

Returns a col_begin_iterator pointing to the first column in the data structure.

Returns
A col_begin_iterator pointing to the first column in the data structure.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::col_begin_iterator cols = mygraph->begin_cols(); cols != mygraph->end_cols(); ++cols) {
std::cout << "col " << cols.col() << ": ";
for(Graph<int>::full_col_iterator it = cols.full_begin(); it != cols.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}
An iterator that iterates over the start of each row.
Definition: Graph.h:970
An iterator that iterates over every row at a constant column.
Definition: Graph.h:749

Output:

col 0: 0 1 0 4
col 1: 1 0 0 5
col 2: 4 0 2 3
col 3: 2 0 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

Strong Guarantee: This function never throws exceptions

## ◆ begin_rows() [1/2]

 virtual const_row_begin_iterator Graph< link_type >::begin_rows ( void ) const
pure virtualnoexcept

Returns a const_row_begin_iterator pointing to the first row in the data structure.

Returns
A const_row_begin_iterator pointing to the row in the data structure.

Example

int main() {
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
const Graph<int>* const_mygraph = mygraph;
for (auto rows = const_mygraph->begin_rows(); rows != const_mygraph->end_rows(); ++rows) {
std::cout << "row " << rows.row() << ": ";
for(auto it = rows.begin(); it != rows.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}
virtual row_begin_iterator begin_rows(void) noexcept=0
Returns a row_begin_iterator pointing to the first row in the data structure.
const typeless_graph_iterator end_rows(void) const noexcept
Returns a typeless_graph_iterator pointing to the beginning of the after the last row.

Output:

row 0: 0 1 4 2
row 1: 1 0 0 0
row 2: 0 0 2 3
row 3: 4 5 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

Strong Guarantee: This function never throws exceptions.

## ◆ begin_rows() [2/2]

 virtual row_begin_iterator Graph< link_type >::begin_rows ( void )
pure virtualnoexcept

Returns a row_begin_iterator pointing to the first row in the data structure.

Returns
A row_begin_iterator pointing to the first row in the data structure.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::row_begin_iterator rows = mygraph->begin_rows(); rows != mygraph->end_rows(); ++rows) {
std::cout << "row " << rows.row() << ": ";
for(Graph<int>::full_row_iterator it = rows.full_begin(); it != rows.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}
An iterator that iterates over the start of each row.
Definition: Graph.h:880

Output:

row 0: 0 1 4 2
row 1: 1 0 0 0
row 2: 0 0 2 3
row 3: 4 5 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

Strong Guarantee: This function never throws exceptions

Here is the caller graph for this function:

## ◆ clear()

pure virtualnoexcept

Set all elements equal to the submitted value.

Parameters
 data Value that each element is set to.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->clear(2);
std::cout << "row 0:" << std::endl;
for (Graph<int>::full_row_iterator it = mygraph->full_row_begin(0); it != mygraph->row_end(0); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
virtual void clear(const link_type &data) noexcept=0
Set all elements equal to the submitted value.

Output:

row 0: 2 2 2 2

Complexity

Linear in number of elements in the graph.

Iterator validity

All iterators are invalidated unless both dimensions are dense.

Exception Safety

Strong Guarantee: This function never throws exceptions.

Here is the caller graph for this function:

## ◆ col_end()

 const typeless_graph_iterator Graph< link_type >::col_end ( unsigned int col_index ) const

Returns a typeless_graph_iterator pointing to the end of the specified column.

This iterator points to beyond the last piece of data and thus should not be dereferenced. Because all iterators in the Graph class are derived from typeless_graph_iterator, they can be compared for equality with a typeless_graph_iterator.

Parameters
 col_index Column index the returned iterator points to.
Returns
A typeless_graph_iterator pointing to the end of a column.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::col_begin_iterator cols = mygraph->begin_cols(1); cols != mygraph->end_cols(); ++cols) {
std::cout << "col " << cols.col() << ": ";
for(Graph<int>::full_col_iterator it = colss.full_begin(); it != cols.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}

Output:

col 1: 1 0 0 5
col 2: 4 0 2 3
col 3: 2 0 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

An assertion is raised if col_index is out of bounds of the target nodeset.

Here is the caller graph for this function:

## ◆ col_sum()

 output Graph< link_type >::col_sum ( unsigned int col_index ) const
inline

Adds up all values in a column together.

Return type is the same as the link_type except for bool in which the column sum returns an int.

## ◆ end_cols()

 const typeless_graph_iterator Graph< link_type >::end_cols ( void ) const
noexcept

Returns a typeless_graph_iterator pointing to the beginning of the after the last column.

Because all iterators in the Graph class are derived from typeless_graph_iterator, they can be compared for equality with a typeless_graph_iterator.

Returns
A typeless_graph_iterator pointing element (col_size, 0).

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::col_begin_iterator cols = mygraph->begin_cols(1); cols != mygraph->end_cols(); ++cols) {
std::cout << "col " << cols.col() << ": ";
for(Graph<int>::full_col_iterator it = cols.full_begin(); it != cols.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}

Output:

col 1: 1 0 0 5
col 2: 4 0 2 3
col 3: 2 0 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

Strong Guarantee: This function never throws exceptions.

## ◆ end_rows()

 const typeless_graph_iterator Graph< link_type >::end_rows ( void ) const
noexcept

Returns a typeless_graph_iterator pointing to the beginning of the after the last row.

Because all iterators in the Graph class are derived from typeless_graph_iterator, they can be compared for equality with a typeless_graph_iterator.

Returns
A typeless_graph_iterator pointing element (row_size, 0).

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::row_begin_iterator rows = mygraph->begin_rows(1); rows != mygraph->end_rows(); ++rows) {
std::cout << "row " << rows.row() << ": ";
for(Graph<int>::full_row_iterator it = rows.full_begin(); it != rows.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}

Output:

row 1: 1 0 0 0
row 2: 0 0 2 3
row 3: 4 5 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

Strong Guarantee: This function never throws exceptions.

Here is the caller graph for this function:

## ◆ examine()

 virtual const link_type & Graph< link_type >::examine ( unsigned int row, unsigned int col ) const
pure virtual

Gets a constant reference to the specified element.

A soft examine is done for the element in which if the element is not present, the default value is returned. The constant reference can not be modified as the default value is a constant in the case its returned.

Parameters
 row Row index of the desired element. col Column index of the desired element.
Returns
A constant reference to the desired element.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for(unsigned int i = 0; i < mygraph->row_size; i++) {
std::cout << "row " << i << " col 0: " << mygraph->examine(i,0) << std::endl;
}
}
virtual const link_type & examine(unsigned int row, unsigned int col) const =0
Gets a constant reference to the specified element.
const unsigned int row_size
The number of rows in the data structure. Equalivilent to the size of the source nodeset.
Definition: Graph.h:98

Output:

row 0 col 0: 0
row 1 col 0: 1
row 2 col 0: 0
row 3 col 0: 4


Complexity

If both source and target dimension are dense, constant. If a dimension is sparse, a binary search is used to locate the correct row and/or column, which individual takes O(log n) based on the number of real rows/columns.

Iterator validity

No changes.

Exception Safety

An assertion is raised if either row or col is out of bounds of the source and target nodeset, respectively.

Here is the caller graph for this function:

## ◆ full_col_begin() [1/2]

 virtual const_full_col_iterator Graph< link_type >::full_col_begin ( unsigned int col_index ) const
pure virtual

Returns a const_full_col_iterator pointing to beginning of the specified column

Parameters
 col_index Column index the returned iterator points to.
Returns
A const_full_col_iterator pointing to the beginning of the column at index col_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1,1) = 4;
mygraph->at(1,2) = 9;
mygraph->at(1,3) = 3;
const Graph<int>* const_mygraph = mygraph;
std::cout << "col 1:";
for(Graph<int>::const_full_col_iterator it = const_mygraph->full_col_begin(1); it != const_mygraph->end_col(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
virtual full_col_iterator full_col_begin(unsigned int col_index)=0
Returns a full_col_iterator pointing to beginning of the specified column
A constant iterator that iterates over every row at a constant column.
Definition: Graph.h:739

Output:

col 1: 1 4 0 5

Complexity

If the source dimension is dense, constant. Otherwise a binary search is used to find the beginning of a column.

Iterator validity

No changes.

Exception Safety

An assertion is raised if col_index is out of bounds of the target nodeset.

## ◆ full_col_begin() [2/2]

 virtual full_col_iterator Graph< link_type >::full_col_begin ( unsigned int col_index )
pure virtual

Returns a full_col_iterator pointing to beginning of the specified column

Parameters
 col_index Column index the returned iterator points to.
Returns
A full_col_iterator pointing to the beginning of the column at index col_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1,1) = 4;
mygraph->at(1,2) = 9;
mygraph->at(1,3) = 3;
std::cout << "col 1:";
for(Graph<int>::full_col_iterator it = mygraph->full_col_begin(1); it != mygraph->end_col(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}

Output:

col 1: 1 4 0 5

Complexity

If the target dimension is dense, constant. Otherwise a binary search is used to find the beginning of a column.

Iterator validity

No changes.

Exception Safety

An assertion is raised if col_index is out of bounds of the target nodeset.

Here is the caller graph for this function:

## ◆ full_row_begin() [1/2]

 virtual const_full_row_iterator Graph< link_type >::full_row_begin ( unsigned int row_index ) const
pure virtual

Returns a const_full_row_iterator pointing to beginning of the specified row

Parameters
 row_index Row index the returned iterator points to.
Returns
A const_full_row_iterator pointing to the beginning of the row at index row_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1,1) = 4;
mygraph->at(1,2) = 9;
mygraph->at(1,3) = 3;
const Graph<int>* const_mygraph = mygraph;
std::cout << "row 1:";
for(Graph<int>::const_full_row_iterator it = const_mygraph->full_row_begin(1); it != const_mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
A constant iterator that iterates over every column at a constant row.
Definition: Graph.h:681

Output:

row 1: 1 4 9 3

Complexity

If the source dimension is dense, constant. Otherwise a binary search is used to find the beginning of a row.

Iterator validity

No changes.

Exception Safety

An assertion is raised if row_index is out of bounds of the source nodeset.

## ◆ full_row_begin() [2/2]

 virtual full_row_iterator Graph< link_type >::full_row_begin ( unsigned int row_index )
pure virtual

Returns a full_row_iterator pointing to beginning of the specified row

Parameters
 row_index Row index the returned iterator points to.
Returns
A full_row_iterator pointing to the beginning of the row at index row_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1,1) = 4;
mygraph->at(1,2) = 9;
mygraph->at(1,3) = 3;
std::cout << "row 1:";
for(Graph<int>::full_row_iterator it = mygraph->full_row_begin(1); it != mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}

Output:

row 1: 1 4 9 3

Complexity

If the source dimension is dense, constant. Otherwise a binary search is used to find the beginning of a row.

Iterator validity

No changes.

Exception Safety

An assertion is raised if row_index is out of bounds of the source nodeset.

Here is the caller graph for this function:

## ◆ get_col() [1/2]

 virtual const_col_begin_iterator Graph< link_type >::get_col ( unsigned int col_index ) const
pure virtual

Returns a const_col_begin_iterator pointing to the specified column in the data structure.

Parameters
 col_index Row index the returned iterator points to.
Returns
A const_col_begin_iterator pointing to the specified column in the data structure.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
const Graph<int>* const_mygraph = mygraph;
for (Graph<int>::const_col_begin_iterator cols = const_mygraph->begin_cols(1); cols != const_mygraph->end_cols(); ++cols) {
std::cout << "col " << cols.col() << ": ";
for(Graph<int>::const_full_col_iterator it = cols.full_begin(); it != cols.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}
A constant iterator that iterates over the start of each column.
Definition: Graph.h:896

Output:

col 1: 1 0 0 5
col 2: 4 0 2 3
col 3: 2 0 3 6


Complexity

Constant if the source dimension is dense. Otherwise a binary search is used to find the beginning of the column.

Iterator validity

No changes.

Exception Safety

An assertion is raised if col_index is out of bounds of the target nodeset.

## ◆ get_col() [2/2]

 virtual col_begin_iterator Graph< link_type >::get_col ( unsigned int col_index )
pure virtual

Returns a col_begin_iterator pointing to the specified column in the data structure.

Parameters
 col_index Column index the returned iterator points to.
Returns
A col_begin_iterator pointing to the specified column in the data structure.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::col_begin_iterator cols = mygraph->begin_cols(1); cols != mygraph->end_cols(); ++cols) {
std::cout << "col " << cols.col() << ": ";
for(Graph<int>::full_col_iterator it = cols.full_begin(); it != cols.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}

Output:

col 1: 1 0 0 5
col 2: 4 0 2 3
col 3: 2 0 3 6


Complexity

Constant if the target dimension is dense. Otherwise a binary search is used to find the beginning of the column.

Iterator validity

No changes.

Exception Safety

An assertion is raised if col_index is out of bounds of the source nodeset.

## ◆ get_data_state()

 void Graph< link_type >::get_data_state ( std::ostream & out ) const
virtual

Implements Typeless_Graph.

## ◆ get_row() [1/2]

 virtual const_row_begin_iterator Graph< link_type >::get_row ( unsigned int row_index ) const
pure virtual

Returns a const_row_begin_iterator pointing to the specified row in the data structure.

Parameters
 row_index Row index the returned iterator points to.
Returns
A const_row_begin_iterator pointing to the specified row in the data structure.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
const Graph<int>* const_mygraph = mygraph;
for (Graph<int>::const_row_begin_iterator rows = const_mygraph->begin_rows(1); rows != const_mygraph->end_rows(); ++rows) {
std::cout << "row " << rows.row() << ": ";
for(Graph<int>::const_full_row_iterator it = rows.full_begin(); it != rows.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}
A constant iterator that iterates over the start of each row.
Definition: Graph.h:794

Output:

row 1: 1 0 0 0
row 2: 0 0 2 3
row 3: 4 5 3 6


Complexity

Constant if the source dimension is dense. Otherwise a binary search is used to find the beginning of the row.

Iterator validity

No changes.

Exception Safety

An assertion is raised if row_index is out of bounds of the source nodeset.

## ◆ get_row() [2/2]

 virtual row_begin_iterator Graph< link_type >::get_row ( unsigned int row_index )
pure virtual

Returns a row_begin_iterator pointing to the specified row in the data structure.

Parameters
 row_index Row index the returned iterator points to.
Returns
A row_begin_iterator pointing to the specified row in the data structure.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::row_begin_iterator rows = mygraph->begin_rows(1); rows != mygraph->end_rows(); ++rows) {
std::cout << "row " << rows.row() << ": ";
for(Graph<int>::full_row_iterator it = rows.full_begin(); it != rows.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}

Output:

row 1: 1 0 0 0
row 2: 0 0 2 3
row 3: 4 5 3 6


Complexity

Constant if the source dimension is dense. Otherwise a binary search is used to find the beginning of the row.

Iterator validity

No changes.

Exception Safety

An assertion is raised if row_index is out of bounds of the source nodeset.

Here is the caller graph for this function:

## ◆ push_deltas()

 void Graph< link_type >::push_deltas ( void )
virtualnoexcept

Applies all queued modifications created by the add_delta function.

Modifications are applied starting with the first modification queued. If two modifications are queued for the same element, the most recent delta overwrites the older delta. If a modification would set an element to equal the default value, the element is instead removed. After all modifications have been made, the queue of deltas is cleared.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->push_deltas();
std::cout << "row 0:";
for (Graph<int>::full_row_iterator it = mygraph->full_row_begin(0); it != mygraph->row_end(0); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}

Output:

row 0: 1 1 4 2

Complexity

Each modification requires an at(unsigned int, unsigned int, const T&) call which can be O(1) or O(log n) depending on dimension density. This call is done for every queued modification.

Iterator validity

If densities aren't sparse some iterators may be invalid based on set of deltas used

Exception Safety

Strong Guarantee: This function never throws exceptions.

Implements Typeless_Graph.

Here is the caller graph for this function:

## ◆ row_end()

 const typeless_graph_iterator Graph< link_type >::row_end ( unsigned int row_index ) const

Returns a typeless_graph_iterator pointing to the end of the specified row.

This iterator points to beyond the last piece of data and thus should not be dereferenced. Because all iterators in the Graph class are derived from typeless_graph_iterator, they can be compared for equality with a typeless_graph_iterator.

Parameters
 row_index Row index the returned iterator points to.
Returns
A typeless_graph_iterator pointing to the end of a row.

Example

int main() {
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
for (Graph<int>::row_begin_iterator rows = mygraph->begin_rows(1); rows != mygraph->end_rows(); ++rows) {
std::cout << "row " << rows.row() << ": ";
for(Graph<int>::full_row_iterator it = rows.full_begin(); it != rows.end(); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
}

Output:

row 1: 1 0 0 0
row 2: 0 0 2 3
row 3: 4 5 3 6


Complexity

Constant

Iterator validity

No changes.

Exception Safety

An assertion is raised if row_index is out of bounds of the source nodeset.

Here is the caller graph for this function:

## ◆ row_sum()

 output Graph< link_type >::row_sum ( unsigned int row_index ) const
inline

Adds up all values in a row together.

Return type is the same as the link_type except for bool in which the row sum returns an int.

## ◆ sparse_col_begin() [1/2]

 virtual const_sparse_col_iterator Graph< link_type >::sparse_col_begin ( unsigned int col_index, const link_type & skip_data ) const
pure virtual

Returns a Graph::const_sparse_col_iterator pointing to beginning of the specified column.

Parameters
 col_index Column index the returned iterator points to. skip_data Element values the iterator will skip over.
Returns
A const_sparse_col_iterator pointing to the beginning of the column at index col_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
const Graph<int>* const_mygraph = mygraph;
std::cout << "non-zero elements in col 1:";
for(Graph<int>::const_sparse_col_iterator it = const_mygraph->sparse_col_begin(1, 0); it != const_mygraph->end_col(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
virtual sparse_col_iterator sparse_col_begin(unsigned int col_index, const link_type &skip_data)=0
Returns a Graph::sparse_col_iterator pointing to beginning of the specified column
A constant iterator that iterates over each element whose value does not equal the skip value.
Definition: Graph.h:761

Output:

non-zero elements in col 1: 1 5

Complexity

If the source dimension is dense, constant. Otherwise a binary search is used to find the beginning of a column.

Iterator validity

No changes.

Exception Safety

An assertion is raised if col_index is out of bounds of the target nodeset.

## ◆ sparse_col_begin() [2/2]

 virtual sparse_col_iterator Graph< link_type >::sparse_col_begin ( unsigned int col_index, const link_type & skip_data )
pure virtual

Returns a Graph::sparse_col_iterator pointing to beginning of the specified column

Parameters
 col_index Column index the returned iterator points to. skip_data Element values the iterator will skip over.
Returns
A Graph::sparse_col_iterator pointing to the beginning of the column at index col_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
std::cout << "non-zero elements in col 1:";
for(Graph<int>::sparse_col_iterator it = mygraph->sparse_col_begin(1, 0); it != mygraph->end_col(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
An iterator that iterates over each element whose value does not equal the skip value.
Definition: Graph.h:783

Output:

non-zero elements in col 1: 1 5

Complexity

If the source dimension is dense, constant. Otherwise a binary search is used to find the beginning of a column.

Iterator validity

No changes.

Exception Safety

An assertion is raised if col_index is out of bounds of the target nodeset.

Here is the caller graph for this function:

## ◆ sparse_row_begin() [1/2]

 virtual const_sparse_row_iterator Graph< link_type >::sparse_row_begin ( unsigned int row_index, const link_type & skip_data ) const
pure virtual

Returns a Graph::const_sparse_row_iterator pointing to beginning of the specified row.

Parameters
 row_index Row index the returned iterator points to. skip_data Element values the iterator will skip over.
Returns
A const_sparse_row_iterator pointing to the beginning of the row at index row_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1,2) = 9;
mygraph->at(1,3) = 3;
const Graph<int>* const_mygraph = mygraph;
std::cout << "non-zero elements in row 1:";
for(Graph<int>::const_sparse_row_iterator it = const_mygraph->sparse_row_begin(1, 0); it != const_mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
virtual sparse_row_iterator sparse_row_begin(unsigned int row_index, const link_type &skip_data)=0
Returns a Graph::sparse_row_iterator pointing to beginning of the specified row
A constant iterator that iterates over each element whose value does not equal the skip value.
Definition: Graph.h:706

Output:

non-zero elements in row 1: 1 9 3

Complexity

If the source dimension is dense, constant. Otherwise a binary search is used to find the beginning of a row.

Iterator validity

No changes.

Exception Safety

An assertion is raised if row_index is out of bounds of the source nodeset.

## ◆ sparse_row_begin() [2/2]

 virtual sparse_row_iterator Graph< link_type >::sparse_row_begin ( unsigned int row_index, const link_type & skip_data )
pure virtual

Returns a Graph::sparse_row_iterator pointing to beginning of the specified row

Parameters
 row_index Row index the returned iterator points to. skip_data Element values the iterator will skip over.
Returns
A Graph::sparse_row_iterator pointing to the beginning of the row at index row_index.

Example

int main()
{
Graph<int>* mygraph;
// Graph<int>* mygraph has been initialized with the following data
// 0 1 4 2
// 1 0 0 0
// 0 0 2 3
// 4 5 3 6
// the default value for mygraph being zero.
// each element with a zero does not have a data entry
mygraph->at(1,2) = 9;
mygraph->at(1,3) = 3;
std::cout << "non-zero elements in row 1:";
for(Graph<int>::sparse_row_iterator it = mygraph->sparse_row_begin(1, 0); it != mygraph->end_row(1); ++it) {
std::cout << " " << *it;
}
std::cout << std::endl;
}
An iterator that iterates over each element whose value does not equal the skip value.
Definition: Graph.h:728

Output:

non-zero elements in row 1: 1 9 3

Complexity

If the source dimension is dense, constant. Otherwise a binary search is used to find the beginning of a row.

Iterator validity

No changes.

Exception Safety

An assertion is raised if row_index is out of bounds of the source nodeset.

Here is the caller graph for this function: