Skip to content

num::graph

Defined in header <structures/graph/graph.hpp>

template <typename Weight, std::integral Index>
class graph;

Weighted directed or undirected graph represented as an adjacency list.

Template parameters

  • Weight: scalar type of edge weights (e.g. double, float, int).
  • Index: Integer type used for vertex indices (e.g. num::idx, uint32_t).

Members

member description
using weight_type = Weight
using index_type = Index
explicit graph(Index n = 0, bool directed = false) Construct a graph with n vertices.
void add_edge(Index u, Index v, Weight weight = Weight{1}) Add an undirected edge between u and v with positive weight.
void add_directed_edge(Index u, Index v, Weight weight = Weight{1}) Add a directed edge from u to v with positive weight.
bool has_edge(Index u, Index v) const Check whether an edge exists from u to v.
Weight edge_weight(Index u, Index v) const Return the weight of edge (u, v), or 0 if no edge exists.
Index degree(Index u) const Return the number of incident edges for vertex u.
Weight weighted_degree(Index u) const Return the sum of edge weights incident to vertex u.
view<const graph_edge> neighbors(Index u) const Return view of neighbor edges for vertex u.
Index n_vertices() const noexcept Return the total number of vertices.
Index n_edges() const noexcept Return the total number of edges.
bool is_directed() const noexcept Return whether the graph is directed.