Class Graph

Nested Relationships

Nested Types

Class Documentation

class Graph

A graph (with optional weights) and parallel iterator methods.

Public Types

using NodeIntAttribute = Attribute<PerNode, int>
using NodeDoubleAttribute = Attribute<PerNode, double>
using NodeStringAttribute = Attribute<PerNode, std::string>
using EdgeIntAttribute = Attribute<PerEdge, int>
using EdgeDoubleAttribute = Attribute<PerEdge, double>
using EdgeStringAttribute = Attribute<PerEdge, std::string>
using OutNeighborRange = NeighborRange<false>
using InNeighborRange = NeighborRange<true>
using OutNeighborWeightRange = NeighborWeightRange<false>
using InNeighborWeightRange = NeighborWeightRange<true>

Public Functions

inline auto &nodeAttributes() noexcept
inline auto &edgeAttributes() noexcept
inline auto attachNodeIntAttribute(const std::string &name)
inline auto attachEdgeIntAttribute(const std::string &name)
inline auto attachNodeDoubleAttribute(const std::string &name)
inline auto attachEdgeDoubleAttribute(const std::string &name)
inline auto attachNodeStringAttribute(const std::string &name)
inline auto attachEdgeStringAttribute(const std::string &name)
inline auto getNodeIntAttribute(const std::string &name)
inline auto getEdgeIntAttribute(const std::string &name)
inline auto getNodeDoubleAttribute(const std::string &name)
inline auto getEdgeDoubleAttribute(const std::string &name)
inline auto getNodeStringAttribute(const std::string &name)
inline auto getEdgeStringAttribute(const std::string &name)
inline void detachNodeAttribute(std::string const &name)
inline void detachEdgeAttribute(std::string const &name)
Graph(count n = 0, bool weighted = false, bool directed = false, bool edgesIndexed = false)

Create a graph of n nodes. The graph has assignable edge weights if weighted is set to true. If weighted is set to false each edge has edge weight 1.0 and any other weight assignment will be ignored.

Parameters:
  • n – Number of nodes.

  • weighted – If set to true, the graph has edge weights.

  • directed – If set to true, the graph will be directed.

template<class EdgeMerger = std::plus<edgeweight>>
inline Graph(const Graph &G, bool weighted, bool directed, bool edgesIndexed = false, EdgeMerger edgeMerger = std::plus<edgeweight>())
Graph(std::initializer_list<WeightedEdge> edges)

Generate a weighted graph from a list of edges. (Useful for small graphs in unit tests that you do not want to read from a file.)

Parameters:

edges[in] list of weighted edges

Graph(const Graph &other) = default

Create a graph as copy of other.

Parameters:

other – The graph to copy.

Graph(Graph &&other) noexcept = default

Default move constructor

~Graph() = default

Default destructor

Graph &operator=(Graph &&other) noexcept = default

Default move assignment operator

Graph &operator=(const Graph &other) = default

Default copy assignment operator

void preallocateUndirected(node u, size_t size)

Reserves memory in the node’s edge containers for undirected graphs.

This function is thread-safe if called from different threads on different nodes.

Parameters:
  • u – the node memory should be reserved for

  • size – the amount of memory to reserve

void preallocateDirected(node u, size_t outSize, size_t inSize)

Reserves memory in the node’s edge containers for directed graphs.

This function is thread-safe if called from different threads on different nodes.

Parameters:
  • u – the node memory should be reserved for

  • inSize – the amount of memory to reserve for in edges

  • outSize – the amount of memory to reserve for out edges

void preallocateDirectedOutEdges(node u, size_t outSize)

Reserves memory in the node’s edge containers for directed graphs.

This function is thread-safe if called from different threads on different nodes.

Parameters:
  • u – the node memory should be reserved for

  • outSize – the amount of memory to reserve for out edges

void preallocateDirectedInEdges(node u, size_t inSize)

Reserves memory in the node’s edge containers for directed graphs.

This function is thread-safe if called from different threads on different nodes.

Parameters:
  • u – the node memory should be reserved for

  • inSize – the amount of memory to reserve for in edges

void indexEdges(bool force = false)

EDGE IDS Initially assign integer edge identifiers.

Parameters:

force – Force re-indexing of edges even if they have already been indexed

inline bool hasEdgeIds() const noexcept

