Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
star-height.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_STAR_HEIGHT_HH
2 # define VCSN_ALGOS_STAR_HEIGHT_HH
3 
4 # include <vcsn/core/rat/visitor.hh>
5 
6 namespace vcsn
7 {
8  namespace detail
9  {
10  template <typename RatExpSet>
12  : public RatExpSet::const_visitor
13  {
14  public:
15  using ratexpset_t = RatExpSet;
16  using super_t = typename ratexpset_t::const_visitor;
17  using node_t = typename super_t::node_t;
18  template <rat::type_t Type>
19  using variadic_t = typename super_t::template variadic_t<Type>;
20 
22  unsigned
23  operator()(const node_t& v)
24  {
25  height_ = 0;
26  v.accept(*this);
27  return height_;
28  }
29 
31  unsigned
32  operator()(const std::shared_ptr<const node_t>& v)
33  {
34  return operator()(*v);
35  }
36 
37  private:
38 
39 # define DEFINE(Type) \
40  using Type ## _t = typename super_t::Type ## _t; \
41  virtual void visit(const Type ## _t& v)
42 
43  DEFINE(atom) { (void) v; }
44  DEFINE(complement) { v.sub()->accept(*this); }
45  DEFINE(conjunction) { visit_variadic(v); }
46  DEFINE(ldiv) { visit_variadic(v); }
47  DEFINE(lweight) { v.sub()->accept(*this); }
48  DEFINE(one) { (void) v; }
49  DEFINE(prod) { visit_variadic(v); }
50  DEFINE(rweight) { v.sub()->accept(*this); }
51  DEFINE(shuffle) { visit_variadic(v); }
52  DEFINE(star) { ++height_; v.sub()->accept(*this); }
53  DEFINE(sum) { visit_variadic(v); }
54  DEFINE(transposition){ v.sub()->accept(*this); }
55  DEFINE(zero) { (void) v; }
56 
57 # undef DEFINE
58 
60  template <rat::type_t Type>
61  void
63  {
64  /* The height of an n-ary is the max of the n heights. */
65  auto max = height_;
66  auto initial = height_;
67  for (auto child : n)
68  {
69  height_ = initial;
70  child->accept(*this);
71  if (max < height_)
72  max = height_;
73  }
74  height_ = max;
75  }
76 
77  unsigned height_;
78  };
79  } // namespace detail
80 
81 
83  template <typename RatExpSet>
84  inline
85  unsigned
86  star_height(const typename RatExpSet::value_t& e)
87  {
89  return s(e);
90  }
91 
92  namespace dyn
93  {
94  namespace detail
95  {
97  template <typename RatExpSet>
98  unsigned
99  star_height(const ratexp& exp)
100  {
101  const auto& e = exp->as<RatExpSet>();
102  return ::vcsn::star_height<RatExpSet>(e.ratexp());
103  }
104 
106  (const ratexp& e) -> unsigned);
107  }
108  }
109 
110 } // namespace vcsn
111 
112 #endif // !VCSN_ALGOS_STAR_HEIGHT_HH
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
typename super_t::node_t node_t
Definition: star-height.hh:17
unsigned operator()(const node_t &v)
Entry point: return the size of v.
Definition: star-height.hh:23
unsigned star_height(const typename RatExpSet::value_t &e)
Star height of a ratexp.
Definition: star-height.hh:86
typename super_t::template variadic_t< Type > variadic_t
Definition: star-height.hh:19
unsigned star_height(const ratexp &exp)
Bridge.
Definition: star-height.hh:99
#define DEFINE(Type)
Definition: star-height.hh:39
unsigned operator()(const std::shared_ptr< const node_t > &v)
Entry point: return the size of v.
Definition: star-height.hh:32
typename ratexpset_t::const_visitor super_t
Definition: star-height.hh:16
void visit_variadic(const variadic_t< Type > &n)
Traverse variadic node.
Definition: star-height.hh:62