Skip to content

Commit

Permalink
fix typos
Browse files Browse the repository at this point in the history
Signed-off-by: Shreeyash Pandey <[email protected]>
  • Loading branch information
bojle committed May 26, 2024
1 parent e828ac4 commit 94c3991
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 92 deletions.
Binary file modified build/doctrees/blog/boost_graphs_remove_vertex.doctree
Binary file not shown.
Binary file modified build/doctrees/environment.pickle
Binary file not shown.
38 changes: 22 additions & 16 deletions build/html/_sources/blog/boost_graphs_remove_vertex.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Here's the code to remove a vertex from a boost graph:

.. code::
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
using Graph = boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, int>;
using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
Expand All @@ -28,7 +31,7 @@ of a bgl are stored internally in a graph, calling `remove_vertex` on this
graph invalidates all iterators to it as all the elements need to be re-arranged
inside the vector. Using invalid iterators will likely cause a segfault.
On the other hand, if `VertexList` is `listS` you're safe, as no iterators are
invalidated. For more information, `refer to the origin doc
invalidated. For more information, `refer to the original doc
<https://www.boost.org/doc/libs/1_85_0/libs/graph/doc/adjacency_list.html>`_

Extended Example
Expand All @@ -51,51 +54,54 @@ removed. Here's the code:

.. code::
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
using Graph = boost::adjacency_list<boost::vecS, boost::listS,
boost::bidirectionalS, int>;
using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
std::vector<Op::Vertex> get_parents(Op::Vertex v, Op::Graph &g) {
std::vector<Op::Vertex> ret;
std::vector<Vertex> get_parents(Vertex v, Graph &g) {
std::vector<Vertex> ret;
auto edges = boost::in_edges(v, g);
for (auto itr = edges.first; itr != edges.second; ++itr) {
Op::Vertex src_v = boost::source(*itr, g);
Vertex src_v = boost::source(*itr, g);
ret.push_back(src_v);
}
return ret;
}
std::vector<Op::Vertex> get_children(Op::Vertex v, Op::Graph &g) {
std::vector<Op::Vertex> ret;
std::vector<Vertex> get_children(Vertex v, Graph &g) {
std::vector<Vertex> ret;
auto edges = boost::out_edges(v, g);
for (auto itr = edges.first; itr != edges.second; ++itr) {
Op::Vertex src_v = boost::target(*itr, g);
Vertex src_v = boost::target(*itr, g);
ret.push_back(src_v);
}
return ret;
}
void connect_parents_to_children(const std::vector<Op::Vertex>& parents,
const std::vector<Op::Vertex>& children, Op::Graph &g) {
for (Op::Vertex i: parents) {
for (Op::Vertex j: children) {
void connect_parents_to_children(const std::vector<Vertex>& parents,
const std::vector<Vertex>& children, Graph &g) {
for (Vertex i: parents) {
for (Vertex j: children) {
std::cout << "connecting " << g[i]->name << " to " << g[j]->name << '\n';
boost::add_edge(i, j, g);
}
}
}
/* remove a vertex but connect its parents to its children */
void safe_remove_vertex(Op::Vertex v, Op::Graph &g) {
std::vector<Op::Vertex> src_vertices = get_parents(v, g);
std::vector<Op::Vertex> dest_vertices = get_children(v, g);
void safe_remove_vertex(Vertex v, Graph &g) {
std::vector<Vertex> src_vertices = get_parents(v, g);
std::vector<Vertex> dest_vertices = get_children(v, g);
connect_parents_to_children(src_vertices, dest_vertices, g);
boost::clear_vertex(v, g);
boost::remove_vertex(v, g);
}
void pass(Op::Graph graph) {
Op::VertexIterator vi, vi_end, next;
void pass(Graph graph) {
VertexIterator vi, vi_end, next;
std::tie(vi, vi_end) = boost::vertices(graph);
for (next = vi; vi != vi_end; vi = next, cnt++) {
Expand Down
48 changes: 27 additions & 21 deletions build/html/blog/boost_graphs_remove_vertex.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/html/searchindex.js

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions docs/_sources/blog/boost_graphs_remove_vertex.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Here's the code to remove a vertex from a boost graph:

.. code::
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
using Graph = boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, int>;
using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
Expand All @@ -28,7 +31,7 @@ of a bgl are stored internally in a graph, calling `remove_vertex` on this
graph invalidates all iterators to it as all the elements need to be re-arranged
inside the vector. Using invalid iterators will likely cause a segfault.
On the other hand, if `VertexList` is `listS` you're safe, as no iterators are
invalidated. For more information, `refer to the origin doc
invalidated. For more information, `refer to the original doc
<https://www.boost.org/doc/libs/1_85_0/libs/graph/doc/adjacency_list.html>`_

Extended Example
Expand All @@ -51,51 +54,54 @@ removed. Here's the code:

.. code::
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
using Graph = boost::adjacency_list<boost::vecS, boost::listS,
boost::bidirectionalS, int>;
using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
std::vector<Op::Vertex> get_parents(Op::Vertex v, Op::Graph &g) {
std::vector<Op::Vertex> ret;
std::vector<Vertex> get_parents(Vertex v, Graph &g) {
std::vector<Vertex> ret;
auto edges = boost::in_edges(v, g);
for (auto itr = edges.first; itr != edges.second; ++itr) {
Op::Vertex src_v = boost::source(*itr, g);
Vertex src_v = boost::source(*itr, g);
ret.push_back(src_v);
}
return ret;
}
std::vector<Op::Vertex> get_children(Op::Vertex v, Op::Graph &g) {
std::vector<Op::Vertex> ret;
std::vector<Vertex> get_children(Vertex v, Graph &g) {
std::vector<Vertex> ret;
auto edges = boost::out_edges(v, g);
for (auto itr = edges.first; itr != edges.second; ++itr) {
Op::Vertex src_v = boost::target(*itr, g);
Vertex src_v = boost::target(*itr, g);
ret.push_back(src_v);
}
return ret;
}
void connect_parents_to_children(const std::vector<Op::Vertex>& parents,
const std::vector<Op::Vertex>& children, Op::Graph &g) {
for (Op::Vertex i: parents) {
for (Op::Vertex j: children) {
void connect_parents_to_children(const std::vector<Vertex>& parents,
const std::vector<Vertex>& children, Graph &g) {
for (Vertex i: parents) {
for (Vertex j: children) {
std::cout << "connecting " << g[i]->name << " to " << g[j]->name << '\n';
boost::add_edge(i, j, g);
}
}
}
/* remove a vertex but connect its parents to its children */
void safe_remove_vertex(Op::Vertex v, Op::Graph &g) {
std::vector<Op::Vertex> src_vertices = get_parents(v, g);
std::vector<Op::Vertex> dest_vertices = get_children(v, g);
void safe_remove_vertex(Vertex v, Graph &g) {
std::vector<Vertex> src_vertices = get_parents(v, g);
std::vector<Vertex> dest_vertices = get_children(v, g);
connect_parents_to_children(src_vertices, dest_vertices, g);
boost::clear_vertex(v, g);
boost::remove_vertex(v, g);
}
void pass(Op::Graph graph) {
Op::VertexIterator vi, vi_end, next;
void pass(Graph graph) {
VertexIterator vi, vi_end, next;
std::tie(vi, vi_end) = boost::vertices(graph);
for (next = vi; vi != vi_end; vi = next, cnt++) {
Expand Down
Loading

0 comments on commit 94c3991

Please sign in to comment.