graph::VVGraph< VertexContent, EdgeContent, compact > Class Template Reference

Class representing a VV graph. More...

#include <graph/vvgraph.h>

Inheritance diagram for graph::VVGraph< VertexContent, EdgeContent, compact >:
Inheritance graph
[legend]

List of all members.

Classes

struct  neighbor_t
 Structure maintaining the data for a single neighbor. More...
struct  search_result_t
 Type of the result of the search for a vertex in a neighborhood. More...
struct  single_neighborhood_t
 Type of the neighborhood of a vertex. More...

Public Types

typedef std::unordered_map
< vertex_t, typename
neighborhood_t::iterator > 
lookup_t
 Type of the fast-search map.
typedef std::list< std::pair
< vertex_t,
single_neighborhood_t > > 
neighborhood_t
 Type of the list of vertexes, together with the neighborhood.
typedef neighborhood_t::value_type neighborhood_value_type
 Shortcut for the value_type of the neighborhood.
typedef neighborhood_t::size_type size_type
 Type of a size.
typedef vertex_t value_type
 Type of the value of the graph as standard container.
Smart pointer types

typedef Arc< EdgeContent > arc_t
 Weak pointer on an arc.
typedef Edge< const EdgeContent > const_edge_t
 Weak pointer on a constant edge.
typedef Edge< EdgeContent > edge_t
 Weak pointer on an edge.
typedef Vertex< VertexContent > vertex_t
 Smart pointer on a vertex.
Iterators

typedef util::CircIterator
< neighbor_iterator
circ_neighbor_iterator
 Iterator used to iterate over the neighbors, but specifying the starting point.
typedef util::range
< circ_neighbor_iterator
circ_neighbor_iterator_range
 Range of circular iterators.
typedef util::CircIterator
< const_neighbor_iterator
const_circ_neighbor_iterator
 Iterator used to iterate over the neighbors, but spcifying the starting point.
typedef util::range
< const_circ_neighbor_iterator
const_circ_neighbor_iterator_range
 Range of circular iterators.
typedef
util::SelectMemberIterator
< typename
neighborhood_t::const_iterator,
const vertex_t,&neighborhood_value_type::first > 
const_iterator
 Constant iterator on the vertexes.
typedef
util::SelectMemberIterator
< typename
edge_list_t::const_iterator,
const vertex_t,&neighbor_t::target
const_neighbor_iterator
 Constant iterator on the neighbors of a vertex.
typedef util::range
< const_neighbor_iterator
const_neighbor_iterator_range
 Constant range of the neighbors of a vertex.
typedef in_edges_t::const_iterator ineighbor_iterator
 Iterator on the incoming neighbors of a vertex.
typedef util::range
< ineighbor_iterator
ineighbor_iterator_range
 Range of the incoming neighbors of a vertex.
typedef
util::SelectMemberIterator
< typename
neighborhood_t::iterator,
const vertex_t,&neighborhood_value_type::first > 
iterator
 Iterator on the vertexes.
typedef
util::SelectMemberIterator
< typename
edge_list_t::iterator,
vertex_t,&neighbor_t::target
neighbor_iterator
 Iterator on the neighbors of a vertex.
typedef util::range
< neighbor_iterator
neighbor_iterator_range
 Range of the neighbors of a vertex.

Public Member Functions

 VVGraph (const VVGraph &copy)
 Copy constructor.
 VVGraph ()
 Default constructor.
Vertex set lookup methods

const vertex_tany () const
 Return a vertex from the graph.
bool contains (const vertex_t &v) const
 Test if v is in the graph.
bool empty () const
 Test if there is any vertex in the graph.
const vertex_toperator[] (size_type idx) const
 Return the element of index idx.
const vertex_treference (vertex_t v) const
 Get a reference on the vertex in the graph.
size_type size () const
 Return the number of vertexes on the graph.
Neighborhood lookup methods

const vertex_tanyIn (const vertex_t &v) const
 Return a vertex in the neighborhood of v.
