Graph Library Random Access Iterators?
Hello all, I am trying to iterate through a list of edges in the boost graph library, but i would like to advance more than one at a time or be able to use random access to an edge in the set. For example: Currently, to find the edge at index in the edge set I have to iterate through all the edges: Edge e; int count = 0; for (edge_range_t er = edges(graph); er.first != er.second; er.first++) { e = (*er.first); if (count == index) break; count++; } return e; I would like something like: Edge e; edge_range_t er = edges(graph); e = (*er[index].first); return e; Is there a way to index with iterators? Regards
On Sat, 6 Mar 2010, Theodore McCormack wrote:
Hello all, I am trying to iterate through a list of edges in the boost graph library, but i would like to advance more than one at a time or be able to use random access to an edge in the set. For example:
Currently, to find the edge at index in the edge set I have to iterate through all the edges:
Edge e; int count = 0; for (edge_range_t er = edges(graph); er.first != er.second; er.first++) { e = (*er.first); if (count == index) break; count++; } return e;
I would like something like:
Edge e; edge_range_t er = edges(graph); e = (*er[index].first); return e;
Is there a way to index with iterators?
Do you need mutability in your graph, or can you create it with a complete edge set at one time? If you do need mutability, passing vecS as the last template argument to adjacency_list (EdgeList) might make it random access, although the documentation does not say so and I am not sure. If you do not need mutability, compressed_sparse_row_graph has an O(lg(E))-time edge_from_index function that takes an index (from 0 to num_edges(g)-1) and returns the corresponding edge. Why do you need random access, though? Maybe there is an alternative way to do what you want. -- Jeremiah Willcock
I need to use mutability in my graph. How would you use the vecS in the
EdgeList for adjacency_list in a random access fashion?
On Sat, Mar 6, 2010 at 1:21 PM, Theodore McCormack
Hello all, I am trying to iterate through a list of edges in the boost graph library, but i would like to advance more than one at a time or be able to use random access to an edge in the set. For example:
Currently, to find the edge at index in the edge set I have to iterate through all the edges:
Edge e; int count = 0; for (edge_range_t er = edges(graph); er.first != er.second; er.first++) { e = (*er.first); if (count == index) break; count++; } return e;
I would like something like:
Edge e; edge_range_t er = edges(graph); e = (*er[index].first); return e;
Is there a way to index with iterators?
Regards
On Sat, 6 Mar 2010, Theodore McCormack wrote:
I need to use mutability in my graph. How would you use the vecS in the EdgeList for adjacency_list in a random access fashion?
Use vecS as the last template argument to adjacency_list and see if that gives you random access. -- Jeremiah Willcock
Thank you Jeremiah for the prompt reply. I have put vecS in the last
template arguement. How would i access the edge list after doing so?
On Sat, Mar 6, 2010 at 7:58 PM, Jeremiah Willcock
On Sat, 6 Mar 2010, Theodore McCormack wrote:
I need to use mutability in my graph. How would you use the vecS in the
EdgeList for adjacency_list in a random access fashion?
Use vecS as the last template argument to adjacency_list and see if that gives you random access.
-- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sat, 6 Mar 2010, Theodore McCormack wrote:
Thank you Jeremiah for the prompt reply. I have put vecS in the last template arguement. How would i access the edge list after doing so?
edges() returns an iterator pair, but I am not sure it's random access. You would need to check, but I suspect vecS makes it random access. -- Jeremiah Willcock PS: Please don't top-post.
Sorry for the top posts, i am new to mailing lists. How do i reply with a
sub-post? I know this is going to be a top post sorry again in advance.
On Sat, Mar 6, 2010 at 8:07 PM, Jeremiah Willcock
On Sat, 6 Mar 2010, Theodore McCormack wrote:
Thank you Jeremiah for the prompt reply. I have put vecS in the last
template arguement. How would i access the edge list after doing so?
edges() returns an iterator pair, but I am not sure it's random access. You would need to check, but I suspect vecS makes it random access.
-- Jeremiah Willcock
PS: Please don't top-post.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sat, Mar 6, 2010 at 12:19 PM, Theodore McCormack
Sorry for the top posts, i am new to mailing lists. How do i reply with a sub-post? I know this is going to be a top post sorry again in advance.
When you reply to a post, you split up and type inside the message you are responding to. This is a good example as to why you should not top post:
A: Yes.
Q: Are you sure?
A: Because it reverses the logical flow of conversation.
Q: Why is top posting annoying in email?
If you are not convinced that it is wrong by the simple example above, now try to mix top and bottom posting:
A: Yes.
Q: Are you sure?
Q: Why is top posting annoying in email? A: Because it reverses the logical flow of conversation.
I don't know about you, but that's simply crazy!
The correct way:
Q: Why is top posting annoying in email? A: Because it reverses the logical flow of conversation. Q: Are you sure? A: Yes.
participants (3)
-
Jeremiah Willcock
-
OvermindDL1
-
Theodore McCormack