Checks if edges have been indexed

Returns:

bool if edges have been indexed

edgeid edgeId(node u, node v) const

Get the id of the given edge.

inline std::pair<node, node> edgeById(index id) const

Get the Edge (u,v) of the given id. (inverse to edgeId)

Note

Time complexity of this function is O(n).

inline index upperEdgeIdBound() const noexcept

Get an upper bound for the edge ids in the graph.

Returns:

An upper bound for the edge ids.

void shrinkToFit()

GRAPH INFORMATION Try to save some memory by shrinking internal data structures of the graph. Only run this once you finished editing the graph. Otherwise it will cause unnecessary reallocation of memory.

void TLX_DEPRECATED(compactEdges())

DEPRECATED: this function will no longer be supported in later releases. Compacts the adjacency arrays by re-using no longer needed slots from deleted edges.

void sortEdges()

Sorts the adjacency arrays by node id. While the running time is linear this temporarily duplicates the memory.

template<class Lambda>
void sortEdges(Lambda lambda)

Sorts the adjacency arrays by a custom criterion.

Parameters:

lambda – Lambda function used to sort the edges. It takes two WeightedEdge e1 and e2 as input parameters, returns true if e1 < e2, false otherwise.

inline void setEdgeCount(Unsafe, count edges)

Set edge count of the graph to edges.

Parameters:

edges – the edge count of a graph

inline void setUpperEdgeIdBound(Unsafe, edgeid newBound)

Set upper bound of edge count.

Parameters:

newBound – New upper edge id bound.

inline void setNumberOfSelfLoops(Unsafe, count loops)

Set the number of self-loops.

Parameters:

loops – New number of self-loops.

node addNode()

Add a new node to the graph and return it.

Returns:

The new node.

node addNodes(count numberOfNewNodes)

Add numberOfNewNodes new nodes.

Parameters:

numberOfNewNodes – Number of new nodes.

Returns:

The index of the last node added.

void removeNode(node v)

Remove a node v and all incident edges from the graph.

Incoming as well as outgoing edges will be removed.

Parameters:

u – Node.

inline void removePartialOutEdges(Unsafe, node u)

Removes out-going edges from node @u. If the graph is weighted and/or has edge ids, weights and/or edge ids will also be removed.

Parameters:

node – u Node.

inline void removePartialInEdges(Unsafe, node u)

Removes in-going edges to node @u. If the graph is weighted and/or has edge ids, weights and/or edge ids will also be removed.

Parameters:

node – u Node.

inline bool hasNode(node v) const noexcept

Check if node v exists in the graph.

Parameters:

v – Node.

Returns:

true if v exists, false otherwise.

void restoreNode(node v)

Restores a previously deleted node v with its previous id in the graph.

Parameters:

v – Node.

inline count degree(node v) const

NODE PROPERTIES Returns the number of outgoing neighbors of v.

Note

The existence of the node is not checked. Calling this function with a non-existing node results in a segmentation fault. Node existence can be checked by calling hasNode(u).

Parameters:

v – Node.

Returns:

The number of outgoing neighbors.

inline count degreeIn(node v) const

Get the number of incoming neighbors of v.

Note

If the graph is not directed, the outgoing degree is returned.

Note

The existence of the node is not checked. Calling this function with a non-existing node results in a segmentation fault. Node existence can be checked by calling hasNode(u).

Parameters:

v – Node.

Returns:

The number of incoming neighbors.

inline count degreeOut(node v) const

Get the number of outgoing neighbors of v.

Note

The existence of the node is not checked. Calling this function with a non-existing node results in a segmentation fault. Node existence can be checked by calling hasNode(u).

Parameters:

v – Node.

Returns:

The number of outgoing neighbors.

inline bool isIsolated(node v) const

Check whether v is isolated, i.e. degree is 0.

Parameters:

v – Node.

Returns:

true if the node is isolated (= degree is 0)

edgeweight weightedDegree(node u, bool countSelfLoopsTwice = false) const

Returns the weighted degree of u.

Parameters:
  • u – Node.

  • countSelfLoopsTwice – If set to true, self-loops will be counted twice.

Returns:

Weighted degree of u.

edgeweight weightedDegreeIn(node u, bool countSelfLoopsTwice = false) const

Returns the weighted in-degree of u.

