2 edge_out.cc -- implement Directed_graph_node
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.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_edge (s
.edge_out_l_arr_
[i
]);
45 Directed_graph_node::OK() const
48 for (int i
=0; i
< edge_out_l_arr_
.size(); i
++)
50 assert (edge_out_l_arr_
[i
]->
51 edge_in_l_arr_
.find_l (this));
53 for (int i
=0; i
< edge_in_l_arr_
.size(); i
++)
54 assert (edge_in_l_arr_
[i
]->contains_b (this));
59 Directed_graph_node::contains_b (const Directed_graph_node
*d
) const
61 return edge_out_l_arr_
.find_l ((Directed_graph_node
*)d
);
65 Directed_graph_node::remove_edge_out_idx (int i
)
68 Directed_graph_node
* d_l
= edge_out_l_arr_
.get (i
);
70 int j
= d_l
->edge_in_l_arr_
.find_i (this);
72 d_l
->edge_in_l_arr_
.unordered_del (j
);
77 Directed_graph_node::remove_edge_in (Directed_graph_node
*d_l
)
80 d_l
->remove_edge_out (this);
85 Directed_graph_node::remove_edge_out (Directed_graph_node
*d_l
)
88 for (int i
=0; i
< edge_out_l_arr_
.size();)
90 if (edge_out_l_arr_
[i
]== d_l
)
91 remove_edge_out_idx (i
);
98 Directed_graph_node::linked_b() const
100 return edge_out_l_arr_
.size() || edge_in_l_arr_
.size ();
104 Directed_graph_node::junk_links()
106 edge_in_l_arr_
.set_size (0);
107 edge_out_l_arr_
.set_size (0);
112 Directed_graph_node::unlink()
117 Link_array
<Directed_graph_node
> t
= edge_out_l_arr_
;
118 t
.concat (edge_in_l_arr_
);
121 while (edge_out_l_arr_
.size())
122 remove_edge_out_idx (0);
124 while (edge_in_l_arr_
.size())
125 remove_edge_in (edge_in_l_arr_
[0]);
128 for (int i
=0; i
< t
.size(); i
++)
133 Directed_graph_node::~Directed_graph_node()
135 // assert (!linked_b()); // hampered by memfrobbing
140 Directed_graph_node::add_edge (Directed_graph_node
* dep_l
)
145 dep_l
->edge_in_l_arr_
.push (this);
146 edge_out_l_arr_
.push (dep_l
);
151 Directed_graph_node::Directed_graph_node()