src/work/sage_graph.h
changeset 986 e997802b855c
parent 921 818510fa3d99
child 987 87f7c54892df
     1.1 --- a/src/work/sage_graph.h	Sat Nov 13 12:24:01 2004 +0000
     1.2 +++ b/src/work/sage_graph.h	Sat Nov 13 12:53:28 2004 +0000
     1.3 @@ -96,8 +96,8 @@
     1.4  
     1.5      struct edge_item {
     1.6        int id;
     1.7 -      node_item* _tail;
     1.8 -      node_item* _head;
     1.9 +      node_item* _source;
    1.10 +      node_item* _target;
    1.11        edge_item* _next_out;
    1.12        edge_item* _prev_out;
    1.13        edge_item* _next_in;
    1.14 @@ -121,22 +121,22 @@
    1.15        return p;
    1.16      }
    1.17  
    1.18 -    edge_item* _add_edge(node_item* _tail, node_item* _head) {
    1.19 +    edge_item* _add_edge(node_item* _source, node_item* _target) {
    1.20        edge_item* e=new edge_item;
    1.21        e->id=edge_id++;
    1.22 -      e->_tail=_tail;
    1.23 -      e->_head=_head;
    1.24 +      e->_source=_source;
    1.25 +      e->_target=_target;
    1.26        
    1.27 -      e->_prev_out=_tail->_last_out_edge;
    1.28 -      if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
    1.29 -      _tail->_last_out_edge=e;
    1.30 -      if (!_tail->_first_out_edge) _tail->_first_out_edge=e; 
    1.31 +      e->_prev_out=_source->_last_out_edge;
    1.32 +      if (_source->_last_out_edge) (_source->_last_out_edge)->_next_out=e;
    1.33 +      _source->_last_out_edge=e;
    1.34 +      if (!_source->_first_out_edge) _source->_first_out_edge=e; 
    1.35        e->_next_out=0;
    1.36   
    1.37 -      e->_prev_in=_head->_last_in_edge;
    1.38 -      if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
    1.39 -      _head->_last_in_edge=e;
    1.40 -      if (!_head->_first_in_edge) { _head->_first_in_edge=e; } 
    1.41 +      e->_prev_in=_target->_last_in_edge;
    1.42 +      if (_target->_last_in_edge) (_target->_last_in_edge)->_next_in=e;
    1.43 +      _target->_last_in_edge=e;
    1.44 +      if (!_target->_first_in_edge) { _target->_first_in_edge=e; } 
    1.45        e->_next_in=0;
    1.46  
    1.47        ++_edge_num;
    1.48 @@ -156,45 +156,45 @@
    1.49  
    1.50      void _delete_edge(edge_item* e) {
    1.51        if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 
    1.52 -	(e->_tail)->_last_out_edge=e->_prev_out;
    1.53 +	(e->_source)->_last_out_edge=e->_prev_out;
    1.54        if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 
    1.55 -	(e->_tail)->_first_out_edge=e->_next_out;
    1.56 +	(e->_source)->_first_out_edge=e->_next_out;
    1.57        if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 
    1.58 -	(e->_head)->_last_in_edge=e->_prev_in;
    1.59 +	(e->_target)->_last_in_edge=e->_prev_in;
    1.60        if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 
    1.61 -	(e->_head)->_first_in_edge=e->_next_in;
    1.62 +	(e->_target)->_first_in_edge=e->_next_in;
    1.63  
    1.64        delete e;
    1.65        --_edge_num;
    1.66      }
    1.67  
    1.68 -    void _set_tail(edge_item* e, node_item* _tail) {
    1.69 +    void _set_source(edge_item* e, node_item* _source) {
    1.70        if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 
    1.71 -	(e->_tail)->_last_out_edge=e->_prev_out;
    1.72 +	(e->_source)->_last_out_edge=e->_prev_out;
    1.73        if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 
    1.74 -	(e->_tail)->_first_out_edge=e->_next_out;
    1.75 +	(e->_source)->_first_out_edge=e->_next_out;
    1.76        
    1.77 -      e->_tail=_tail;
    1.78 +      e->_source=_source;
    1.79        
    1.80 -      e->_prev_out=_tail->_last_out_edge;
    1.81 -      if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
    1.82 -      _tail->_last_out_edge=e;
    1.83 -      if (!_tail->_first_out_edge) _tail->_first_out_edge=e; 
    1.84 +      e->_prev_out=_source->_last_out_edge;
    1.85 +      if (_source->_last_out_edge) (_source->_last_out_edge)->_next_out=e;
    1.86 +      _source->_last_out_edge=e;
    1.87 +      if (!_source->_first_out_edge) _source->_first_out_edge=e; 
    1.88        e->_next_out=0;
    1.89      }
    1.90  
    1.91 -    void _set_head(edge_item* e, node_item* _head) {
    1.92 +    void _set_target(edge_item* e, node_item* _target) {
    1.93        if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 
    1.94 -	(e->_head)->_last_in_edge=e->_prev_in;
    1.95 +	(e->_target)->_last_in_edge=e->_prev_in;
    1.96        if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 
    1.97 -	(e->_head)->_first_in_edge=e->_next_in;
    1.98 +	(e->_target)->_first_in_edge=e->_next_in;
    1.99        
   1.100 -      e->_head=_head;
   1.101 +      e->_target=_target;
   1.102        
   1.103 -      e->_prev_in=_head->_last_in_edge;
   1.104 -      if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
   1.105 -      _head->_last_in_edge=e;
   1.106 -      if (!_head->_first_in_edge) { _head->_first_in_edge=e; } 
   1.107 +      e->_prev_in=_target->_last_in_edge;
   1.108 +      if (_target->_last_in_edge) (_target->_last_in_edge)->_next_in=e;
   1.109 +      _target->_last_in_edge=e;
   1.110 +      if (!_target->_first_in_edge) { _target->_first_in_edge=e; } 
   1.111        e->_next_in=0;
   1.112      }
   1.113  
   1.114 @@ -221,8 +221,8 @@
   1.115      //OutEdgeIt firstOutEdge(const Node v) const { return OutEdgeIt(v); }
   1.116      //InEdgeIt firstInEdge(const Node v) const { return InEdgeIt(v); }
   1.117      //SymEdgeIt firstSymEdge(const Node v) const { return SymEdgeIt(v); }
   1.118 -    Node tail(Edge e) const { return e.tailNode(); }
   1.119 -    Node head(Edge e) const { return e.headNode(); }
   1.120 +    Node source(Edge e) const { return e.sourceNode(); }
   1.121 +    Node target(Edge e) const { return e.targetNode(); }
   1.122  
   1.123      Node aNode(const OutEdgeIt& e) const { return e.aNode(); }
   1.124      Node aNode(const InEdgeIt& e) const { return e.aNode(); }
   1.125 @@ -251,8 +251,8 @@
   1.126        e=InEdgeIt(*this, v); return e; }
   1.127      SymEdgeIt& first(SymEdgeIt& e, Node v) const { 
   1.128        e=SymEdgeIt(*this, v); return e; }
   1.129 -    //void getTail(Node& n, const Edge& e) const { n=tail(e); }
   1.130 -    //void getHead(Node& n, const Edge& e) const { n=head(e); }
   1.131 +    //void getSource(Node& n, const Edge& e) const { n=source(e); }
   1.132 +    //void getTarget(Node& n, const Edge& e) const { n=target(e); }
   1.133  
   1.134      //void getANode(Node& n, const OutEdgeIt& e) const { n=e.aNode(); }
   1.135      //void getANode(Node& n, const InEdgeIt& e) const { n=e.aNode(); }
   1.136 @@ -329,12 +329,12 @@
   1.137        //while (first<NodeIt>().valid()) erase(first<NodeIt>());
   1.138      }
   1.139  
   1.140 -    void setTail(Edge e, Node tail) {
   1.141 -      _set_tail(e.edge, tail.node); 
   1.142 +    void setSource(Edge e, Node source) {
   1.143 +      _set_source(e.edge, source.node); 
   1.144      }
   1.145  
   1.146 -    void setHead(Edge e, Node head) {
   1.147 -      _set_head(e.edge, head.node); 
   1.148 +    void setTarget(Edge e, Node target) {
   1.149 +      _set_target(e.edge, target.node); 
   1.150      }
   1.151  
   1.152      /* stream operations, for testing purpose */
   1.153 @@ -348,7 +348,7 @@
   1.154  //     }
   1.155  //     friend std::ostream& operator<<(std::ostream& os, const Edge& i) { 
   1.156  //       if (i.valid()) 
   1.157 -// 	os << "(" << i.edge->_tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")"; 
   1.158 +// 	os << "(" << i.edge->_source->id << "--" << i.edge->id << "->" << i.edge->_target->id << ")"; 
   1.159  //       else 
   1.160  // 	os << "invalid";
   1.161  //       return os; 
   1.162 @@ -419,8 +419,8 @@
   1.163        friend bool operator==(Edge u, Edge v) { return v.edge==u.edge; } 
   1.164        friend bool operator!=(Edge u, Edge v) { return v.edge!=u.edge; } 
   1.165      protected:
   1.166 -      Node tailNode() const { return Node(edge->_tail); }
   1.167 -      Node headNode() const { return Node(edge->_head); }
   1.168 +      Node sourceNode() const { return Node(edge->_source); }
   1.169 +      Node targetNode() const { return Node(edge->_target); }
   1.170      public:
   1.171        friend std::ostream& operator<<(std::ostream& os, const Edge& i);
   1.172      };
   1.173 @@ -440,7 +440,7 @@
   1.174  //       EdgeIt(edge_item* _e) : Edge(_e) { }
   1.175      public:
   1.176        EdgeIt& operator++() { 
   1.177 -	node_item* v=edge->_tail;
   1.178 +	node_item* v=edge->_source;
   1.179  	edge=edge->_next_out; 
   1.180  	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
   1.181  	return *this;
   1.182 @@ -456,8 +456,8 @@
   1.183        OutEdgeIt(const SageGraph&, const Edge& e) : Edge(e) { }
   1.184        OutEdgeIt& operator++() { edge=edge->_next_out; return *this; }
   1.185      protected:
   1.186 -      Node aNode() const { return Node(edge->_tail); }
   1.187 -      Node bNode() const { return Node(edge->_head); }
   1.188 +      Node aNode() const { return Node(edge->_source); }
   1.189 +      Node bNode() const { return Node(edge->_target); }
   1.190      };
   1.191      
   1.192      class InEdgeIt : public Edge {
   1.193 @@ -469,8 +469,8 @@
   1.194        InEdgeIt(const SageGraph&, const Edge& e) : Edge(e) { }
   1.195        InEdgeIt& operator++() { edge=edge->_next_in; return *this; }
   1.196      protected:
   1.197 -      Node aNode() const { return Node(edge->_head); }
   1.198 -      Node bNode() const { return Node(edge->_tail); }
   1.199 +      Node aNode() const { return Node(edge->_target); }
   1.200 +      Node bNode() const { return Node(edge->_source); }
   1.201      };
   1.202  
   1.203      class SymEdgeIt : public Edge {
   1.204 @@ -495,7 +495,7 @@
   1.205      protected:
   1.206        SymEdgeIt& operator++() { 
   1.207  	if (out_or_in) { 
   1.208 -	  node_item* v=edge->_tail;
   1.209 +	  node_item* v=edge->_source;
   1.210  	  edge=edge->_next_out; 
   1.211  	  if (!edge) { out_or_in=0; edge=v->_first_in_edge; }
   1.212  	} else {
   1.213 @@ -505,9 +505,9 @@
   1.214        }
   1.215      protected:
   1.216        Node aNode() const { 
   1.217 -	return (out_or_in) ? Node(edge->_tail) : Node(edge->_head); }
   1.218 +	return (out_or_in) ? Node(edge->_source) : Node(edge->_target); }
   1.219        Node bNode() const { 
   1.220 -	return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); }
   1.221 +	return (out_or_in) ? Node(edge->_target) : Node(edge->_source); }
   1.222      };
   1.223    };
   1.224  
   1.225 @@ -523,8 +523,8 @@
   1.226    inline
   1.227    std::ostream& operator<<(std::ostream& os, const SageGraph::Edge& i) { 
   1.228      if (i.valid()) 
   1.229 -      os << "(" << i.tailNode() << "--" << i.edge->id << "->" 
   1.230 -	 << i.headNode() << ")"; 
   1.231 +      os << "(" << i.sourceNode() << "--" << i.edge->id << "->" 
   1.232 +	 << i.targetNode() << ")"; 
   1.233      else 
   1.234        os << "invalid";
   1.235      return os;