2 edge_out.cc -- implement Directed_graph_node
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "directed-graph.hh"
11 #ifdef PARANOID // these checks eat huge amounts of time.
12 #define PARANOID_OK() OK()
18 Link_array<Directed_graph_node> const &
19 Directed_graph_node::get_in_edge_arr() const
21 return edge_in_l_arr_;
24 Link_array<Directed_graph_node> const &
25 Directed_graph_node::get_out_edge_arr()const
27 return edge_out_l_arr_;
31 Should not copy deps automatically
33 Directed_graph_node::Directed_graph_node(Directed_graph_node const&)
38 Directed_graph_node::copy_edges_out(Directed_graph_node const &s)
40 for(int i=0; i < s.edge_out_l_arr_.size(); i++)
41 add(s.edge_out_l_arr_[i]);
45 Directed_graph_node::OK() const
48 for (int i=0; i < edge_out_l_arr_.size(); i++) {
49 assert(edge_out_l_arr_[i]->
50 edge_in_l_arr_.find_l(this));
52 for (int i=0; i < edge_in_l_arr_.size(); i++)
53 assert(edge_in_l_arr_[i]->contains_b( this));
58 Directed_graph_node::contains_b(const Directed_graph_node *d)const
60 return edge_out_l_arr_.find_l((Directed_graph_node*)d);
64 Directed_graph_node::remove_edge_out_idx(int i)
67 Directed_graph_node * d_l = edge_out_l_arr_.get(i);
69 int j = d_l->edge_in_l_arr_.find_i(this);
71 d_l->edge_in_l_arr_.unordered_del(j);
76 Directed_graph_node::remove_edge_in(Directed_graph_node *d_l)
79 d_l->remove_edge_out(this);
84 Directed_graph_node::remove_edge_out (Directed_graph_node *d_l)
87 for (int i=0; i < edge_out_l_arr_.size(); ) {
88 if (edge_out_l_arr_[i]== d_l)
89 remove_edge_out_idx(i);
96 Directed_graph_node::linked_b()const
98 return edge_out_l_arr_.size() || edge_in_l_arr_.size();
102 Directed_graph_node::junk_links()
104 edge_in_l_arr_.set_size(0);
105 edge_out_l_arr_.set_size(0);
110 Directed_graph_node::unlink()
115 Link_array<Directed_graph_node> t = edge_out_l_arr_;
116 t.concat(edge_in_l_arr_);
119 while ( edge_out_l_arr_.size() )
120 remove_edge_out_idx(0);
122 while (edge_in_l_arr_.size() )
123 remove_edge_in(edge_in_l_arr_[0]);
126 for (int i =0; i < t.size(); i++)
131 Directed_graph_node::~Directed_graph_node()
138 Directed_graph_node::add(Directed_graph_node* dep_l)
143 dep_l->edge_in_l_arr_.push(this);
144 edge_out_l_arr_.push(dep_l);
149 Directed_graph_node::Directed_graph_node()