Parameters:
  • u – Node.

  • countSelfLoopsTwice – If set to true, self-loops will be counted twice.

Returns:

Weighted in-degree of v.

bool addEdge(node u, node v, edgeweight ew = defaultEdgeWeight, bool checkMultiEdge = false)

Insert an edge between the nodes u and v. If the graph is weighted you can optionally set a weight for this edge. The default weight is 1.0. Note: Multi-edges are not supported and will NOT be handled consistently by the graph data structure. It is possible to check for multi-edges by enabling parameter “checkForMultiEdges”. If already present, the new edge is not inserted. Enabling this check increases the complexity of the function to O(max(deg(u), deg(v))).

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

  • weight – Optional edge weight.

  • checkMultiEdge – If true, this enables a check for a possible multi-edge.

Returns:

true if edge has been added, false otherwise (in case checkMultiEdge is set to true and the new edge would have been a multi-edge.)

bool addPartialEdge(Unsafe, node u, node v, edgeweight ew = defaultEdgeWeight, uint64_t index = 0, bool checkForMultiEdges = false)

Insert an edge between the nodes u and v. Unline the addEdge function, this function does not not add any information to v. If the graph is weighted you can optionally set a weight for this edge. The default weight is 1.0. Note: Multi-edges are not supported and will NOT be handled consistently by the graph data structure. It is possible to check for multi-edges by enabling parameter “checkForMultiEdges”. If already present, the new edge is not inserted. Enabling this check increases the complexity of the function to O(max(deg(u), deg(v))).

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

  • weight – Optional edge weight.

  • ew – Optional edge weight.

  • index – Optional edge index.

  • checkMultiEdge – If true, this enables a check for a possible multi-edge.

Returns:

true if edge has been added, false otherwise (in case checkMultiEdge is set to true and the new edge would have been a multi-edge.)

bool addPartialInEdge(Unsafe, node u, node v, edgeweight ew = defaultEdgeWeight, uint64_t index = 0, bool checkForMultiEdges = false)

Insert an in edge between the nodes u and v in a directed graph. If the graph is weighted you can optionally set a weight for this edge. The default weight is 1.0. Note: Multi-edges are not supported and will NOT be handled consistently by the graph data structure. It is possible to check for multi-edges by enabling parameter “checkForMultiEdges”. If already present, the new edge is not inserted. Enabling this check increases the complexity of the function to O(max(deg(u), deg(v))).

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

  • ew – Optional edge weight.

  • index – Optional edge index.

  • checkMultiEdge – If true, this enables a check for a possible multi-edge.

Returns:

true if edge has been added, false otherwise (in case checkMultiEdge is set to true and the new edge would have been a multi-edge.)

bool addPartialOutEdge(Unsafe, node u, node v, edgeweight ew = defaultEdgeWeight, uint64_t index = 0, bool checkForMultiEdges = false)

Insert an out edge between the nodes u and v in a directed graph. If the graph is weighted you can optionally set a weight for this edge. The default weight is 1.0. Note: Multi-edges are not supported and will NOT be handled consistently by the graph data structure. It is possible to check for multi-edges by enabling parameter “checkForMultiEdges”. If already present, the new edge is not inserted. Enabling this check increases the complexity of the function to O(max(deg(u), deg(v))).

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

  • ew – Optional edge weight.

  • index – Optional edge index.

  • checkMultiEdge – If true, this enables a check for a possible multi-edge.

Returns:

true if edge has been added, false otherwise (in case checkMultiEdge is set to true and the new edge would have been a multi-edge.)

inline void setKeepEdgesSorted(bool sorted = true)

If set to true, the ingoing and outgoing adjacency vectors will automatically be updated to maintain a sorting (if it existed before) by performing up to n-1 swaps. If the user plans to remove multiple edges, better set it to false and call sortEdges() afterwards to avoid redundant swaps. Default = true.

inline void setMaintainCompactEdges(bool compact = true)

If set to true, the EdgeIDs will automatically be adjusted, so that no gaps in between IDs exist. If the user plans to remove multiple edges, better set it to false and call indexEdges(force=true) afterwards to avoid redundant re-indexing. Default = true.

inline bool getKeepEdgesSorted() const noexcept

Returns true if edges are currently being sorted when removeEdge() is called.

