Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/include/Digraph.h
Go to the documentation of this file.
00001 
00009 #ifndef DIGRAPH_H
00010 #define DIGRAPH_H
00011 
00012 #include "Graph.h"
00013 
00014 namespace grafalgo {
00015 
00025 class Digraph : public Graph {
00026 public:         Digraph(int=1,int=1);
00027                 ~Digraph();
00028         
00029         void    resize(int,int);
00030         void    resize(int numv) { resize(numv,numv); }
00031         void    expand(int,int);
00032         void    expand(int numv) { resize(numv,max(numv,m())); }
00033 
00034         vertex  tail(edge) const;       
00035         vertex  head(edge) const;      
00036 
00037         virtual edge firstAt(vertex) const;     
00038         virtual edge nextAt(vertex,edge) const;
00039         edge    firstIn(vertex) const;  
00040         edge    nextIn(vertex,edge) const; 
00041         edge    firstOut(vertex) const; 
00042         edge    nextOut(vertex,edge) const;
00043 
00044         edge    joinWith(vertex,vertex,edge);
00045         bool    remove(edge);
00046 
00047         void    rgraph(int,int);    
00048         void    rdag(int,int);     
00049 
00050         // create a string representation
00051         //virtual string& edge2string(edge,string&) const;
00052         virtual string& toDotString(string&) const;
00053 
00054         // input
00055 
00056 
00057 protected:
00058         void makeSpace(int,int);
00059         void freeSpace();
00060         string& adjList2string(vertex, string&) const;
00061         bool    readAdjList(istream&);
00062 
00063 private:
00064         edge    *fi;            
00065         Digraph& operator=(const Digraph&);
00066 };
00067 
00072 inline edge Digraph::tail(edge e) const { return left(e); }
00073 
00078 inline edge Digraph::head(edge e) const { return right(e); }
00079 
00084 inline edge Digraph::firstAt(vertex v) const {
00085         assert(validVertex(v));
00086         return (fi[v] != 0 ? fi[v]/2 : firstOut(v));
00087 }
00088 
00095 inline edge Digraph::nextAt(vertex v, edge e) const {
00096         assert(validVertex(v) && validEdge(e));
00097         if (v != evec[e].l && v != evec[e].r) return 0;
00098         int ee = (v == evec[e].l ? 2*e : 2*e+1);
00099         int ff = adjLists->suc(ee);
00100         return (ff == fi[v] ? firstOut(v) : (ff == fe[v] ? 0 : ff/2));
00101 }
00102 
00107 inline edge Digraph::firstIn(vertex v) const {
00108         assert(validVertex(v));
00109         return fi[v]/2;
00110 }
00111 
00118 inline edge Digraph::nextIn(vertex v, edge e) const {
00119         assert(validVertex(v) && validEdge(e));
00120         if (v != evec[e].l && v != evec[e].r) return 0;
00121         int ee = (v == evec[e].l ? 2*e : 2*e+1);
00122         int ff = adjLists->suc(ee);
00123         return (fi[v] == ff ? 0 : ff/2);
00124 }
00125 
00130 inline edge Digraph::firstOut(vertex v) const {
00131         assert(validVertex(v));
00132         return fe[v]/2;
00133 }
00134 
00141 inline edge Digraph::nextOut(vertex v, edge e) const {
00142         assert(validVertex(v) && validEdge(e));
00143         if (v != evec[e].l && v != evec[e].r) return 0;
00144         int ee = (v == evec[e].l ? 2*e : 2*e+1);
00145         int ff = adjLists->suc(ee);
00146         return (fe[v] == ff ? 0 : ff/2);
00147 }
00148 
00149 } // ends namespace
00150 
00151 #endif
 All Classes Files Functions Variables Typedefs Friends