17 #ifndef VCSN_AUTOMATA_IMPLEMENTATION_LISTG_GRAPH_IMPL_HXX
18 # define VCSN_AUTOMATA_IMPLEMENTATION_LISTG_GRAPH_IMPL_HXX
26 # include <vaucanson/automata/implementation/listg_graph_impl.hh>
40 template <class Kind, class WordValue, class WeightValue, \
41 class SeriesValue, class Letter, class Tag, class GeometryCoords>
44 Graph<Kind, WordValue, WeightValue, SeriesValue, Letter, Tag, GeometryCoords>
59 GClass::Graph (
unsigned initial_number_of_state,
60 unsigned reserve_number_of_edge)
62 states_.resize(initial_number_of_state);
63 edges_.reserve(reserve_number_of_edge);
71 typename GClass::states_t
72 GClass::states()
const
75 hstate_t(states_.size() - 1),
80 typename GClass::edges_t
84 hedge_t(edges_.size() - 1),
89 typename GClass::initial_support_t
90 GClass::initial()
const
92 return initial_support_t(initial_);
96 typename GClass::final_support_t
99 return final_support_t(final_);
109 GClass::has_state(
const hstate_t& n)
const
111 bool res = (n.is_valid() &&
112 n < unsigned(states_.size()) &&
113 (removed_states_.find(n) == removed_states_.end()));
116 for (
unsigned i = 0; i < edges_.size(); ++i)
117 if (removed_edges_.find(hedge_t(i)) == removed_edges_.end())
118 postcondition(edges_[i].from != n
119 && edges_[i].to != n);
120 # endif // !VCSN_NDEBUG
125 typename GClass::hstate_t
126 GClass::get_state(
int n)
const
128 precondition(has_state(hstate_t(n)));
133 typename GClass::hstate_t
136 if (removed_states_.size() == 0)
139 return hstate_t(states_.size() - 1);
142 hstate_t n = *removed_states_.begin();
143 removed_states_.erase(n);
144 assertion(n < states_.size());
146 states_[n].output_edges.clear();
147 states_[n].input_edges.clear();
149 postcondition(has_state(n));
155 GClass::del_state(
const hstate_t& n)
157 precondition (has_state(n));
160 typename state_value::edges_t::const_iterator e = v.output_edges.begin();
161 typename state_value::edges_t::const_iterator end = v.output_edges.end();
162 typename state_value::edges_t::const_iterator next = e;
164 for (; e != end; e = next)
170 e = v.input_edges.begin();
171 end = v.input_edges.end();
172 for (next = e; e != end; e = next)
178 removed_states_.insert(n);
181 postcondition(!has_state(n));
186 GClass::set_initial(
const hstate_t& n,
const series_set_elt_value_t& v,
187 const series_set_elt_value_t& z)
189 precondition (has_state(n));
197 const typename GClass::series_set_elt_value_t&
198 GClass::get_initial(
const hstate_t& n,
const series_set_elt_value_t& z)
const
200 precondition(has_state(n));
201 typename initial_t::const_iterator i = initial_.find(n);
202 if (i == initial_.end())
209 GClass::is_initial(
const hstate_t& s,
const series_set_elt_value_t& z)
const
211 return get_initial(s, z) != z;
216 GClass::clear_initial()
218 return initial_.clear();
223 GClass::set_final(
const hstate_t& n,
const series_set_elt_value_t& v,
224 const series_set_elt_value_t& z)
226 precondition (has_state(n));
234 const typename GClass::series_set_elt_value_t&
235 GClass::get_final(
const hstate_t& n,
const series_set_elt_value_t& z)
const
237 precondition (has_state(n));
238 typename final_t::const_iterator i = final_.find(n);
239 if (i == final_.end())
246 GClass::is_final(
const hstate_t& s,
const series_set_elt_value_t& z)
const
248 return get_final(s, z) != z;
253 GClass::clear_final()
255 return final_.clear();
265 GClass::has_edge(
const hedge_t& e)
const
267 bool res = (removed_edges_.find(e) == removed_edges_.end()
268 && (e < edges_.size()));
271 for (
unsigned i = 0; i < states_.size(); ++i)
272 if (removed_states_.find(hstate_t(i)) == removed_states_.end())
273 postcondition(states_[i].output_edges.find(e) ==
274 states_[i].output_edges.end());
275 # endif // !VCSN_NDEBUG
280 typename GClass::hedge_t
281 GClass::add_edge(
const hstate_t& n1,
const hstate_t& n2,
284 precondition(has_state(n1));
285 precondition(has_state(n2));
287 if (removed_edges_.size() == 0)
289 edges_.push_back(edge_value_t(n1, n2, v));
290 e = hedge_t(edges_.size() - 1);
294 e = *removed_edges_.begin();
295 removed_edges_.erase(e);
296 assertion(e < edges_.size());
301 states_[n1].output_edges.insert(e);
302 states_[n2].input_edges.insert(e);
304 postcondition(has_edge(e));
310 GClass::del_edge(
const hedge_t& e)
312 precondition (has_edge(e));
314 const edge_value_t& ev = edges_[e];
315 states_[ev.from].output_edges.erase(e);
316 states_[ev.to].input_edges.erase(e);
317 removed_edges_.insert(e);
319 postcondition(!has_edge(e));
324 typename GClass::hstate_t
325 GClass::src_of(
const hedge_t& e1)
const
327 precondition(has_edge(e1));
328 return edges_[e1].from;
332 typename GClass::hstate_t
333 GClass::dst_of(
const hedge_t& e2)
const
335 precondition(has_edge(e2));
336 return edges_[e2].to;
340 const typename GClass::label_t&
341 GClass::label_of(
const hedge_t& n)
const
343 precondition(has_edge(n));
349 GClass::update(
const hedge_t& e, label_t l)
351 precondition(has_edge(e));
362 typename WordValue::iterator it;
363 typename label_t::const_iterator r;
367 for (
unsigned i = 0; i < edges_.size(); ++i)
369 if (removed_edges_.find(hedge_t(i)) != removed_edges_.end())
373 if (!has_state(dst_of(hedge_t(i)))
374 || !has_state(src_of(hedge_t(i))))
378 l = label_of(hedge_t(i));
379 for (r = l.begin(); r != l.end(); ++r)
382 for (it = w.begin(); it != w.end(); ++it)
383 if (!s.
series().monoid().alphabet().contains(*it))
402 const Tag& GClass::tag()
const
407 template <
class Kind,
class WordValue,
class WeightValue,
class SerieValue,
408 class Letter,
class Tag,
class GeometryCoords,
class I>
409 Tag& op_tag(
const AutomataBase<I>&,
410 Graph<Kind, WordValue, WeightValue,
411 SerieValue ,Letter, Tag, GeometryCoords>& v)
416 template <
class Kind,
class WordValue,
class WeightValue,
class SerieValue,
417 class Letter,
class Tag,
class GeometryCoords,
class I>
418 const Tag& op_tag(
const AutomataBase<I>&,
419 const Graph<Kind, WordValue, WeightValue,
420 SerieValue ,Letter, Tag, GeometryCoords>& v)
430 template <
class Kind,
class WordValue,
class WeightValue,
class SeriesValue,
431 class Letter,
class Tag,
class GeometryCoords,
class I>
432 typename GClass::geometry_t&
433 op_geometry(
const AutomataBase<I>&,
434 Graph<Kind, WordValue, WeightValue,
435 SeriesValue, Letter, Tag, GeometryCoords>& v)
440 template <
class Kind,
class WordValue,
class WeightValue,
class SeriesValue,
441 class Letter,
class Tag,
class GeometryCoords,
class I>
442 const typename GClass::geometry_t&
443 op_geometry(
const AutomataBase<I>&,
444 const Graph<Kind, WordValue, WeightValue,
445 SeriesValue, Letter, Tag, GeometryCoords>& v)
452 const typename GClass::geometry_t&
453 GClass::geometry()
const
459 typename GClass::geometry_t&
472 #endif // ! VCSN_AUTOMATA_IMPLEMENTATION_LISTG_GRAPH_IMPL_HXX