arc_t arc (const vertex_t &src, const vertex_t &tgt)
 Returns the arc (i.e.
const_edge_t edge (const vertex_t &src, const vertex_t &tgt) const
 Returns the edge from src to tgt.
edge_t edge (const vertex_t &src, const vertex_t &tgt)
 Returns the edge from src to tgt.
bool empty (const vertex_t &v) const
 Test if a vertex has a neighbor.
bool flag (const vertex_t &src, const vertex_t &neighbor)
 Flag a neighbor for quick retrieval.
const vertex_tflagged (const vertex_t &src) const
 Return the flagged neighbor or a null vertex is no neighbor have been flagged.
const vertex_tiAnyIn (const vertex_t &v) const
 Returns any incoming neighbor of v.
bool iEmpty (const vertex_t &v) const
 Test if a vertex has an incoming neighbor.
ineighbor_iterator_range iNeighbors (const vertex_t &v) const
 Return the range of incoming neighbors of v.
size_type iValence (const vertex_t &v) const
 Returns the number of incoming neighbors of v.
const_circ_neighbor_iterator_range neighbors (const vertex_t &v, const vertex_t &n) const
 Return the range of neighbors of v, starting at n.
circ_neighbor_iterator_range neighbors (const vertex_t &v, const vertex_t &n)
 Return the range of neighbors of v, starting at n.
neighbor_iterator_range neighbors (const vertex_t &v)
 Return the range of neighbors of v.
const_neighbor_iterator_range neighbors (const vertex_t &v) const
 Return the constant range of neighbors of v.
const vertex_tnextTo (const vertex_t &v, const vertex_t &neighbor, unsigned int n=1) const
 Returns the nth vertex after neighbor in the neighborhood of v.
const vertex_tprevTo (const vertex_t &v, const vertex_t &ref, unsigned int n=1) const
 Returns the nth vertex before ref in the neighborhood of v.
const vertex_tsource (const arc_t &arc) const
const vertex_tsource (const edge_t &edge) const
 Return the source vertex of the edge.
const vertex_ttarget (const arc_t &arc) const
const vertex_ttarget (const edge_t &edge) const
 Return the target vertex of the edge.
size_type valence (const vertex_t &v) const
 Returns the number of neighbors of v.
STL compatibility methods

const_iterator begin () const
 Returns an iterator on the beginning of the set of vertexes of the graph.
iterator begin ()
 Returns an iterator on the beginning of the set of vertexes of the graph.
void clear (iterator it)
 Clear the outgoing edges of a vertex.
size_type count (const vertex_t &v) const
 Count the number of vertexes v in the graph (can be 0 or 1 only).
const_iterator end () const
 Returns an iterator on the end of the set of vertexes of the graph.
iterator end ()
 Returns an iterator on the end of the set of vertexes of the graph.
iterator erase (iterator pos)
 Erase element at position pos.
void eraseAllEdges (iterator it)
 Clear the neighborhood of a vertex.
circ_neighbor_iterator eraseEdge (const vertex_t &v, circ_neighbor_iterator pos)
 Erase the edge pointed to by the iterator.
neighbor_iterator eraseEdge (const vertex_t &v, neighbor_iterator pos)
 Erase the edge pointed to by the iterator.
const_iterator find (const vertex_t &v) const
 Find the vertex v in the graph.
iterator find (const vertex_t &v)
 Find the vertex v in the graph.
const_neighbor_iterator findIn (const vertex_t &v, const vertex_t &n) const
 Find the vertex n in the neighborhood of v.
neighbor_iterator findIn (const vertex_t &v, const vertex_t &n)
 Find the vertex n in the neighborhood of v.
template<typename Iterator >
void insert (Iterator first, Iterator last)
 Insert all the vertexes from first to last-1 in the graph.
iterator insert (iterator pos, const vertex_t &v)
 Insert a new vertex in the graph.
void store_vertices (std::vector< vertex_t > &vertices, bool cached=true) const
 Store the vertices in a STL container.
Whole structure methods

void clear ()
 Clear the graph.
void eraseAllEdges ()
 Clear all the edges in the graph.
VVGraphoperator= (const VVGraph &other)
 Copy the graph into another graph.
bool operator== (const VVGraph &other) const
 Test equality for the graphs.
template<typename VertexContainer >
VVGraph subgraph (const VertexContainer &vertexes) const
 Extract the subgraph containing the vertexes.
void swap (VVGraph &other)
 Swap the content of two graphs.
Neighborhood edition methods

bool clear (const vertex_t &v)
 Clear the outgoing edges of a vertex.
bool eraseAllEdges (const vertex_t &v)
 Clear the neighborhood of a vertex.
size_type eraseEdge (const vertex_t &src, const vertex_t &tgt)
 Erase the edge from src to tgt.
edge_t insertEdge (const vertex_t &src, const vertex_t &tgt)
 Insert a new edge in the graph, without ordering.
template<typename VertexContainer >
std::vector< edge_tinsertEdges (const vertex_t &src, const VertexContainer &targets)
 Insert a set of edges, keeping the relative order of the list of edges.
edge_t replace (const vertex_t &v, const vertex_t &neighbor, const vertex_t &new_neighbor)
 Replace a vertex by another in a neighborhood.
template<typename VertexContainer >
std::vector< edge_tspliceAfter (const vertex_t &v, const vertex_t &neighbor, const VertexContainer &new_neighbor)
 Splice a list of vertices after a neighbor.
edge_t spliceAfter (const vertex_t &v, const vertex_t &neighbor, const vertex_t &new_neighbor)
 Insert neighbor in the neighborhood of v after reference.
template<typename VertexContainer >
std::vector< edge_tspliceBefore (const vertex_t &v, const vertex_t &neighbor, const VertexContainer &new_neighbor)
 Splice a list of vertices before a neighbor.
edge_t spliceBefore (const vertex_t &v, const vertex_t &neighbor, const vertex_t &new_neighbor)
 Insert neighbor in the neighborhood of v before reference.
Vertex set edition methods

size_type erase (const vertex_t &v)
 Remove a vertex from the graph.
iterator insert (const vertex_t &v)
 Insert a new vertex in the graph.

Protected Types

typedef search_result_t< const
single_neighborhood_t,
int_const_neighbor_iterator
const_neighbor_found_t
 Constant result of a search in the neighborhood.
typedef neighbor_t::edge_list_t edge_list_t
 Type of the list of outgoing neighbors.
typedef neighbor_t::base EdgeCache
typedef __vvgraph_set< compact,
vertex_t >::type 
in_edges_t
 Type of the list of sources of the in-edges.
typedef edge_list_t::const_iterator int_const_neighbor_iterator
 Constant iterator on the outgoing edges.
typedef edge_list_t::iterator int_neighbor_iterator
 Iterator on the outgoing edges.
typedef search_result_t
< single_neighborhood_t,
int_neighbor_iterator
neighbor_found_t
 Result of a search in the neighborhood.
typedef single_neighborhood_t::base VertexCache

Protected Member Functions

const_neighbor_found_t findInVertex (const vertex_t &v, const vertex_t &neighbor) const
 Constant version of findInVertex(const vertex_t&, const vertex_t&).
neighbor_found_t findInVertex (const vertex_t &v, const vertex_t &neighbor)
 Find a vertex neighbor in the neighborhood of v.
neighborhood_t::const_iterator findVertex (const vertex_t &v) const
 Constant version of findVertex(const vertex_t&).
neighborhood_t::iterator findVertex (const vertex_t &v)
 Find a vertex in the graph and returns the iterator on it.
std::pair< ineighbor_iterator,
bool > 
insertInEdge (const vertex_t &v, const vertex_t &new_neighbor)
 Insert v in the in_edges of new_neighbor and return true if the insertion was actually done, or false if v was already there.
void undoInEdge (const vertex_t &new_neighbor, ineighbor_iterator &it)
 Undo the insertion of an in edge as a roll-back mechanism if the whole edge insertion fails.
void updateEdgeCache (const vertex_t &v, typename edge_list_t::iterator new_edge_it, const vertex_t &in_edge)
 Update the edge cache information of vertex v in its neighborhood and the in_edge too.
void updateVertexCache (const vertex_t &v, typename neighborhood_t::iterator it)
 Update the vertex cache for vertex v.

Protected Attributes

intptr_t graph_id
 Unique graph identifier.
lookup_t lookup
 Hash map to optimise look-up.
neighborhood_t neighborhood
 Main data structure containing everything.

Detailed Description

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
class graph::VVGraph< VertexContent, EdgeContent, compact >

Class representing a VV graph.

A VV graph is an oriented rotational graph. That is, the edges of a given vertex have a circular order. That is, if an edge has three edges e1, e2, e3, there is no first edge, but we can say e1 < e2 < e3 < e1. In that case, '<' denote the succession.

VertexContent is the type used to hold the vertex data.

EdgeContent is the type used to hold the edge data. If no type is specified for EdgeContent, then an empty structure is used.

Performance notes

The graph includes two caching mecanisms to improve performances when iterating over the graph and retrieve edge information:

  1. while iterating over the graph, the vertex cache the current iterator. So that accessing the neighborhood of the vertex is constant time (i.e. it's dereferencing the cached iterator).
  2. while iterating over the neighborhood of a vertex, the target vertex (i.e. the one returned by the iteration) cache the iterator on the neighborhood. So that any operation using that specific edge (i.e. getting edge data, splicing, replacing or erasing) is alos constant time.

To make this caching mecanism correct, the cached data are never copied. This means, to make use of the caching mecanism, you have to iterate using constant references (references will end up with compilation errors if used on the graph):

 forall(const vertex &v, S)
 {
   // Here the vertex v has the vertex cache
   forall(const vertex &n, S.neighbors(S)) // Makes use of the cache
   {
     S.edge(v,n)->pos = Point3d(1,2,3); // Uses the edge cache
     S.edge(n,v)->pos = Point3d(3,2,1); // Do not use any cache
   }
   v->pos = Point3d(0,0,0); // Valid
 }
Warning:
Do not iterate using constant references if you ever remove the vertex you iterate on ! (i.e. remove from the graph if you iterate on the graph or remove from the neighborhood if you iterate on the neighborhood)

Even though this code manipulate constant references, modifying the data pointed by the vertex is allowed. The vertexes are coded to allow that. That means if you are using vertexes in a dictionary or a set, using their content to compare them, you must not modify them ! The compiler won't guard you against it.

Definition at line 362 of file vvgraph.h.


Member Typedef Documentation

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef Arc<EdgeContent> graph::VVGraph< VertexContent, EdgeContent, compact >::arc_t

Weak pointer on an arc.

When an object of this type is destroyed, the content of the primary edge (i.e. the edge source -> target) is copied into the other.

Definition at line 394 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::CircIterator<neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::circ_neighbor_iterator

Iterator used to iterate over the neighbors, but specifying the starting point.

Definition at line 615 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::range<circ_neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::circ_neighbor_iterator_range

Range of circular iterators.

Definition at line 620 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::CircIterator<const_neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::const_circ_neighbor_iterator

Iterator used to iterate over the neighbors, but spcifying the starting point.

Definition at line 653 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::range<const_circ_neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::const_circ_neighbor_iterator_range

Range of circular iterators.

Definition at line 658 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef Edge<const EdgeContent> graph::VVGraph< VertexContent, EdgeContent, compact >::const_edge_t

Weak pointer on a constant edge.

Definition at line 387 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::SelectMemberIterator<typename neighborhood_t::const_iterator, const vertex_t, &neighborhood_value_type::first> graph::VVGraph< VertexContent, EdgeContent, compact >::const_iterator

Constant iterator on the vertexes.

Definition at line 599 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef search_result_t<const single_neighborhood_t, int_const_neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::const_neighbor_found_t [protected]

Constant result of a search in the neighborhood.

Definition at line 1731 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::SelectMemberIterator<typename edge_list_t::const_iterator, const vertex_t, &neighbor_t::target> graph::VVGraph< VertexContent, EdgeContent, compact >::const_neighbor_iterator

Constant iterator on the neighbors of a vertex.

Definition at line 641 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::range<const_neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::const_neighbor_iterator_range

Constant range of the neighbors of a vertex.

The first element of the pair is a constant iterator on the beginning of the range, the second element is the past-the-end constant iterator.

Definition at line 647 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef neighbor_t::edge_list_t graph::VVGraph< VertexContent, EdgeContent, compact >::edge_list_t [protected]

Type of the list of outgoing neighbors.

Definition at line 498 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef Edge<EdgeContent> graph::VVGraph< VertexContent, EdgeContent, compact >::edge_t

Weak pointer on an edge.

Definition at line 383 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef __vvgraph_set<compact,vertex_t>::type graph::VVGraph< VertexContent, EdgeContent, compact >::in_edges_t [protected]

Type of the list of sources of the in-edges.

Definition at line 503 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef in_edges_t::const_iterator graph::VVGraph< VertexContent, EdgeContent, compact >::ineighbor_iterator

Iterator on the incoming neighbors of a vertex.

An incoming neighbor is a source vertex of an edge whose target is the current vertex.

Definition at line 628 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::range<ineighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::ineighbor_iterator_range

Range of the incoming neighbors of a vertex.

See also:
ineighbor_iterator

Definition at line 635 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef edge_list_t::const_iterator graph::VVGraph< VertexContent, EdgeContent, compact >::int_const_neighbor_iterator [protected]

Constant iterator on the outgoing edges.

Definition at line 1722 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef edge_list_t::iterator graph::VVGraph< VertexContent, EdgeContent, compact >::int_neighbor_iterator [protected]

Iterator on the outgoing edges.

Definition at line 1718 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::SelectMemberIterator<typename neighborhood_t::iterator, const vertex_t, &neighborhood_value_type::first> graph::VVGraph< VertexContent, EdgeContent, compact >::iterator

Iterator on the vertexes.

Definition at line 594 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef std::unordered_map<vertex_t, typename neighborhood_t::iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::lookup_t

Type of the fast-search map.

Definition at line 575 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef search_result_t<single_neighborhood_t, int_neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::neighbor_found_t [protected]

Result of a search in the neighborhood.

Definition at line 1727 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::SelectMemberIterator<typename edge_list_t::iterator, vertex_t, &neighbor_t::target> graph::VVGraph< VertexContent, EdgeContent, compact >::neighbor_iterator

Iterator on the neighbors of a vertex.

Definition at line 605 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef util::range<neighbor_iterator> graph::VVGraph< VertexContent, EdgeContent, compact >::neighbor_iterator_range

Range of the neighbors of a vertex.

Definition at line 609 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef std::list<std::pair<vertex_t, single_neighborhood_t> > graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood_t

Type of the list of vertexes, together with the neighborhood.

Definition at line 570 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef neighborhood_t::value_type graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood_value_type

Shortcut for the value_type of the neighborhood.

Definition at line 581 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef neighborhood_t::size_type graph::VVGraph< VertexContent, EdgeContent, compact >::size_type

Type of a size.

Definition at line 586 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef vertex_t graph::VVGraph< VertexContent, EdgeContent, compact >::value_type

Type of the value of the graph as standard container.

Definition at line 400 of file vvgraph.h.

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
typedef Vertex<VertexContent> graph::VVGraph< VertexContent, EdgeContent, compact >::vertex_t

Smart pointer on a vertex.

Definition at line 378 of file vvgraph.h.


Constructor & Destructor Documentation

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
graph::VVGraph< VertexContent, EdgeContent, compact >::VVGraph (  )  [inline]

Default constructor.

Creates an empty VV graph

Definition at line 407 of file vvgraph.h.

00408           : graph_id(graph::getNextGraphId())
00409           {}

template<GRAPH_TEMPLATE >
graph::VVGraph< GRAPH_TEMPLATE >::VVGraph ( const VVGraph< VertexContent, EdgeContent, compact > &  copy  )  [inline]

Copy constructor.

Maintains the caches in a valid state

Definition at line 2699 of file vvgraph.h.

02700     : graph_id(graph::getNextGraphId())
02701     {
02702       *this = copy;
02703     }


Member Function Documentation

template<GRAPH_TEMPLATE >
const VVGraph< GRAPH_ARGS >::vertex_t & graph::VVGraph< GRAPH_TEMPLATE >::any (  )  const [inline]

Return a vertex from the graph.

Returns:
A vertex of the graph, or a null vertex if the graph is empty.

Example:

 vvgraph S;
 // Add vertices in S
 const vertex& v = S.any(); // Get a vertex in S

Definition at line 1975 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::begin(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, and graph::Vertex< VertexContent >::null.

01976     {
01977       if(neighborhood.empty())
01978         return vertex_t::null;
01979       return *begin();
01980     }

template<GRAPH_TEMPLATE >
const VVGraph< GRAPH_ARGS >::vertex_t & graph::VVGraph< GRAPH_TEMPLATE >::anyIn ( const vertex_t v  )  const [inline]

Return a vertex in the neighborhood of v.

Returns:
A vertex in the neighborhood of v, or a null vertex if v is not in the graph or v has no neighborhood.

Example:

 vvgraph S;
 forall(const vertex& v, S)
 {
   const vertex& n = S.anyIn(v);
   if(n)
   {
     edge e = S.edge(v,n); // e exist !
   }
 }

Definition at line 1993 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, and graph::Vertex< VertexContent >::null.

01994     {
01995       if(v.isNull())
01996         return vertex_t::null;//vertex_t(0);
01997       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
01998       if(it_found == neighborhood.end() || it_found->second.edges.empty())
01999         return vertex_t::null;//vertex_t(0);
02000       const edge_list_t& lst = it_found->second.edges;
02001       return lst.front().target;
02002     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::arc_t graph::VVGraph< GRAPH_TEMPLATE >::arc ( const vertex_t src,
const vertex_t tgt 
) [inline]

Returns the arc (i.e.

undirected edge) between src and tgt.

When the arc is destroyed, the values of both half-edge are synchronized.

Example:

 struct VertexContent();
 struct EdgeContent {int a; }
 typedef graph::VVGraph<VertexContent,EdgeContent> vvgraph;
 typedef vvgraph::vertex_t vertex;
 typedef vvgraph::arc_t arc;
 typedef vvgraph::edge_t edge;
 // ...

 vvgraph S;
 // initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
     if(v<n)
       S.arc(v,n)->a = 5
  }

At the end, all edges have a value of 5 for a, even though we applied the function to only half the edges.

Definition at line 2383 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::Vertex< VertexContent >::id(), and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it.

02385     {
02386       neighbor_found_t found = this->findInVertex(src, tgt);
02387       if(!found)
02388         return arc_t();
02389       neighbor_found_t other = this->findInVertex(tgt, src);
02390       if(!other)
02391         return arc_t();
02392       return arc_t(src.id(), tgt.id(), &*found.it, &*other.it);
02393     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
const_iterator graph::VVGraph< VertexContent, EdgeContent, compact >::begin (  )  const [inline]

Returns an iterator on the beginning of the set of vertexes of the graph.

Definition at line 1558 of file vvgraph.h.

01558 { return neighborhood.begin(); }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
iterator graph::VVGraph< VertexContent, EdgeContent, compact >::begin (  )  [inline]

Returns an iterator on the beginning of the set of vertexes of the graph.

Definition at line 1549 of file vvgraph.h.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::any().

01549 { return neighborhood.begin(); }

template<GRAPH_TEMPLATE >
void graph::VVGraph< GRAPH_TEMPLATE >::clear ( iterator  it  )  [inline]

Clear the outgoing edges of a vertex.

Definition at line 1910 of file vvgraph.h.

References util::SelectMemberIterator< Iterator, T, member, Reference, Pointer >::base(), and graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex().

01911     {
01912       const vertex_t& v = *it;
01913       for(typename edge_list_t::iterator it_el = it.base()->second.edges.begin() ;
01914           it_el != it.base()->second.edges.end() ; ++it_el)
01915       {
01916         typename neighborhood_t::iterator it_found = this->findVertex(it_el->target);
01917         it_found->second.in_edges.erase(v);
01918       }
01919       it.base()->second.edges.clear();
01920     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
void graph::VVGraph< VertexContent, EdgeContent, compact >::clear (  )  [inline]

Clear the graph.

Definition at line 1474 of file vvgraph.h.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::clear().

01474 { neighborhood.clear(); lookup.clear();  }

template<GRAPH_TEMPLATE >
bool graph::VVGraph< GRAPH_TEMPLATE >::clear ( const vertex_t v  )  [inline]

Clear the outgoing edges of a vertex.

Example:

 vvgraph S;
 // Initialize S
 forall(const vertex& v, S)
 {
   if(condition)
   {
     S.clear(v);
     assert(S.empty(v));
   }
 }

Definition at line 1898 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::clear(), graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::clear(), and vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::clearOldGraphs().

01899     {
01900       typename neighborhood_t::iterator it_found = this->findVertex(v);
01901       if(it_found != neighborhood.end() )
01902       {
01903         clear(it_found);
01904         return true;
01905       }
01906       return false;
01907     }

template<GRAPH_TEMPLATE >
bool graph::VVGraph< GRAPH_TEMPLATE >::contains ( const vertex_t v  )  const [inline]

Test if v is in the graph.

Returns:
true is v is in the graph.

Example:

 vvgraph S;
 vertex v;
 S.insert(v);
 assert(S.contains(v));

Definition at line 2253 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph().

02254     {
02255       return this->findVertex(v) != neighborhood.end();
02256     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::size_type graph::VVGraph< GRAPH_TEMPLATE >::count ( const vertex_t v  )  const [inline]

Count the number of vertexes v in the graph (can be 0 or 1 only).

Definition at line 1924 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::lookup.

01925     {
01926       return lookup.count(v);
01927     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::const_edge_t graph::VVGraph< GRAPH_TEMPLATE >::edge ( const vertex_t src,
const vertex_t tgt 
) const [inline]

Returns the edge from src to tgt.

If the edge does not exists, returns a null edge.

Example:

 struct VertexContent {};
 struct EdgeContent { int a; }
 typedef graph::VVGraph<VertexContent,EdgeContent> vvgraph;
 typedef vvgraph::vertex_t vertex;
 typedef vvgraph::edge_t edge;
 typedef vvgraph::const_edge_t const_edge;
 // ...

 void fct(const vvgraph& S)
 {
   forall(const vertex& v, S)
   {
     forall(const vertex& n, S.neighbors(v))
     {
       const_edge e = S.edge(v,n);
       cout << e->a << endl; // Here e->a cannot be modified
     }
   }
 }

Definition at line 2397 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::Vertex< VertexContent >::id(), and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it.

02399     {
02400       const_neighbor_found_t found = this->findInVertex(src, tgt);
02401       if(!found)
02402         return const_edge_t();
02403       return const_edge_t(src.id(), tgt.id(), &*found.it);
02404     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::edge_t graph::VVGraph< GRAPH_TEMPLATE >::edge ( const vertex_t src,
const vertex_t tgt 
) [inline]

Returns the edge from src to tgt.

If the edge does not exists, returns a null edge.

Example:

 struct VertexContent {};
 struct EdgeContent { int a; }
 typedef graph::VVGraph<VertexContent,EdgeContent> vvgraph;
 typedef vvgraph::vertex_t vertex;
 typedef vvgraph::edge_t edge;
 // ...

 vvgraph S;
 // initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     edge e = S.edge(v,n);
     e->a = 10;
   }
 }

Definition at line 2372 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::Vertex< VertexContent >::id(), and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it.

Referenced by algorithms::split().

02374     {
02375       neighbor_found_t found = this->findInVertex(src, tgt);
02376       if(!found)
02377         return edge_t();
02378       return edge_t(src.id(), tgt.id(), &*found.it);
02379     }

template<GRAPH_TEMPLATE >
bool graph::VVGraph< GRAPH_TEMPLATE >::empty ( const vertex_t v  )  const [inline]

Test if a vertex has a neighbor.

Returns false if it does. If a vertex is not in the graph, it is considered as having no neighbor. In the same way, the null vertex has no neighbors.

Example:

 vvgraph S;
 // initialize S
 forall(cnst vertex& v, S)
 {
   if(!S.empty(v))
   {
      const vertex& n = S.anyIn(v);
      // Working with n a neighbor of v
   }
 }

Definition at line 2017 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02018     {
02019       if(v.isNull())
02020         return true;
02021       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02022       if(it_found == neighborhood.end())
02023         return true;
02024       return it_found->second.edges.empty();
02025     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
bool graph::VVGraph< VertexContent, EdgeContent, compact >::empty (  )  const [inline]

Test if there is any vertex in the graph.

Definition at line 796 of file vvgraph.h.

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::border().

00796 { return neighborhood.empty(); }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
const_iterator graph::VVGraph< VertexContent, EdgeContent, compact >::end (  )  const [inline]

Returns an iterator on the end of the set of vertexes of the graph.

Definition at line 1562 of file vvgraph.h.

01562 { return neighborhood.end(); }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
iterator graph::VVGraph< VertexContent, EdgeContent, compact >::end (  )  [inline]

Returns an iterator on the end of the set of vertexes of the graph.

Definition at line 1553 of file vvgraph.h.

01553 { return neighborhood.end(); }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::iterator graph::VVGraph< GRAPH_TEMPLATE >::erase ( iterator  pos  )  [inline]

Erase element at position pos.

And return the iterator on the next element (as required for sequence containers in C++)

Definition at line 1817 of file vvgraph.h.

References util::SelectMemberIterator< Iterator, T, member, Reference, Pointer >::base(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseAllEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

01818     {
01819       eraseAllEdges(it);
01820       lookup.erase(*it);
01821       return neighborhood.erase(it.base());
01822     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::size_type graph::VVGraph< GRAPH_TEMPLATE >::erase ( const vertex_t v  )  [inline]

Remove a vertex from the graph.

Parameters:
v vertex to erase
Returns:
1 if the vertex was erased, 0 else.

Example:

 vvgraph S;
 // Add vertices to S
 vertex v = S.any();
 S.erase(v); // Remove a vertex of S

Definition at line 1826 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::eraseAllEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::deleteCellInGraphs(), vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::deleteJunction(), and vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::mergeCells().

01827     {
01828       if(eraseAllEdges(v))
01829       {
01830         typename lookup_t::iterator it_found = lookup.find(v);
01831         if(it_found == lookup.end()) return 0;
01832         typename neighborhood_t::iterator it = it_found->second;
01833         neighborhood.erase(it);
01834         lookup.erase(v);
01835         return 1;
01836       }
01837       return 0;
01838     }

template<GRAPH_TEMPLATE >
void graph::VVGraph< GRAPH_TEMPLATE >::eraseAllEdges ( iterator  it  )  [inline]

Clear the neighborhood of a vertex.

All edges, to and from *it will be erased.

Definition at line 1864 of file vvgraph.h.

References util::SelectMemberIterator< Iterator, T, member, Reference, Pointer >::base(), graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood.

01865     {
01866       const vertex_t& v = *it_found;
01867       for(typename edge_list_t::iterator it_el = it_found.base()->second.edges.begin() ;
01868           it_el != it_found.base()->second.edges.end() ; ++it_el)
01869       {
01870         typename lookup_t::iterator it_found = lookup.find(it_el->target);
01871         if(it_found != lookup.end())
01872           it_found->second->second.in_edges.erase(v);
01873       }
01874       it_found.base()->second.edges.clear();
01875       it_found.base()->second.flagged = 0;
01876       // Remove the incoming edges
01877       in_edges_t &in_edges = it_found.base()->second.in_edges;
01878       for( typename in_edges_t::iterator it = in_edges.begin() ;
01879            it != in_edges.end() ; ++it )
01880       {
01881 #ifndef VVGRAPH_NO_EDGE_CACHE
01882         EdgeCache *cache = reinterpret_cast<EdgeCache*>(it->cache);
01883         if(!cache or !cache->eraseEdge())
01884         {
01885 #endif
01886           neighbor_found_t found = findInVertex(*it, v);
01887           found.neighborhood->edges.erase(found.it);
01888           if(found.neighborhood->flagged && *found.neighborhood->flagged == v) found.neighborhood->flagged = 0;
01889 #ifndef VVGRAPH_NO_EDGE_CACHE
01890         }
01891 #endif
01892       }
01893       in_edges.clear();
01894     }

template<GRAPH_TEMPLATE >
void graph::VVGraph< GRAPH_TEMPLATE >::eraseAllEdges (  )  [inline]

Clear all the edges in the graph.

Example:

 vvgraph S;
 // Initialize S
 vvgraph::size_type s1 = S.size(); // Save the number of vertices
 S.eraseAllEdges();
 assert(s1 == S.size()); // The number of vertices didn't change
 forall(const vertex& v, S)
 {
   assert(S.empty(v)); // No neighbor
 }

Definition at line 1840 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::erase(), and graph::VVGraph< VertexContent, EdgeContent, compact >::eraseAllEdges().

01841     {
01842       for(typename neighborhood_t::iterator it = neighborhood.begin();
01843           it != neighborhood.end() ; ++it)
01844       {
01845         it->second.edges.clear();
01846         it->second.in_edges.clear();
01847         it->second.flagged = 0;
01848       }
01849     }

template<GRAPH_TEMPLATE >
bool graph::VVGraph< GRAPH_TEMPLATE >::eraseAllEdges ( const vertex_t v  )  [inline]

Clear the neighborhood of a vertex.

All edges, to and from v will be erased.

Example:

 vvgraph S;
 // Initialize S
 forall(const vertex& v, S)
 {
   if(condition)
   {
     S.eraseAllEdges(v);
     assert(S.empty(v)); // No outgoing edges
     assert(S.iEmpty(v)); // No incoming edges
   }
 }

Definition at line 1852 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::eraseAllEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

01853     {
01854       typename neighborhood_t::iterator it_found = this->findVertex(v);
01855       if(it_found != neighborhood.end() )
01856       {
01857         eraseAllEdges(it_found);
01858         return true;
01859       }
01860       return false;
01861     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::circ_neighbor_iterator graph::VVGraph< GRAPH_TEMPLATE >::eraseEdge ( const vertex_t v,
circ_neighbor_iterator  pos 
) [inline]

Erase the edge pointed to by the iterator.

Definition at line 2229 of file vvgraph.h.

References util::CircIterator< ForwardIterator >::end(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseEdge(), and util::CircIterator< ForwardIterator >::isInitIterator().

02230     {
02231       neighbor_iterator nit = eraseEdge(v, pos.base());
02232       if(pos.isInitIterator(nit))
02233         return pos.end();
02234       return circ_neighbor_iterator(pos, nit);
02235     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::neighbor_iterator graph::VVGraph< GRAPH_TEMPLATE >::eraseEdge ( const vertex_t v,
neighbor_iterator  pos 
) [inline]

Erase the edge pointed to by the iterator.

Definition at line 2209 of file vvgraph.h.

References util::SelectMemberIterator< Iterator, T, member, Reference, Pointer >::base(), graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02210     {
02211       typename neighborhood_t::iterator it_found = this->findVertex(v);
02212       if(it_found == neighborhood.end())
02213         return neighbor_iterator();
02214       const vertex_t& n = *pos;
02215       typename neighborhood_t::iterator it_found2 = this->findVertex(n);
02216       if(it_found2 == neighborhood.end())
02217         return neighbor_iterator();
02218       size_type result = it_found2->second.in_edges.erase(v);
02219       if(result)
02220       {
02221         typename edge_list_t::iterator it = pos.base();
02222         return it_found->second.edges.erase(it);
02223       }
02224       return neighbor_iterator();
02225     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::size_type graph::VVGraph< GRAPH_TEMPLATE >::eraseEdge ( const vertex_t src,
const vertex_t tgt 
) [inline]

Erase the edge from src to tgt.

Returns:
True if successful.

Example:

 vvgraph S;
 // Initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     if(condition)
     {
       S.eraseEdge(v,n);
       break; // The iteration must not continue after the neighborhood has been altered
     }
   }
 }

Definition at line 2239 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::eraseEdge(), and algorithms::split().

02240     {
02241       neighbor_found_t found = this->findInVertex(v, n);
02242       if(!found)
02243         return 0;
02244       if(found.neighborhood->flagged && *found.neighborhood->flagged == n) found.neighborhood->flagged = 0;
02245       found.neighborhood->edges.erase(found.it);
02246       typename lookup_t::iterator it_found = lookup.find(n);
02247       if(it_found != lookup.end())
02248         it_found->second->second.in_edges.erase(v);
02249       return 1;
02250     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
const_iterator graph::VVGraph< VertexContent, EdgeContent, compact >::find ( const vertex_t v  )  const [inline]

Find the vertex v in the graph.

Returns:
An iterator on v if found, or end()

Definition at line 1615 of file vvgraph.h.

01615 { return this->findVertex(v); }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
iterator graph::VVGraph< VertexContent, EdgeContent, compact >::find ( const vertex_t v  )  [inline]

Find the vertex v in the graph.

Returns:
An iterator on v if found, or end()

Definition at line 1609 of file vvgraph.h.

01609 { return this->findVertex(v); }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::const_neighbor_iterator graph::VVGraph< GRAPH_TEMPLATE >::findIn ( const vertex_t v,
const vertex_t n 
) const [inline]

Find the vertex n in the neighborhood of v.

Returns:
  • An iterator on n in the neighborhood of v, if found
  • An iterator on the end of the neighborhood if n is not found in v
  • Otherwise, the result is undefined

Definition at line 2199 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood.

02200     {
02201       const_neighbor_found_t found = this->findInVertex(v, n);
02202       if(found.neighborhood)
02203         return const_neighbor_iterator(found.it);
02204       return const_neighbor_iterator(found.it);
02205     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::neighbor_iterator graph::VVGraph< GRAPH_TEMPLATE >::findIn ( const vertex_t v,
const vertex_t n 
) [inline]

Find the vertex n in the neighborhood of v.

Returns:
  • An iterator on n in the neighborhood of v, if found
  • An iterator on the end of the neighborhood if n is not found in v
  • Otherwise, the result is undefined

Definition at line 2189 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood.

02190     {
02191       neighbor_found_t found = this->findInVertex(v, n);
02192       if(found.neighborhood)
02193         return neighbor_iterator(found.it);
02194       return neighbor_iterator();
02195     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::const_neighbor_found_t graph::VVGraph< GRAPH_TEMPLATE >::findInVertex ( const vertex_t v,
const vertex_t neighbor 
) const [inline, protected]

Constant version of findInVertex(const vertex_t&, const vertex_t&).

Definition at line 2149 of file vvgraph.h.

References graph::Vertex< VertexContent >::cache, graph::Vertex< VertexContent >::cache_source, graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::Vertex< VertexContent >::isNull(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02150     {
02151       if(v.isNull() || n.isNull() || v == n)
02152         return const_neighbor_found_t();
02153 #ifndef VVGRAPH_NO_EDGE_CACHE
02154       if(n.cache_source == v.id())
02155       {
02156         EdgeCache  *cache = reinterpret_cast<EdgeCache*>(n.cache);
02157         if(cache->graph_id() == graph_id)
02158         {
02159           return const_neighbor_found_t(cache->it(), cache->neighborhood());
02160         }
02161       }
02162       else if(v.cache_source == v.id())
02163       {
02164         EdgeCache *cache = reinterpret_cast<EdgeCache*>(v.cache);
02165         if(cache->graph_id() == graph_id and cache->it()->target == n)
02166         {
02167           return const_neighbor_found_t(cache->it(), cache->neighborhood());
02168         }
02169       }
02170 #endif // VVGRAPH_NO_EDGE_CACHE
02171       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02172       if(it_found == neighborhood.end())
02173         return const_neighbor_found_t();
02174       const edge_list_t &lst = it_found->second.edges;
02175       const single_neighborhood_t &neighborhood = it_found->second;
02176       for(typename edge_list_t::const_iterator it = lst.begin() ;
02177           it != lst.end() ; ++it)
02178       {
02179         if(it->target == n)
02180         {
02181           return const_neighbor_found_t(it, &neighborhood);
02182         }
02183       }
02184       return const_neighbor_found_t(lst.end(), &neighborhood, false);
02185     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::neighbor_found_t graph::VVGraph< GRAPH_TEMPLATE >::findInVertex ( const vertex_t v,
const vertex_t neighbor 
) [inline, protected]

Find a vertex neighbor in the neighborhood of v.

If 'v' is in the graph and 'neighbor' is in its neighborhood, the result is convertible to true, 'neighborhood' points toward the neighborhood structure and 'it' points toward the neighbor.

If 'v' is in the graph, but 'neighbor' is not in the neighborhood, the result is convertible to false, 'neighborhood' points toward the neighborhood structure and 'it' is neighborhood->edges.end().

If v is not in the graph, the result is convertible to false and the address of the stored neighborhood is 0.

Definition at line 2109 of file vvgraph.h.

References graph::Vertex< VertexContent >::cache, graph::Vertex< VertexContent >::cache_source, graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::Vertex< VertexContent >::isNull(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::arc(), graph::VVGraph< VertexContent, EdgeContent, compact >::edge(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseAllEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::findIn(), graph::VVGraph< VertexContent, EdgeContent, compact >::flag(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighbors(), graph::VVGraph< VertexContent, EdgeContent, compact >::nextTo(), graph::VVGraph< VertexContent, EdgeContent, compact >::prevTo(), graph::VVGraph< VertexContent, EdgeContent, compact >::replace(), graph::VVGraph< VertexContent, EdgeContent, compact >::spliceAfter(), graph::VVGraph< VertexContent, EdgeContent, compact >::spliceBefore(), and graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph().

02110     {
02111       if(v.isNull() || n.isNull() || v == n)
02112         return neighbor_found_t();
02113 #ifndef VVGRAPH_NO_EDGE_CACHE
02114       if(n.cache_source == v.id())
02115       {
02116         EdgeCache* cache = reinterpret_cast<EdgeCache*>(n.cache);
02117         if(cache->graph_id() == graph_id)
02118         {
02119           return neighbor_found_t(cache->it(), cache->neighborhood());
02120         }
02121       }
02122       else if(v.cache_source == v.id())
02123       {
02124         EdgeCache* cache = reinterpret_cast<EdgeCache*>(v.cache);
02125         if(cache->graph_id() == graph_id and cache->it()->target == n)
02126         {
02127           return neighbor_found_t(cache->it(), cache->neighborhood());
02128         }
02129       }
02130 #endif // VVGRAPH_NO_EDGE_CACHE
02131       typename neighborhood_t::iterator it_found = this->findVertex(v);
02132       if(it_found == neighborhood.end())
02133         return neighbor_found_t();
02134       edge_list_t &lst = it_found->second.edges;
02135       single_neighborhood_t &neighborhood = it_found->second;
02136       for(typename edge_list_t::iterator it = lst.begin() ;
02137           it != lst.end() ; ++it)
02138       {
02139         if(it->target == n)
02140         {
02141           return neighbor_found_t(it, &neighborhood);
02142         }
02143       }
02144       return neighbor_found_t(lst.end(), &neighborhood, false);
02145     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::neighborhood_t::const_iterator graph::VVGraph< GRAPH_TEMPLATE >::findVertex ( const vertex_t v  )  const [inline, protected]

Constant version of findVertex(const vertex_t&).

Definition at line 2088 of file vvgraph.h.

References graph::Vertex< VertexContent >::cache, graph::Vertex< VertexContent >::cache_source, graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02089     {
02090 #ifndef VVGRAPH_NO_VERTEX_CACHE
02091       if(v.cache)
02092       {
02093         if(v.cache_source == 0)
02094         {
02095           VertexCache* cache = reinterpret_cast<VertexCache*>(v.cache);
02096           if(cache->graph_id() == graph_id)
02097             return cache->neighborhood();
02098         }
02099       }
02100 #endif // VVGRAPH_NO_VERTEX_CACHE
02101       typename lookup_t::const_iterator it_found = lookup.find(v);
02102       if(it_found != lookup.end())
02103         return it_found->second;
02104       return neighborhood.end();
02105     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::neighborhood_t::iterator graph::VVGraph< GRAPH_TEMPLATE >::findVertex ( const vertex_t v  )  [inline, protected]

Find a vertex in the graph and returns the iterator on it.

Goal is to introduce a new optimization. When iterating over the vertices of the graph, they will cache their own iterator. So accessing their neighborhood would be constant time.

Definition at line 2065 of file vvgraph.h.

References graph::Vertex< VertexContent >::cache, graph::Vertex< VertexContent >::cache_source, graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::anyIn(), graph::VVGraph< VertexContent, EdgeContent, compact >::clear(), graph::VVGraph< VertexContent, EdgeContent, compact >::contains(), graph::VVGraph< VertexContent, EdgeContent, compact >::empty(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseAllEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseEdge(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::find(), graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::flagged(), graph::VVGraph< VertexContent, EdgeContent, compact >::iAnyIn(), graph::VVGraph< VertexContent, EdgeContent, compact >::iEmpty(), graph::VVGraph< VertexContent, EdgeContent, compact >::iNeighbors(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::iValence(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighbors(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::reference(), graph::VVGraph< VertexContent, EdgeContent, compact >::replace(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::source(), graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::target(), and graph::VVGraph< VertexContent, EdgeContent, compact >::valence().

02066     {
02067 #ifndef VVGRAPH_NO_VERTEX_CACHE
02068       if(v.cache)
02069       {
02070         if(v.cache_source == 0)
02071         {
02072           VertexCache* cache = reinterpret_cast<VertexCache*>(v.cache);
02073           if(cache->graph_id() == graph_id)
02074           {
02075             return cache->neighborhood();
02076           }
02077         }
02078       }
02079 #endif // VVGRAPH_NO_VERTEX_CACHE
02080       typename lookup_t::const_iterator it_found = lookup.find(v);
02081       if(it_found != lookup.end())
02082         return it_found->second;
02083       return neighborhood.end();
02084     }

template<GRAPH_TEMPLATE >
bool graph::VVGraph< GRAPH_TEMPLATE >::flag ( const vertex_t src,
const vertex_t neighbor 
) [inline]

Flag a neighbor for quick retrieval.

Returns:
true if the vertex has been correctly flagged

Example:

 vvgraph S;
 // Initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     if(condition(v,n))
     {
       S.flag(v,n);
       break;
     }
   }
 }
 // ...
 forall(const vertex& v, S)
 {
   const vertex& n = S.flagged(v);
   if(n) // If a neighbor has been flagged
   {
     // Work with the flagged neighbor
   }
 }

Definition at line 2407 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood.

02409     {
02410       neighbor_found_t found = this->findInVertex(src, neighbor);
02411       if(!found)
02412         return false;
02413       found.neighborhood->flagged = &(found.it->target);
02414       return true;
02415     }

template<GRAPH_TEMPLATE >
const VVGraph< GRAPH_ARGS >::vertex_t & graph::VVGraph< GRAPH_TEMPLATE >::flagged ( const vertex_t src  )  const [inline]

Return the flagged neighbor or a null vertex is no neighbor have been flagged.

See also:
VVGraph::flag(const vertex_t&, const vertex_t&)

Definition at line 2419 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, and graph::Vertex< VertexContent >::null.

02420     {
02421       typename neighborhood_t::const_iterator found = this->findVertex(src);
02422       if(found == neighborhood.end() or found->second.flagged == 0)
02423         return vertex_t::null;
02424       return *found->second.flagged;
02425     }

template<GRAPH_TEMPLATE >
const VVGraph< GRAPH_ARGS >::vertex_t & graph::VVGraph< GRAPH_TEMPLATE >::iAnyIn ( const vertex_t v  )  const [inline]

Returns any incoming neighbor of v.

Returns:
A vertex in the incoming neighborhood of v, or a null vertex if v is not in the graph or v has no incoming neighbor.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& n, S)
 {
   const vertex& v = S.iAnyIn(v);
   if(v)
   {
     edge e = S.edge(v, n);
     // Work with e the edge from v to n
   }
 }

Definition at line 2029 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, and graph::Vertex< VertexContent >::null.

02030     {
02031       if(v.isNull())
02032         return vertex_t::null;//vertex_t(0);
02033       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02034       if(it_found == neighborhood.end() || it_found->second.in_edges.empty())
02035         return vertex_t::null;//vertex_t(0);
02036       const in_edges_t& lst = it_found->second.in_edges;
02037       return *lst.begin();
02038     }

template<GRAPH_TEMPLATE >
bool graph::VVGraph< GRAPH_TEMPLATE >::iEmpty ( const vertex_t v  )  const [inline]

Test if a vertex has an incoming neighbor.

Returns false if it does. If a vertex is not in the graph, it is considered as having no incoming neighbor. In the same way, the null vertex has no incoming neighbors.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& n, S)
 {
   if(!S.iEmpty(n))
   {
     const vertex& v = S.iAnyIn(n);
     edge e = S.edge(v,n); // It exists !
   }
 }

Definition at line 2053 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02054     {
02055       if(v.isNull())
02056         return true;
02057       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02058       if(it_found == neighborhood.end())
02059         return true;
02060       return it_found->second.in_edges.empty();
02061     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::ineighbor_iterator_range graph::VVGraph< GRAPH_TEMPLATE >::iNeighbors ( const vertex_t v  )  const [inline]

Return the range of incoming neighbors of v.

Iterating over iNeighbors will go through all the vertexes having an edge toward v.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& n, S)
 {
   forall(const vertex& v, S.iNeighbors(v))
   {
     // n is a neighbor of v
   }
 }

Definition at line 2636 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), util::make_range(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02637     {
02638       ineighbor_iterator_range result;
02639       if(v.isNull())
02640         return result;
02641       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02642       if(it_found == neighborhood.end())
02643         return result;
02644       const in_edges_t &lst = it_found->second.in_edges;
02645       result = util::make_range(ineighbor_iterator(lst.begin()),
02646                                 ineighbor_iterator(lst.end()));
02647       return result;
02648     }

template<GRAPH_TEMPLATE >
template<typename Iterator >
void graph::VVGraph< GRAPH_TEMPLATE >::insert ( Iterator  first,
Iterator  last 
) [inline]

Insert all the vertexes from first to last-1 in the graph.

Definition at line 1965 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::insert().

01966     {
01967       for(Iterator it = first ; it != last ; ++it)
01968       {
01969         insert(*it);
01970       }
01971     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::iterator graph::VVGraph< GRAPH_TEMPLATE >::insert ( iterator  pos,
const vertex_t v 
) [inline]

Insert a new vertex in the graph.

The iterator is ignored ...

Definition at line 1958 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::insert().

01959     {
01960       return this->insert(v);
01961     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::iterator graph::VVGraph< GRAPH_TEMPLATE >::insert ( const vertex_t v  )  [inline]

Insert a new vertex in the graph.

Returns:
An iterator on the inserted vertex.

Example:

 vvgraph S;
 vertex v; // Create a vertex
 S.insert(v); // Insert it in the graph

Definition at line 1931 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateVertexCache().

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::insert(), algorithms::split(), and graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph().

01932     {
01933       typename lookup_t::iterator it_found;
01934       bool inserted;
01935       util::tie(it_found, inserted) = lookup.insert(std::make_pair(v, typename neighborhood_t::iterator()));
01936       if(inserted)
01937       {
01938         neighborhood.push_front(std::make_pair(v,single_neighborhood_t()));
01939         typename neighborhood_t::iterator it = neighborhood.begin();
01940         it_found->second = it;
01941         updateVertexCache(it->first, it);
01942         return it;
01943       }
01944       return it_found->second;
01945     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::edge_t graph::VVGraph< GRAPH_TEMPLATE >::insertEdge ( const vertex_t src,
const vertex_t tgt 
) [inline]

Insert a new edge in the graph, without ordering.

If new_neighbor is already in the neighborhood of v, the insertion fails.

Returns:
The just created edge if everything succeed, or a null edge.

Example:

 vvgraph S;
 vertex v1, v2;
 S.insert(v1);
 S.insert(v2);
 S.insertEdge(v1, v2); // Insert the edge between v1 and v2
 S.insertEdge(v2, v1); // Insert the edge between v2 and v1

Definition at line 2550 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache().

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::connectFromJunctions(), and algorithms::split().

02552     {
02553       if(v.isNull() || new_neighbor.isNull() || v == new_neighbor )
02554         return edge_t();
02555       typename neighborhood_t::iterator it_found = this->findVertex(v);
02556       if(it_found == neighborhood.end())
02557         return edge_t();
02558       ineighbor_iterator it_in;
02559       bool inserted;
02560       util::tie(it_in, inserted) = insertInEdge(v, new_neighbor);
02561       if(!inserted)
02562         return edge_t();
02563       edge_list_t &lst = it_found->second.edges;
02564       lst.push_front(neighbor_t(new_neighbor, EdgeContent(), it_found->second, graph_id));
02565       typename edge_list_t::iterator it = lst.begin();
02566       updateEdgeCache(v, it, *it_in);
02567       return edge_t(v.id(), new_neighbor.id(), &*it);
02568     }

template<GRAPH_TEMPLATE >
template<typename VertexContainer >
std::vector< typename VVGraph< GRAPH_ARGS >::edge_t > graph::VVGraph< GRAPH_TEMPLATE >::insertEdges ( const vertex_t src,
const VertexContainer &  targets 
) [inline]

Insert a set of edges, keeping the relative order of the list of edges.

Definition at line 2525 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache().

02526     {
02527       std::vector<edge_t> result;
02528       typename neighborhood_t::iterator it_found = this->findVertex(v);
02529       if(it_found == neighborhood.end()) return result;
02530       ineighbor_iterator it_in;
02531       bool inserted;
02532       edge_list_t& lst = it_found->second.edges;
02533       typename edge_list_t::iterator lst_it = lst.begin();
02534       result.reserve(new_neighbors.size());
02535       for(typename VertexContainer::const_iterator it = new_neighbors.begin() ;
02536           it != new_neighbors.end() ; ++it) {
02537         const vertex_t& new_neighbor = *it;
02538         if(new_neighbor.isNull() or new_neighbor == v) return result;
02539         util::tie(it_in, inserted) = this->insertInEdge(v, new_neighbor);
02540         if(!inserted) return result;
02541         typename edge_list_t::iterator new_lst_it = lst.insert(lst_it, neighbor_t(new_neighbor, EdgeContent(), it_found->second, graph_id));
02542         updateEdgeCache(v, new_lst_it, *it_in);
02543         result.push_back(edge_t(v.id(), new_neighbor.id(), &*new_lst_it));
02544       }
02545       return result;
02546     }

template<GRAPH_TEMPLATE >
std::pair< typename VVGraph< GRAPH_ARGS >::ineighbor_iterator, bool > graph::VVGraph< GRAPH_TEMPLATE >::insertInEdge ( const vertex_t v,
const vertex_t new_neighbor 
) [inline, protected]

Insert v in the in_edges of new_neighbor and return true if the insertion was actually done, or false if v was already there.

Definition at line 2260 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::lookup.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::replace(), graph::VVGraph< VertexContent, EdgeContent, compact >::spliceAfter(), graph::VVGraph< VertexContent, EdgeContent, compact >::spliceBefore(), and graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph().

02261     {
02262       typename lookup_t::iterator found = lookup.find(new_neighbor);
02263       if(found == lookup.end())
02264         return std::make_pair(ineighbor_iterator(), false);
02265       //typename neighborhood_t::iterator found = neighborhood.find(new_neighbor);
02266       //if(found == neighborhood.end())
02267       //return std::make_pair(ineighbor_iterator(), false);
02268       return found->second->second.in_edges.insert(v);
02269     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::size_type graph::VVGraph< GRAPH_TEMPLATE >::iValence ( const vertex_t v  )  const [inline]

Returns the number of incoming neighbors of v.

The incoming neighbors are the set of vertexes with on edge ending on v.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& n, S)
 {
    size_t nb_ineighbors = S.iValence(n);
    // nb_ineighbors is the number of vertices source of an edge toward n
 }

Definition at line 2042 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02043     {
02044       if(v.isNull())
02045         return 0;
02046       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02047       if(it_found == neighborhood.end())
02048         return 0;
02049       return it_found->second.in_edges.size();
02050     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::const_circ_neighbor_iterator_range graph::VVGraph< GRAPH_TEMPLATE >::neighbors ( const vertex_t v,
const vertex_t n 
) const [inline]

Return the range of neighbors of v, starting at n.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& m, S.neighbors(v,n))
 {
   // m is a neighbor of v
   // on the first loop, m == n
 }

Definition at line 2604 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, util::make_range(), and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood.

02605     {
02606       const_circ_neighbor_iterator_range result;
02607       if(v.isNull())
02608         return result;
02609       const_neighbor_found_t found = this->findInVertex(v, n);
02610       if(!found)
02611         return result;
02612       const edge_list_t &lst = found.neighborhood->edges;
02613       result = util::make_range(const_circ_neighbor_iterator(lst.begin(), lst.end(), found.it),
02614                                 const_circ_neighbor_iterator(lst.begin(), lst.end()));
02615       return result;
02616     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::circ_neighbor_iterator_range graph::VVGraph< GRAPH_TEMPLATE >::neighbors ( const vertex_t v,
const vertex_t n 
) [inline]

Return the range of neighbors of v, starting at n.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& m, S.neighbors(v,n))
 {
   // m is a neighbor of v
   // on the first loop, m == n
 }

Definition at line 2620 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, util::make_range(), and graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood.

02621     {
02622       circ_neighbor_iterator_range result;
02623       if(v.isNull())
02624         return result;
02625       neighbor_found_t found = this->findInVertex(v, n);
02626       if(!found)
02627         return result;
02628       edge_list_t &lst = found.neighborhood->edges;
02629       result = util::make_range(circ_neighbor_iterator(lst.begin(), lst.end(), found.it),
02630                                 circ_neighbor_iterator(lst.begin(), lst.end()));
02631       return result;
02632     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::neighbor_iterator_range graph::VVGraph< GRAPH_TEMPLATE >::neighbors ( const vertex_t v  )  [inline]

Return the range of neighbors of v.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     // n is a neighbor of v
   }
 }

Definition at line 2588 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), util::make_range(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02589     {
02590       neighbor_iterator_range result;
02591       if(v.isNull())
02592         return result;
02593       typename neighborhood_t::iterator it_found = this->findVertex(v);
02594       if(it_found == neighborhood.end())
02595         return result;
02596       edge_list_t &lst = it_found->second.edges;
02597       result = util::make_range(neighbor_iterator(lst.begin()),
02598                                 neighbor_iterator(lst.end()));
02599       return result;
02600     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::const_neighbor_iterator_range graph::VVGraph< GRAPH_TEMPLATE >::neighbors ( const vertex_t v  )  const [inline]

Return the constant range of neighbors of v.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     // n is a neighbor of v
   }
 }

Definition at line 2572 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), util::make_range(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by solver::Solver< nb_vars, identifier >::FindPartials(), vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::mergeCells(), and solver::Solver< nb_vars, identifier >::solveAdaptiveCrankNicholson().

02573     {
02574       const_neighbor_iterator_range result;
02575       if(v.isNull())
02576         return result;
02577       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02578       if(it_found == neighborhood.end())
02579         return result;
02580       const edge_list_t &lst = it_found->second.edges;
02581       result = util::make_range(const_neighbor_iterator(lst.begin()),
02582                                 const_neighbor_iterator(lst.end()));
02583       return result;
02584     }

template<GRAPH_TEMPLATE >
const VVGraph< GRAPH_ARGS >::vertex_t & graph::VVGraph< GRAPH_TEMPLATE >::nextTo ( const vertex_t v,
const vertex_t neighbor,
unsigned int  n = 1 
) const [inline]

Returns the nth vertex after neighbor in the neighborhood of v.

Returns:
The vertex found or a null vertex if there is any problem.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     const vertex& m, S.nextTo(v);
     // m is the vertex after n in v
   }
 }

Definition at line 2332 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood, and graph::Vertex< VertexContent >::null.

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::mergeCells(), and algorithms::split().

02335     {
02336       const_neighbor_found_t found = this->findInVertex(v, ref);
02337       if(!found)
02338         return vertex_t::null;//vertex_t(0);
02339       typename edge_list_t::const_iterator it = found.it;
02340       const edge_list_t& lst = found.neighborhood->edges;
02341       for(unsigned int i = 0 ; i < n ; ++i)
02342       {
02343         ++it;
02344         if(it == lst.end())
02345           it = lst.begin();
02346       }
02347       return it->target;
02348     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS > & graph::VVGraph< GRAPH_TEMPLATE >::operator= ( const VVGraph< VertexContent, EdgeContent, compact > &  other  )  [inline]

Copy the graph into another graph.

Definition at line 2766 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateVertexCache().

02767     {
02768       //    for(const_iterator it = other.begin() ; it != other.end() ; ++it)
02769       //    {
02770       //      this->insert(*it);
02771       //    }
02772 
02773       //    for(const_iterator it = other.begin() ; it != other.end() ; ++it)
02774       //    {
02775       //      vertex_t prev(0);
02776       //      const vertex_t& v = *it;
02777       //      const_neighbor_iterator_range ns = other.neighbors(v);
02778       //      for(const_neighbor_iterator itn = ns.first ; itn != ns.second ; ++itn)
02779       //      {
02780       //        const vertex_t& n = *itn;
02781       //        if(prev)
02782       //          this->spliceAfter(v, prev, n);
02783       //        else
02784       //          this->insertEdge(v,n);
02785       //        prev = n;
02786       //      }
02787       //    }
02788 
02789       // Copy the structure
02790       neighborhood = other.neighborhood;
02791       lookup.clear();
02792       typename neighborhood_t::iterator it;
02793       for(it = neighborhood.begin() ; it != neighborhood.end() ; ++it)
02794       {
02795         lookup[it->first] = it;
02796       }
02797       // And reconstruct the cache
02798       typename edge_list_t::iterator it_e;
02799       for(it = neighborhood.begin() ; it != neighborhood.end() ; ++it)
02800       {
02801         const vertex_t& src = it->first;
02802         updateVertexCache(src, it);
02803 #ifndef VVGRAPH_NO_EDGE_CACHE
02804         if(not compact)
02805         {
02806           edge_list_t& lst = it->second.edges;
02807           for(it_e = lst.begin() ; it_e != lst.end() ; ++it_e)
02808           {
02809             // Find the incoming vertex corresponding the this edge
02810             typename lookup_t::iterator it_found = lookup.find(it_e->target);
02811             const vertex_t& iv = *(it_found->second->second.in_edges.find(src));
02812             //const vertex_t& iv = *(neighborhood[it_e->target].in_edges.find(src));
02813             updateEdgeCache(src, it_e, iv);
02814             it_e->set(&it->second, graph_id);
02815           }
02816         }
02817 #endif
02818       }
02819       return *this;
02820     }

template<GRAPH_TEMPLATE >
bool graph::VVGraph< GRAPH_TEMPLATE >::operator== ( const VVGraph< VertexContent, EdgeContent, compact > &  other  )  const [inline]

Test equality for the graphs.

Two graphs are equal if they shared the sames vertices and their neighborhood are equivalent.

Note:
Current implementation do not consider invariance of neighborhood by rotation.

Definition at line 2719 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

02720     {
02721       if(neighborhood.size() != other.neighborhood.size())
02722         return false;
02723       for(typename neighborhood_t::const_iterator it = neighborhood.begin() ;
02724           it != neighborhood.end() ; ++it)
02725       {
02726         const vertex_t& v1 = it->first;
02727         typename lookup_t::const_iterator it_found = other.lookup.find(v1);
02728         if(it_found == other.lookup.end())
02729           return false;
02730         if(it->second.edges.empty())
02731         {
02732           if(!it_found->second->second.edges.empty())
02733             return false;
02734         }
02735         else
02736         {
02737           const edge_list_t& lst = it->second.edges;
02738           const edge_list_t& olst = it_found->second->second.edges;
02739           if(lst.size() != olst.size()) return false;
02740           const vertex_t& v2 = lst.begin()->target;
02741           bool found = false;
02742           for(typename edge_list_t::const_iterator it_olst = olst.begin() ;
02743               it_olst != olst.end() ; ++it_olst)
02744           {
02745             if(it_olst->target == v2)
02746             {
02747               found = true;
02748               for(typename edge_list_t::const_iterator it_lst = lst.begin() ;
02749                   it_lst != lst.end() ; ++it_lst)
02750               {
02751                 if(it_lst->target != it_olst->target) return false;
02752                 ++it_olst;
02753                 if(it_olst == olst.end()) it_olst = olst.begin();
02754               }
02755               break;
02756             }
02757           }
02758           if(!found) return false;
02759         }
02760       }
02761       return true;
02762     }

template<GRAPH_TEMPLATE >
const VVGraph< GRAPH_ARGS >::vertex_t & graph::VVGraph< GRAPH_TEMPLATE >::operator[] ( size_type  idx  )  const [inline]

Return the element of index idx.

Note:
This is a convenience function whose complexity if O(idx)
Returns:
The element idx position after the first one (using iterators)

Example:

 vvgraph S;
 // Fill in S
 size_t i = 0, selected = 0;
 forall(const vertex& v, S)
 {
   if(condition(v))
   {
     selected = i;
     break;
   }
   ++i;
 }
 // ...
 const vertex& v = S[selected]; // Work with the vertex previously selected

This construct is useful is case you need to refer to your vertices by 32bits numbers. It is true if you use selection with OpenGL for example.

Definition at line 1984 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

01985     {
01986       typename neighborhood_t::const_iterator it = neighborhood.begin();
01987       std::advance(it, idx);
01988       return it->first;
01989     }

template<GRAPH_TEMPLATE >
const VVGraph< GRAPH_ARGS >::vertex_t & graph::VVGraph< GRAPH_TEMPLATE >::prevTo ( const vertex_t v,
const vertex_t ref,
unsigned int  n = 1 
) const [inline]

Returns the nth vertex before ref in the neighborhood of v.

If ref is not in the neighborhood of v, return a null vertex.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     const vertex& m, S.prevTo(v);
     // m is the vertex before n in v
   }
 }

Definition at line 2352 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood, and graph::Vertex< VertexContent >::null.

02355     {
02356       const_neighbor_found_t found = this->findInVertex(v, ref);
02357       if(!found)
02358         return vertex_t::null;//vertex_t(0);
02359       typename edge_list_t::const_iterator it = found.it;
02360       const edge_list_t& lst = found.neighborhood->edges;
02361       for(unsigned int i = 0 ; i < n ; ++i)
02362       {
02363         if(it == lst.begin())
02364           it = lst.end();
02365         --it;
02366       }
02367       return it->target;
02368     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
const vertex_t& graph::VVGraph< VertexContent, EdgeContent, compact >::reference ( vertex_t  v  )  const [inline]

Get a reference on the vertex in the graph.

If the vertex do not exist in the graph, the function returns a null vertex.

Note:
This function is useful if you obtained the vertex not from this graph but will use it intensively.

Example:

 vvgraph S1, S2;
 // Initialize S1 and S2 with the same vertices but different neighborhood
 forall(const vertex& v1, S1)
 {
   const vertex& v2 = S2.reference(v1);
   // Use v2 in S2 and v1 in v1 for speed optimizatioN
 }

Definition at line 780 of file vvgraph.h.

00781         {
00782           typename neighborhood_t::const_iterator found = this->findVertex(v);
00783           if(found != neighborhood.end())
00784             return found->first;
00785           return vertex_t::null;//vertex_t(0);
00786         }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::edge_t graph::VVGraph< GRAPH_TEMPLATE >::replace ( const vertex_t v,
const vertex_t neighbor,
const vertex_t new_neighbor 
) [inline]

Replace a vertex by another in a neighborhood.

Parameters:
[in] v Vertex whose neighborhood is changed.
[in] neighbor Vertex to replace
[in] new_neighbor Vertex replacing neighbor

If new_neighbor is already in the neighborhood of v, then the operation fails and nothing is changed.

Returns:
The edge between v and new_neighbor or a null edge if anything goes wrong.

Example:

 vvgraph S;
 // Initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     if(condition)
     {
       vertex n1;
       S.replace(v,n,n1); // Now n1 is where n was in v
       break; // The iteration must not continue after the neighborhood has been altered
     }
   }
 }

Definition at line 2307 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::id(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache().

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::connectFromJunctions(), vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::deleteJunction(), vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::mergeCells(), and algorithms::split().

02310     {
02311       if(new_neighbor.isNull() or (v == new_neighbor) or (neighbor == new_neighbor))
02312         return edge_t();
02313       neighbor_found_t found = this->findInVertex(v, neighbor);
02314       if(!found)
02315         return edge_t();
02316       typename neighborhood_t::iterator n_found = this->findVertex(neighbor);
02317       ineighbor_iterator it_in;
02318       bool inserted;
02319       util::tie(it_in, inserted) = insertInEdge(v, new_neighbor);
02320       if(!inserted)
02321         return edge_t();
02322       n_found->second.in_edges.erase(v);
02323       found.it->target = new_neighbor;
02324       found.it->clear_edge();
02325       updateEdgeCache(v, found.it, *it_in);
02326       if(n_found->second.flagged and *n_found->second.flagged == neighbor) n_found->second.flagged = 0;
02327       return edge_t(v.id(), new_neighbor.id(), &*found.it);
02328     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
size_type graph::VVGraph< VertexContent, EdgeContent, compact >::size (  )  const [inline]
template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
const vertex_t& graph::VVGraph< VertexContent, EdgeContent, compact >::source ( const edge_t edge  )  const [inline]

Return the source vertex of the edge.

Example:

 void fct(edge e, const vvgraph& S)
 {
   const vertex& src = S.source(e);
   const vertex& tgt = S.target(e);
   // Work with the vertices
 }

Definition at line 1201 of file vvgraph.h.

01202         {
01203           typename neighborhood_t::const_iterator found = this->findVertex(vertex_t(edge.source()));
01204           if(found != neighborhood.end())
01205             return found->first;
01206           return vertex_t::null;//vertex_t(0);
01207         }

template<GRAPH_TEMPLATE >
template<typename VertexContainer >
std::vector< typename VVGraph< GRAPH_ARGS >::edge_t > graph::VVGraph< GRAPH_TEMPLATE >::spliceAfter ( const vertex_t v,
const vertex_t neighbor,
const VertexContainer &  new_neighbor 
) [inline]

Splice a list of vertices after a neighbor.

The order of the vertices is kept.

Definition at line 2452 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache().

02455     {
02456       std::vector<edge_t> result;
02457       neighbor_found_t found = this->findInVertex(v, neighbor);
02458       if(!found) return result;
02459       ineighbor_iterator it_in;
02460       bool inserted;
02461       ++found.it;
02462       result.reserve(new_neighbors.size());
02463       for(typename VertexContainer::const_iterator it = new_neighbors.begin() ;
02464           it != new_neighbors.end() ; ++it) {
02465         const vertex_t& new_neighbor = *it;
02466         util::tie(it_in, inserted) = insertInEdge(v, new_neighbor);
02467         if(!inserted) return result;
02468         typename edge_list_t::iterator new_edge_it = found.neighborhood->edges.insert(found.it, neighbor_t(new_neighbor, EdgeContent(), *found.neighborhood, graph_id));
02469         updateEdgeCache(v, new_edge_it, *it_in);
02470         result.push_back(edge_t(v.id(), new_neighbor.id(), &*new_edge_it));
02471       }
02472       return result;
02473     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::edge_t graph::VVGraph< GRAPH_TEMPLATE >::spliceAfter ( const vertex_t v,
const vertex_t neighbor,
const vertex_t new_neighbor 
) [inline]

Insert neighbor in the neighborhood of v after reference.

If new_neighbor is already in the neighborhood of v, the insertion fails.

Returns:
The just created edge if everything succeed, or a null edge.

Example:

 vvgraph S;
 // Initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     if(condition)
     {
       vertex n1;
       S.spliceAfter(v,n,n1); // Now n1 is after n in v
       break; // The iteration must not continue after the neighborhood has been altered
     }
   }
 }

Definition at line 2429 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache().

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::connectFromJunctions(), vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::mergeCells(), and algorithms::split().

02432     {
02433       if(new_neighbor.isNull() || v == new_neighbor)
02434         return edge_t();
02435       neighbor_found_t found = this->findInVertex(v, neighbor);
02436       if(!found)
02437         return edge_t();
02438       ineighbor_iterator it_in;
02439       bool inserted;
02440       util::tie(it_in, inserted) = insertInEdge(v, new_neighbor);
02441       if(!inserted)
02442         return edge_t();
02443       ++found.it;
02444       typename edge_list_t::iterator new_edge_it = found.neighborhood->edges.insert(found.it, neighbor_t(new_neighbor, EdgeContent(), *found.neighborhood, graph_id));
02445       updateEdgeCache(v, new_edge_it, *it_in);
02446       return edge_t(v.id(), new_neighbor.id(), &*new_edge_it);
02447     }

template<GRAPH_TEMPLATE >
template<typename VertexContainer >
std::vector< typename VVGraph< GRAPH_ARGS >::edge_t > graph::VVGraph< GRAPH_TEMPLATE >::spliceBefore ( const vertex_t v,
const vertex_t neighbor,
const VertexContainer &  new_neighbor 
) [inline]

Splice a list of vertices before a neighbor.

The order of the vertices is kept.

Definition at line 2499 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache().

02502     {
02503       std::vector<edge_t> result;
02504       neighbor_found_t found = this->findInVertex(v, neighbor);
02505       if(!found) return result;
02506       ineighbor_iterator it_in;
02507       bool inserted;
02508       result.reserve(new_neighbors.size());
02509       for(typename VertexContainer::const_iterator it = new_neighbors.begin() ;
02510           it != new_neighbors.end() ; ++it) {
02511         const vertex_t& new_neighbor = *it;
02512         util::tie(it_in, inserted) = insertInEdge(v, new_neighbor);
02513         if(!inserted) return result;
02514         typename edge_list_t::iterator new_edge_it = found.neighborhood->edges.insert(found.it, neighbor_t(new_neighbor, EdgeContent(), *found.neighborhood, graph_id));
02515         updateEdgeCache(v, new_edge_it, *it_in);
02516         result.push_back(edge_t(v.id(), new_neighbor.id(), &*new_edge_it));
02517       }
02518       return result;
02519     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::edge_t graph::VVGraph< GRAPH_TEMPLATE >::spliceBefore ( const vertex_t v,
const vertex_t neighbor,
const vertex_t new_neighbor 
) [inline]

Insert neighbor in the neighborhood of v before reference.

If new_neighbor is already in the neighborhood of v, the insertion fails.

Returns:
The just created edge if everything succeed, or a null edge.

Example:

 vvgraph S;
 // Initialize S
 forall(const vertex& v, S)
 {
   forall(const vertex& n, S.neighbors(v))
   {
     if(condition)
     {
       vertex n1;
       S.spliceBefore(v,n,n1); // Now n1 is before n in v
       break; // The iteration must not continue after the neighborhood has been altered
     }
   }
 }

Definition at line 2477 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::Vertex< VertexContent >::id(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::Vertex< VertexContent >::isNull(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::neighborhood, util::tie(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache().

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::connectFromJunctions(), vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::mergeCells(), and algorithms::split().

02480     {
02481       if(new_neighbor.isNull() || v == new_neighbor)
02482         return edge_t();
02483       neighbor_found_t found = this->findInVertex(v, neighbor);
02484       if(!found)
02485         return edge_t();
02486       ineighbor_iterator it_in;
02487       bool inserted;
02488       util::tie(it_in, inserted) = insertInEdge(v, new_neighbor);
02489       if(!inserted)
02490         return edge_t();
02491       typename edge_list_t::iterator new_edge_it = found.neighborhood->edges.insert(found.it, neighbor_t(new_neighbor, EdgeContent(), *found.neighborhood, graph_id));
02492       updateEdgeCache(v, new_edge_it, *it_in);
02493       return edge_t(v.id(), new_neighbor.id(), &*new_edge_it);
02494     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
void graph::VVGraph< VertexContent, EdgeContent, compact >::store_vertices ( std::vector< vertex_t > &  vertices,
bool  cached = true 
) const [inline]

Store the vertices in a STL container.

By default, the cache will be setup for quick vertex access.

Example:

 vvgraph S;
 // Initialize S
 std::vector<vertex> vertices;
 S.store_vertices(vertices);
 forall(const vertex& v, vertices)
 {
   // The cache information is used to speed up lookup
   if(condition)
   {
     S.erase(v); // Valid, but do not use v in S after that
   }
 }

Definition at line 1584 of file vvgraph.h.

01585         {
01586           vertices.resize(this->size(), vertex_t::null);
01587           size_t k = 0;
01588           for(typename neighborhood_t::const_iterator it = neighborhood.begin() ;
01589               it != neighborhood.end() ; ++it)
01590           {
01591             const vertex_t& v = it->first;
01592             vertices[k] = v;
01593 #ifndef VVGRAPH_NO_CACHE
01594             if(cached)
01595             {
01596               vertices[k].cache = v.cache;
01597               vertices[k].cache_source = v.cache_source;
01598             }
01599 #endif
01600             ++k;
01601           }
01602         }

template<GRAPH_TEMPLATE >
template<typename VertexContainer >
VVGraph< GRAPH_ARGS > graph::VVGraph< GRAPH_TEMPLATE >::subgraph ( const VertexContainer &  vertexes  )  const [inline]

Extract the subgraph containing the vertexes.

The subgraph is the set of vertexes and the edges whose source and target are in the extracted vertexes.

Example:

 vvgraph S;
 // Initialize S
 std::vector<vertex> to_keep;
 // Fill in to_keep with a subset of the vertices of S
 vvgraph S1 = S.subgraph(to_keep);

Definition at line 2652 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::contains(), graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::VVGraph< VertexContent, EdgeContent, compact >::insert(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertInEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::search_result_t< Neighborhood, Iterator >::it, graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood, graph::VVGraph< VertexContent, EdgeContent, compact >::updateEdgeCache(), and graph::VVGraph< VertexContent, EdgeContent, compact >::updateVertexCache().

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::saveSubgraphs().

02653     {
02654       typename VertexContainer::const_iterator it;
02655       VVGraph result;
02656       // First, insert the vertexes in the result graph
02657       for(it = verts.begin() ; it != verts.end() ; ++it)
02658       {
02659         result.insert(*it);
02660       }
02661       typename neighborhood_t::const_iterator it_orign;
02662       typename neighborhood_t::iterator it_n;
02663       typename edge_list_t::const_reverse_iterator it_sn;
02664       // Then, creates the in and out edges
02665       for(it_n = result.neighborhood.begin() ; it_n != result.neighborhood.end() ; ++it_n)
02666       {
02667         const vertex_t& v = it_n->first;
02668         result.updateVertexCache(v, it_n);
02669         // For each vertex, find out which edges to add
02670         it_orign = this->findVertex(v);
02671         const edge_list_t& orig_lst = it_orign->second.edges;
02672         edge_list_t& lst = it_n->second.edges;
02673         // Going backward because it is easier to retrieve the iterator ...
02674         for( it_sn = orig_lst.rbegin() ; it_sn != orig_lst.rend() ; ++it_sn )
02675         {
02676           // For each existing edge from the vertex, keep only the ones whose 
02677           // target are on the subgraph
02678           if(result.contains(it_sn->target))
02679           {
02680             // Insert the incoming edge
02681             ineighbor_iterator it_in = result.insertInEdge(v, it_sn->target).first;
02682             // Insert the outgoing edge
02683             lst.push_front(neighbor_t(it_sn->target, *it_sn, it_n->second, result.graph_id));
02684             // Update the cache
02685             result.updateEdgeCache(v, lst.begin(), *it_in);
02686           }
02687         }
02688         // At last, update the flag, if any
02689         if(it_orign->second.flagged and result.contains(*it_orign->second.flagged))
02690         {
02691           const_neighbor_found_t found = this->findInVertex(v, *it_orign->second.flagged);
02692           it_n->second.flagged = &(found.it->target);
02693         }
02694       }
02695       return result;
02696     }

template<GRAPH_TEMPLATE >
void graph::VVGraph< GRAPH_TEMPLATE >::swap ( VVGraph< VertexContent, EdgeContent, compact > &  other  )  [inline]

Swap the content of two graphs.

Definition at line 2823 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id, graph::VVGraph< VertexContent, EdgeContent, compact >::lookup, and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by std::swap().

02824     {
02825       neighborhood.swap(other.neighborhood);
02826       lookup.swap(lookup);
02827       std::swap(graph_id, other.graph_id);
02828     }

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
const vertex_t& graph::VVGraph< VertexContent, EdgeContent, compact >::target ( const edge_t edge  )  const [inline]

Return the target vertex of the edge.

Example:

 void fct(edge e, const vvgraph& S)
 {
   const vertex& src = S.source(e);
   const vertex& tgt = S.target(e);
   // Work with the vertices
 }

Definition at line 1230 of file vvgraph.h.

01231         {
01232           typename neighborhood_t::const_iterator found = this->findVertex(vertex_t(edge.target()));
01233           if(found != neighborhood.end())
01234             return found->first;
01235           return vertex_t::null;//vertex_t(0);
01236         }

template<GRAPH_TEMPLATE >
void graph::VVGraph< GRAPH_TEMPLATE >::undoInEdge ( const vertex_t new_neighbor,
ineighbor_iterator it 
) [inline, protected]

Undo the insertion of an in edge as a roll-back mechanism if the whole edge insertion fails.

Definition at line 2272 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::lookup.

02274     {
02275       typename lookup_t::iterator found = lookup.find(new_neighbor);
02276       //typename neighborhood_t::iterator found = neighborhood.find(new_neighbor);
02277       //if(found == neighborhood.end())
02278       //return;
02279       if(found == lookup.end())
02280         return;
02281       found->second->second.in_edges.erase(it);
02282     }

template<GRAPH_TEMPLATE >
void graph::VVGraph< GRAPH_TEMPLATE >::updateEdgeCache ( const vertex_t v,
typename edge_list_t::iterator  new_edge_it,
const vertex_t in_edge 
) [inline, protected]

Update the edge cache information of vertex v in its neighborhood and the in_edge too.

Definition at line 2285 of file vvgraph.h.

References graph::Vertex< VertexContent >::cache, graph::Vertex< VertexContent >::cache_source, graph::Vertex< VertexContent >::id(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighbor_t::target.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::operator=(), graph::VVGraph< VertexContent, EdgeContent, compact >::replace(), graph::VVGraph< VertexContent, EdgeContent, compact >::spliceAfter(), graph::VVGraph< VertexContent, EdgeContent, compact >::spliceBefore(), and graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph().

02288     {
02289 #ifndef VVGRAPH_NO_EDGE_CACHE
02290       if(not compact)
02291       {
02292         // Caching in the neighbor
02293         neighbor_t& neighbor = *new_edge_it;
02294         neighbor.setIt(new_edge_it);
02295         neighbor.target.cache_source = v.id();
02296         neighbor.target.cache = reinterpret_cast<void*>(&neighbor);
02297 
02298         // Caching in the incoming edge source
02299         in_edge.cache_source = v.id();
02300         in_edge.cache = reinterpret_cast<void*>(&neighbor);
02301       }
02302 #endif // VVGRAPH_NO_EDGE_CACHE
02303     }

template<GRAPH_TEMPLATE >
void graph::VVGraph< GRAPH_TEMPLATE >::updateVertexCache ( const vertex_t v,
typename neighborhood_t::iterator  it 
) [inline, protected]

Update the vertex cache for vertex v.

Definition at line 1948 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::insert(), graph::VVGraph< VertexContent, EdgeContent, compact >::operator=(), and graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph().

01950     {
01951 #ifndef VVGRAPH_NO_VERTEX_CACHE
01952       it->second.update(graph_id, v, it);
01953 #endif
01954     }

template<GRAPH_TEMPLATE >
VVGraph< GRAPH_ARGS >::size_type graph::VVGraph< GRAPH_TEMPLATE >::valence ( const vertex_t v  )  const [inline]

Returns the number of neighbors of v.

If v is not in the graph, the behavior is undefined.

Example:

 vvgraph S;
 // initialize S
 forall(const vertex& v, S)
 {
   size_t nb_neighbors = S.valence(v); // Number of neighbors of v in S
   // ...
 }

Definition at line 2006 of file vvgraph.h.

References graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::Vertex< VertexContent >::isNull(), and graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood.

Referenced by vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::border(), and vvcomplex::VVComplex< MANDATORY_COMPLEX_TEMPLATE_ARGS, RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >)>::deleteJunction().

02007     {
02008       if(v.isNull())
02009         return 0;
02010       typename neighborhood_t::const_iterator it_found = this->findVertex(v);
02011       if(it_found == neighborhood.end())
02012         return 0;
02013       return it_found->second.edges.size();
02014     }


Member Data Documentation

template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
intptr_t graph::VVGraph< VertexContent, EdgeContent, compact >::graph_id [protected]
template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
lookup_t graph::VVGraph< VertexContent, EdgeContent, compact >::lookup [protected]
template<typename VertexContent, typename EdgeContent = _EmptyEdgeContent, bool compact = false>
neighborhood_t graph::VVGraph< VertexContent, EdgeContent, compact >::neighborhood [protected]

Main data structure containing everything.

Definition at line 1797 of file vvgraph.h.

Referenced by graph::VVGraph< VertexContent, EdgeContent, compact >::any(), graph::VVGraph< VertexContent, EdgeContent, compact >::anyIn(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::begin(), graph::VVGraph< VertexContent, EdgeContent, compact >::clear(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::clear(), graph::VVGraph< VertexContent, EdgeContent, compact >::contains(), graph::VVGraph< VertexContent, EdgeContent, compact >::empty(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::empty(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::end(), graph::VVGraph< VertexContent, EdgeContent, compact >::erase(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseAllEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::eraseEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::findInVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::findVertex(), graph::VVGraph< VertexContent, EdgeContent, compact >::flagged(), graph::VVGraph< VertexContent, EdgeContent, compact >::iAnyIn(), graph::VVGraph< VertexContent, EdgeContent, compact >::iEmpty(), graph::VVGraph< VertexContent, EdgeContent, compact >::iNeighbors(), graph::VVGraph< VertexContent, EdgeContent, compact >::insert(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdge(), graph::VVGraph< VertexContent, EdgeContent, compact >::insertEdges(), graph::VVGraph< VertexContent, EdgeContent, compact >::iValence(), graph::VVGraph< VertexContent, EdgeContent, compact >::neighbors(), graph::VVGraph< VertexContent, EdgeContent, compact >::operator=(), graph::VVGraph< VertexContent, EdgeContent, compact >::operator==(), graph::VVGraph< VertexContent, EdgeContent, compact >::operator[](), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::reference(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::size(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::source(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::store_vertices(), graph::VVGraph< VertexContent, EdgeContent, compact >::subgraph(), graph::VVGraph< VertexContent, EdgeContent, compact >::swap(), graph::VVGraph< RESOLVE_LEAF_CLASS(LeafClass, Tissue< ALL_COMPLEX_TEMPLATE_ARGS >), graph::_EmptyEdgeContent, false >::target(), and graph::VVGraph< VertexContent, EdgeContent, compact >::valence().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:38:12 2013 for VVE by  doxygen 1.6.3