inline bool getMaintainCompactEdges() const noexcept
void removeEdge(node u, node v)

Removes the undirected edge {u,v}.

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

void removeAllEdges()

Removes all the edges in the graph.

template<typename Condition>
std::pair<count, count> removeAdjacentEdges(node u, Condition condition, bool edgesIn = false)

Removes edges adjacent to a node according to a specific criterion.

Parameters:
  • u – The node whose adjacent edges shall be removed.

  • condition – A function that takes a node as an input and returns a bool. If true the edge (u, v) is removed.

  • edgesIn – Whether in-going or out-going edges shall be removed.

Returns:

std::pair<count, count> The number of removed edges (first) and the number of removed self-loops (second).

void removeSelfLoops()

Removes all self-loops in the graph.

void removeMultiEdges()

Removes all multi-edges in the graph.

void swapEdge(node s1, node t1, node s2, node t2)

Changes the edges {s1, t1} into {s1, t2} and the edge {s2, t2} into {s2, t1}.

If there are edge weights or edge ids, they are preserved. Note that no check is performed if the swap is actually possible, i.e. does not generate duplicate edges.

Parameters:
  • s1 – The first source

  • t1 – The first target

  • s2 – The second source

  • t2 – The second target

bool hasEdge(node u, node v) const noexcept

Checks if undirected edge {u,v} exists in the graph.

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

Returns:

true if the edge exists, false otherwise.

inline bool isWeighted() const noexcept

Returns true if this graph supports edge weights other than 1.0.

Returns:

true if this graph supports edge weights other than 1.0.

inline bool isDirected() const noexcept

Return true if this graph supports directed edges.

Returns:

true if this graph supports directed edges.

inline bool isEmpty() const noexcept

Return true if graph contains no nodes.

Returns:

true if graph contains no nodes.

inline count numberOfNodes() const noexcept

Return the number of nodes in the graph.

Returns:

The number of nodes.

inline count numberOfEdges() const noexcept

Return the number of edges in the graph.

Returns:

The number of edges.

inline count numberOfSelfLoops() const noexcept

Return the number of loops {v,v} in the graph.

Note

This involves calculation, so store result if needed multiple times.

Returns:

The number of loops.

inline index upperNodeIdBound() const noexcept

Get an upper bound for the node ids in the graph.

Returns:

An upper bound for the node ids.

bool checkConsistency() const

Check for invalid graph states, such as multi-edges.

Returns:

False if the graph is in invalid state.

inline void timeStep()

Trigger a time step - increments counter.

This method is deprecated and will not be supported in future releases.

inline count time()

Get time step counter.

This method is deprecated and will not be supported in future releases.

Returns:

Time step counter.

edgeweight weight(node u, node v) const

Return edge weight of edge {u,v}. Returns 0 if edge does not exist. BEWARE: Running time is \Theta(deg(u))!

Parameters:
  • u – Endpoint of edge.

  • v – Endpoint of edge.

Returns:

Edge weight of edge {u,v} or 0 if edge does not exist.

void setWeight(node u, node v, edgeweight ew)

Set the weight of an edge. If the edge does not exist, it will be inserted.

Parameters:
  • u[in] endpoint of edge

  • v[in] endpoint of edge

  • weight[in] edge weight

void setWeightAtIthNeighbor(Unsafe, node u, index i, edgeweight ew)

Set the weight to the i-th neighbour of u.

Parameters:
  • u[in] endpoint of edge

  • i[in] index of the nexight

  • weight[in] edge weight

void setWeightAtIthInNeighbor(Unsafe, node u, index i, edgeweight ew)

Set the weight to the i-th incoming neighbour of u.

Parameters:
  • u[in] endpoint of edge

  • i[in] index of the nexight

  • weight[in] edge weight

void increaseWeight(node u, node v, edgeweight ew)

Increase the weight of an edge. If the edge does not exist, it will be inserted.

Parameters:
  • u[in] endpoint of edge

  • v[in] endpoint of edge

  • weight[in] edge weight

edgeweight totalEdgeWeight() const noexcept

Returns the sum of all edge weights.

Returns:

The sum of all edge weights.

inline NodeRange nodeRange() const noexcept

Get an iterable range over the nodes of the graph.

Returns:

Iterator range over the nodes of the graph.

inline EdgeRange edgeRange() const noexcept

