src/include/oldgraph.h
changeset 96 e2e18eb0fd10
parent 1 207fb3c727cb
equal deleted inserted replaced
0:cabfc2b8d4f5 1:e7a9b875ed17
   109   void inc_nodes_size(int n);
   109   void inc_nodes_size(int n);
   110   
   110   
   111  public:
   111  public:
   112   int NodeNum() {return nodenum;};
   112   int NodeNum() {return nodenum;};
   113   int EdgeNum();
   113   int EdgeNum();
   114   int MaxNode() {return nodes_size;};
   114   int MaxNode() const {return nodes_size;};
   115   int FirstNode() {return firstnode;};
   115   int FirstNode() const {return firstnode;};
   116   int NextNode(int n) {return nodes[n].next;};
   116   int NextNode(int n) const {return nodes[n].next;};
   117   int PrevNode(int n) {return nodes[n].prev;};
   117   int PrevNode(int n) const {return nodes[n].prev;};
   118   N& operator()(int n) {return *(N*)(nodes[n].data);};
   118   N& operator()(int n) const {return *(N*)(nodes[n].data);};
   119   N& Data      (int n) {return *(N*)(nodes[n].data);};
   119   N& Data      (int n) const {return *(N*)(nodes[n].data);};
   120   int AddNode();
   120   int AddNode();
   121   void AddNodeBlock(int n) {for(int i=0;i<n;i++) AddNode();}
   121   void AddNodeBlock(int n) const {for(int i=0;i<n;i++) AddNode();}
   122   int AddNode(int n);
   122   int AddNode(int n);
   123   void Delete(int n);
   123   void Delete(int n);
   124   int isaNode(int n) {return n>=0&&n<nodes_size&&nodes[n].indeg!=FREE_NODE;};
   124   int isaNode(int n) const 
   125   
   125         {return n>=0&&n<nodes_size&&nodes[n].indeg!=FREE_NODE;};
   126   int InDeg(int n) {return nodes[n].indeg;};
   126   
   127   int OutDeg(int n) {return nodes[n].outdeg;};
   127   int InDeg(int n) const {return nodes[n].indeg;};
   128   EdgePoint FirstIn(int n) {return nodes[n].firstin;};
   128   int OutDeg(int n) const {return nodes[n].outdeg;};
   129   EdgePoint FirstOut(int n) {return nodes[n].firstout;};
   129   EdgePoint FirstIn(int n) const {return nodes[n].firstin;};
   130 
   130   EdgePoint FirstOut(int n) const {return nodes[n].firstout;};
   131   E& operator()(EdgePoint e) {return *(E*)(((edge_t*)e)->data);};
   131 
   132   E& Data      (EdgePoint e) {return *(E*)(((edge_t*)e)->data);};
   132   E& operator()(EdgePoint e) const {return *(E*)(((edge_t*)e)->data);};
   133   int From(EdgePoint e) {return e->from;};
   133   E& Data      (EdgePoint e) const {return *(E*)(((edge_t*)e)->data);};
   134   int To(EdgePoint e) {return e->to;};
   134   int From(EdgePoint e) const {return e->from;};
   135   EdgePoint NextIn(EdgePoint e)
   135   int To(EdgePoint e) const {return e->to;};
       
   136   EdgePoint NextIn(EdgePoint e) const 
   136     {return e->nextin;};
   137     {return e->nextin;};
   137   EdgePoint NextOut(EdgePoint e)
   138   EdgePoint NextOut(EdgePoint e)const 
   138     {return e->nextout;};
   139     {return e->nextout;};
   139   EdgePoint AddEdge(int f, int t);
   140   EdgePoint AddEdge(int f, int t);
   140   void Delete(EdgePoint e);
   141   void Delete(EdgePoint e);
   141   EdgePoint Edge(int f,int t);
   142   EdgePoint Edge(int f,int t);
   142   //  EdgePoint Edge(E &d)
   143   //  EdgePoint Edge(E &d)
   143   //    {return (EdgePoint)(((char*)&d)-(char*)&(((edge_t*)NULL)->data));};
   144   //    {return (EdgePoint)(((char*)&d)-(char*)&(((edge_t*)NULL)->data));};
   144   E& operator()(int f, int t) {return *(E*)(((edge_t*)Edge(f,t))->data);};
   145   E& operator()(int f, int t) const {return *(E*)(((edge_t*)Edge(f,t))->data);};
   145   E& Data(int f, int t) {return *(E*)(((edge_t*)Edge(f,t))->data);};
   146   E& Data(int f, int t) const {return *(E*)(((edge_t*)Edge(f,t))->data);};
   146   void Delete(int f, int t) {Delete(Edge(f,t));};
   147   void Delete(int f, int t) {Delete(Edge(f,t));};
   147   void Reverse(EdgePoint e);
   148   void Reverse(EdgePoint e);
   148 
   149 
   149   // Functions for EdgeIndex
   150   // Functions for EdgeIndex
   150   
   151   
   151   EdgePoint Edge(EdgeIndex i)
   152   EdgePoint Edge(EdgeIndex i) const 
   152     { return (EdgePoint)(edges[i.block]->fields+i.index);};
   153     { return (EdgePoint)(edges[i.block]->fields+i.index);};
   153   EdgeIndex Index(EdgePoint e) { return e->index;};
   154   EdgeIndex Index(EdgePoint e) const { return e->index;};
   154   EdgeIndex Index(int f, int t) { EdgePoint e; return Edge(f,t)->index; }
   155   EdgeIndex Index(int f, int t) const { EdgePoint e; return Edge(f,t)->index; }
   155   void Delete(EdgeIndex i) { Delete(Edge(i));};
   156   void Delete(EdgeIndex i) { Delete(Edge(i));};
   156   E& operator()(EdgeIndex i)
   157   E& operator()(EdgeIndex i) const 
   157      {return *(E*)(edges[i.block]->fields[i.index].data);};
   158      {return *(E*)(edges[i.block]->fields[i.index].data);};
   158   E& Data(EdgeIndex i)
   159   E& Data(EdgeIndex i) const 
   159      {return *(E*)(edges[i.block]->fields[i.index].data);};
   160      {return *(E*)(edges[i.block]->fields[i.index].data);};
   160   EdgePoint AddEdge(int f, int t,EdgeIndex in);
   161   EdgePoint AddEdge(int f, int t,EdgeIndex in);
   161   
   162   
   162 
   163 
   163   
   164   
   164   // Operators for symmetric graphs:
   165   // Operators for symmetric graphs:
   165 
   166 
   166   EdgePoint FirstEdge(int n)
   167   EdgePoint FirstEdge(int n) const 
   167     { return (EdgePoint)(FirstIn(n)?FirstIn(n):FirstOut(n));};
   168     { return (EdgePoint)(FirstIn(n)?FirstIn(n):FirstOut(n));};
   168   EdgePoint NextEdge(int n,EdgePoint e)
   169   EdgePoint NextEdge(int n,EdgePoint e) const 
   169     { return From(e)==n?NextOut(e):(NextIn(e)?NextIn(e):FirstOut(n)); };
   170     { return From(e)==n?NextOut(e):(NextIn(e)?NextIn(e):FirstOut(n)); };
   170   int Opposite(EdgePoint e,int n)
   171   int Opposite(EdgePoint e,int n) const 
   171     { return From(e)+To(e)-n; };
   172     { return From(e)+To(e)-n; };
   172   
   173   
   173   // Initializers, destructors
   174   // Initializers, destructors
   174        
   175        
   175   OldGraph() {setup();};
   176   OldGraph() {setup();};
   220   
   221   
   221 }
   222 }
   222 
   223 
   223 template<class N, class E> void OldGraph<N,E>::destroy()
   224 template<class N, class E> void OldGraph<N,E>::destroy()
   224 {
   225 {
   225   edge_block *oe;
       
   226   int i;
   226   int i;
   227   
   227   
   228   while(firstnode!=INVALID) Delete(firstnode);
   228   while(firstnode!=INVALID) Delete(firstnode);
   229   delete [] nodes;
   229   delete [] nodes;
   230   for(i=0;i<edge_block_num;i++) delete edges[i];
   230   for(i=0;i<edge_block_num;i++) delete edges[i];