gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Modify the implementation of ListDigraph::ArcIt (#311) The new implementation is based on out-arc iteration (like ListGraph::ArcIt) instead of in-arc iteration to make it consistent with the documentation.
0 1 0
default
1 file changed with 7 insertions and 7 deletions:
↑ Collapse diff ↑
Show white space 48 line context
... ...
@@ -95,62 +95,62 @@
95 95
    ListDigraphBase()
96 96
      : nodes(), first_node(-1),
97 97
        first_free_node(-1), arcs(), first_free_arc(-1) {}
98 98

	
99 99

	
100 100
    int maxNodeId() const { return nodes.size()-1; }
101 101
    int maxArcId() const { return arcs.size()-1; }
102 102

	
103 103
    Node source(Arc e) const { return Node(arcs[e.id].source); }
104 104
    Node target(Arc e) const { return Node(arcs[e.id].target); }
105 105

	
106 106

	
107 107
    void first(Node& node) const {
108 108
      node.id = first_node;
109 109
    }
110 110

	
111 111
    void next(Node& node) const {
112 112
      node.id = nodes[node.id].next;
113 113
    }
114 114

	
115 115

	
116 116
    void first(Arc& arc) const {
117 117
      int n;
118 118
      for(n = first_node;
119
          n!=-1 && nodes[n].first_in == -1;
119
          n != -1 && nodes[n].first_out == -1;
120 120
          n = nodes[n].next) {}
121
      arc.id = (n == -1) ? -1 : nodes[n].first_in;
121
      arc.id = (n == -1) ? -1 : nodes[n].first_out;
122 122
    }
123 123

	
124 124
    void next(Arc& arc) const {
125
      if (arcs[arc.id].next_in != -1) {
126
        arc.id = arcs[arc.id].next_in;
125
      if (arcs[arc.id].next_out != -1) {
126
        arc.id = arcs[arc.id].next_out;
127 127
      } else {
128 128
        int n;
129
        for(n = nodes[arcs[arc.id].target].next;
130
            n!=-1 && nodes[n].first_in == -1;
129
        for(n = nodes[arcs[arc.id].source].next;
130
            n != -1 && nodes[n].first_out == -1;
131 131
            n = nodes[n].next) {}
132
        arc.id = (n == -1) ? -1 : nodes[n].first_in;
132
        arc.id = (n == -1) ? -1 : nodes[n].first_out;
133 133
      }
134 134
    }
135 135

	
136 136
    void firstOut(Arc &e, const Node& v) const {
137 137
      e.id = nodes[v.id].first_out;
138 138
    }
139 139
    void nextOut(Arc &e) const {
140 140
      e.id=arcs[e.id].next_out;
141 141
    }
142 142

	
143 143
    void firstIn(Arc &e, const Node& v) const {
144 144
      e.id = nodes[v.id].first_in;
145 145
    }
146 146
    void nextIn(Arc &e) const {
147 147
      e.id=arcs[e.id].next_in;
148 148
    }
149 149

	
150 150

	
151 151
    static int id(Node v) { return v.id; }
152 152
    static int id(Arc e) { return e.id; }
153 153

	
154 154
    static Node nodeFromId(int id) { return Node(id);}
155 155
    static Arc arcFromId(int id) { return Arc(id);}
156 156

	
0 comments (0 inline)