Get an iterable range over the edges of the graph.

Returns:

Iterator range over the edges of the graph.

inline EdgeWeightRange edgeWeightRange() const noexcept

Get an iterable range over the edges of the graph and their weights.

Returns:

Iterator range over the edges of the graph and their weights.

inline NeighborRange<false> neighborRange(node u) const

Get an iterable range over the neighbors of .

Parameters:

u – Node.

Returns:

Iterator range over the neighbors of u.

inline NeighborWeightRange<false> weightNeighborRange(node u) const

Get an iterable range over the neighbors of u including the edge weights.

Parameters:

u – Node.

Returns:

Iterator range over pairs of neighbors of u and corresponding edge weights.

inline NeighborRange<true> inNeighborRange(node u) const

Get an iterable range over the in-neighbors of .

Parameters:

u – Node.

Returns:

Iterator range over pairs of in-neighbors of u.

inline NeighborWeightRange<true> weightInNeighborRange(node u) const

Get an iterable range over the in-neighbors of u including the edge weights.

Parameters:

u – Node.

Returns:

Iterator range over pairs of in-neighbors of u and corresponding edge weights.

inline index indexOfNeighbor(node u, node v) const

Returns the index of node v in the array of outgoing edges of node u.

Parameters:
  • u – Node

  • v – Node

Returns:

index of node v in the array of outgoing edges of node u.

inline node getIthNeighbor(node u, index i) const

Return the i-th (outgoing) neighbor of u.

Parameters:
  • u – Node.

  • i – index; should be in [0, degreeOut(u))

Returns:

i-th (outgoing) neighbor of u, or none if no such neighbor exists.

inline node getIthInNeighbor(node u, index i) const

Return the i-th (incoming) neighbor of u.

Parameters:
  • u – Node.

  • i – index; should be in [0, degreeIn(u))

Returns:

i-th (incoming) neighbor of u, or none if no such neighbor exists.

inline edgeweight getIthNeighborWeight(node u, index i) const

Return the weight to the i-th (outgoing) neighbor of u.

Parameters:
  • u – Node.

  • i – index; should be in [0, degreeOut(u))

Returns:

edge weight to the i-th (outgoing) neighbor of u, or +inf if no such neighbor exists.

inline std::pair<node, edgeweight> getIthNeighborWithWeight(node u, index i) const

Get i-th (outgoing) neighbor of u and the corresponding edge weight.

Parameters:
  • u – Node.

  • i – index; should be in [0, degreeOut(u))

Returns:

pair: i-th (outgoing) neighbor of u and the corresponding edge weight, or defaultEdgeWeight if unweighted.

inline std::pair<node, edgeweight> getIthNeighborWithWeight(Unsafe, node u, index i) const

Get i-th (outgoing) neighbor of u and the corresponding edge weight.

Parameters:
  • u – Node.

  • i – index; should be in [0, degreeOut(u))

Returns:

pair: i-th (outgoing) neighbor of u and the corresponding edge weight, or defaultEdgeWeight if unweighted.

inline std::pair<node, edgeid> getIthNeighborWithId(node u, index i) const

Get i-th (outgoing) neighbor of u and the corresponding edge id.

Parameters:
  • u – Node.

  • i – index; should be in [0, degreeOut(u))

Returns:

pair: i-th (outgoing) neighbor of u and the corresponding edge id, or none if no such neighbor exists.

template<typename L>
void forNodes(L handle) const

Iterate over all nodes of the graph and call handle (lambda closure).

Parameters:

handle – Takes parameter (node).

template<typename L>
void parallelForNodes(L handle) const

Iterate randomly over all nodes of the graph and call handle (lambda closure).

Parameters:

handle – Takes parameter (node).

template<typename C, typename L>
void forNodesWhile(C condition, L handle) const

Iterate over all nodes of the graph and call handle (lambda closure) as long as condition remains true. This allows for breaking from a node loop.

Parameters:
  • condition – Returning false breaks the loop.

  • handle – Takes parameter (node).

template<typename L>
void forNodesInRandomOrder(L handle) const

Iterate randomly over all nodes of the graph and call handle (lambda closure).

Parameters:

handle – Takes parameter (node).

template<typename L>
void balancedParallelForNodes(L handle) const

