Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add num_edges(g) and has_edge(g) CPOs #96

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/graph/container/compressed_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,13 @@ class compressed_graph_base
return const_vertices_type(g.row_index_.begin(), g.row_index_.end() - 1); // don't include terminating row
}

friend constexpr auto num_edges(const compressed_graph_base& g) {
return static_cast<size_type>(g.col_index_.size());
}
friend constexpr bool has_edge(const compressed_graph_base& g) {
return g.col_index_.size() > 0;
}

friend vertex_id_type vertex_id(const compressed_graph_base& g, const_iterator ui) {
return static_cast<vertex_id_type>(ui - g.row_index_.begin());
}
Expand Down
8 changes: 8 additions & 0 deletions include/graph/container/dynamic_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ class dynamic_graph_base {
edge_adder(edge_type(std::move(e.target_id), std::move(e.value)));
}
}
edge_count_ += 1;
}
}

Expand Down Expand Up @@ -1169,6 +1170,7 @@ class dynamic_graph_base {
edge_adder(edge_type(std::move(e.target_id), std::move(e.value)));
}
}
edge_count_ += 1;
}
}

Expand Down Expand Up @@ -1226,11 +1228,17 @@ class dynamic_graph_base {

private: // Member Variables
vertices_type vertices_;
size_t edge_count_ = 0;

private: // CPO properties
friend constexpr vertices_type& vertices(dynamic_graph_base& g) { return g.vertices_; }
friend constexpr const vertices_type& vertices(const dynamic_graph_base& g) { return g.vertices_; }

friend auto num_edges(const dynamic_graph_base& g) {
return g.edge_count_;
}
friend bool has_edge(const dynamic_graph_base& g) { return g.edge_count_ > 0; }

friend vertex_id_type vertex_id(const dynamic_graph_base& g, typename vertices_type::const_iterator ui) {
return static_cast<vertex_id_type>(ui - g.vertices_.begin());
}
Expand Down
Loading
Loading