Iterate in parallel over all nodes of the graph and call handler (lambda closure). Using schedule(guided) to remedy load-imbalances due to e.g. unequal degree distribution.

Parameters:

handle – Takes parameter (node).

template<typename L>
void forNodePairs(L handle) const

Iterate over all undirected pairs of nodes and call handle (lambda closure).

Parameters:

handle – Takes parameters (node, node).

template<typename L>
void parallelForNodePairs(L handle) const

Iterate over all undirected pairs of nodes in parallel and call handle (lambda closure).

Parameters:

handle – Takes parameters (node, node).

template<typename L>
void forEdges(L handle) const

Iterate over all edges of the const graph and call handle (lambda closure).

Parameters:

handle – Takes parameters (node, node), (node, node, edgweight), (node, node, edgeid) or (node, node, edgeweight, edgeid).

template<typename L>
void parallelForEdges(L handle) const

Iterate in parallel over all edges of the const graph and call handle (lambda closure).

Parameters:

handle – Takes parameters (node, node) or (node, node, edgweight), (node, node, edgeid) or (node, node, edgeweight, edgeid).

template<typename L>
void forNeighborsOf(node u, L handle) const

Iterate over all neighbors of a node and call handle (lamdba closure).

Note

For directed graphs only outgoing edges from u are considered. A node is its own neighbor if there is a self-loop.

Parameters:
  • u – Node.

  • handle – Takes parameter (node) or (node, edgeweight) which is a neighbor of u.

template<typename L>
void forEdgesOf(node u, L handle) const

Iterate over all incident edges of a node and call handle (lamdba closure).

Note

For undirected graphs all edges incident to u are also outgoing edges.

Parameters:
  • u – Node.

  • handle – Takes parameters (node, node), (node, node, edgeweight), (node, node, edgeid) or (node, node, edgeweight, edgeid) where the first node is u and the second is a neighbor of u.

template<typename L>
void forInNeighborsOf(node u, L handle) const

Iterate over all neighbors of a node and call handler (lamdba closure). For directed graphs only incoming edges from u are considered.

template<typename L>
void forInEdgesOf(node u, L handle) const

Iterate over all incoming edges of a node and call handler (lamdba closure).

Handle takes parameters (u, v) or (u, v, w) where w is the edge weight.

Note

For undirected graphs all edges incident to u are also incoming edges.

template<typename L>
double parallelSumForNodes(L handle) const

Iterate in parallel over all nodes and sum (reduce +) the values returned by the handler

template<typename L>
double parallelSumForEdges(L handle) const

Iterate in parallel over all edges and sum (reduce +) the values returned by the handler

class EdgeIterator : public NetworKit::Graph::EdgeIteratorBase

Class to iterate over the edges of the graph. If the graph is undirected, operator*() returns the edges (u, v) s.t. u <= v.

Public Types

using value_type = Edge
using reference = value_type&
using pointer = value_type*
using iterator_category = std::forward_iterator_tag
using difference_type = ptrdiff_t
using self = EdgeIterator

Public Functions

inline EdgeIterator(const Graph *G, NodeIterator nodeIter)
inline EdgeIterator()
inline bool operator==(const EdgeIterator &rhs) const noexcept
inline bool operator!=(const EdgeIterator &rhs) const noexcept
inline Edge operator*() const noexcept
inline EdgeIterator &operator++()
inline EdgeIterator operator++(int)
inline EdgeIterator operator--()
inline EdgeIterator operator--(int)
class EdgeIteratorBase

Subclassed by NetworKit::Graph::EdgeIterator, NetworKit::Graph::EdgeWeightIterator

class EdgeRange

Wrapper class to iterate over a range of the edges of a graph.

Public Functions

inline EdgeRange(const Graph &G)
inline EdgeRange()
~EdgeRange() = default
inline EdgeIterator begin() const
inline EdgeIterator end() const
class EdgeWeightIterator : public NetworKit::Graph::EdgeIteratorBase

Class to iterate over the edges of the graph and their weights. If the graph is undirected, operator*() returns a WeightedEdge struct with u <= v.

Public Types

using value_type = WeightedEdge
using reference = value_type&
using pointer = value_type*
using iterator_category = std::forward_iterator_tag
using difference_type = ptrdiff_t
using self = EdgeWeightIterator

Public Functions

inline EdgeWeightIterator(const Graph *G, NodeIterator nodeIter)
inline EdgeWeightIterator()

WARNING: This constructor is required for Python and should not be used as the iterator is not initialized.

inline bool operator==(const EdgeWeightIterator &rhs) const noexcept
inline bool operator!=(const EdgeWeightIterator &rhs) const noexcept
inline EdgeWeightIterator &operator++()
inline EdgeWeightIterator operator++(int)
inline EdgeWeightIterator operator--()
inline EdgeWeightIterator operator--(int)
inline WeightedEdge operator*() const noexcept
class EdgeWeightRange

Wrapper class to iterate over a range of the edges of a graph and their weights.

Public Functions

inline EdgeWeightRange(const Graph &G)
inline EdgeWeightRange()
~EdgeWeightRange() = default
inline EdgeWeightIterator begin() const
inline EdgeWeightIterator end() const
class NeighborIterator

Class to iterate over the in/out neighbors of a node.

Public Types

using value_type = node
using reference = value_type&
using pointer = value_type*
using iterator_category = std::forward_iterator_tag
using difference_type = ptrdiff_t
using self = NeighborIterator

Public Functions

inline NeighborIterator(std::vector<node>::const_iterator nodesIter)
inline NeighborIterator()

WARNING: This contructor is required for Python and should not be used as the iterator is not initialized.

inline NeighborIterator &operator++()
inline NeighborIterator operator++(int)
inline NeighborIterator operator--()
inline NeighborIterator operator--(int)
inline bool operator==(const NeighborIterator &rhs) const
inline bool operator!=(const NeighborIterator &rhs) const
inline node operator*() const
template<bool InEdges = false>
class NeighborRange

Wrapper class to iterate over a range of the neighbors of a node within a for loop.

Public Functions

inline NeighborRange(const Graph &G, node u)
inline NeighborRange()
inline NeighborIterator begin() const
inline NeighborIterator end() const
class NeighborWeightIterator

Class to iterate over the in/out neighbors of a node including the edge weights. Values are std::pair<node, edgeweight>.

Public Types

using value_type = std::pair<node, edgeweight>
using reference = value_type&
using pointer = value_type*
using iterator_category = std::forward_iterator_tag
using difference_type = ptrdiff_t
using self = NeighborWeightIterator

Public Functions

inline NeighborWeightIterator(std::vector<node>::const_iterator nodesIter, std::vector<edgeweight>::const_iterator weightIter)
inline NeighborWeightIterator()

WARNING: This contructor is required for Python and should not be used as the iterator is not initialized.

inline NeighborWeightIterator &operator++()
inline NeighborWeightIterator operator++(int)
inline NeighborWeightIterator operator--()
inline NeighborWeightIterator operator--(int)
inline bool operator==(const NeighborWeightIterator &rhs) const
inline bool operator!=(const NeighborWeightIterator &rhs) const
inline std::pair<node, edgeweight> operator*() const
template<bool InEdges = false>
class NeighborWeightRange

Wrapper class to iterate over a range of the neighbors of a node including the edge weights within a for loop. Values are std::pair<node, edgeweight>.

Public Functions

inline NeighborWeightRange(const Graph &G, node u)
inline NeighborWeightRange()
inline NeighborWeightIterator begin() const
inline NeighborWeightIterator end() const
class NodeIterator

Class to iterate over the nodes of a graph.

Public Types

using value_type = node
using reference = value_type&
using pointer = value_type*
using iterator_category = std::forward_iterator_tag
using difference_type = ptrdiff_t
using self = NodeIterator

Public Functions

inline NodeIterator(const Graph *G, node u)
inline NodeIterator()

WARNING: This constructor is required for Python and should not be used as the iterator is not initialized.

~NodeIterator() = default
inline NodeIterator &operator++()
inline NodeIterator operator++(int)
inline NodeIterator operator--()
inline NodeIterator operator--(int)
inline bool operator==(const NodeIterator &rhs) const noexcept
inline bool operator!=(const NodeIterator &rhs) const noexcept
inline node operator*() const noexcept
class NodeRange

Wrapper class to iterate over a range of the nodes of a graph.

Public Functions

inline NodeRange(const Graph &G)
inline NodeRange()
~NodeRange() = default
inline NodeIterator begin() const noexcept
inline NodeIterator end() const noexcept