Vcsn  2.2
Be Rational
info.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm> // std::max
4 #include <iostream>
5 
7 
8 namespace vcsn
9 {
10  namespace rat
11  {
12 
16  template <typename ExpSet>
17  class info
18  : public ExpSet::const_visitor
19  {
20  public:
21  using expressionset_t = ExpSet;
22  using super_t = typename expressionset_t::const_visitor;
23  using self_t = info;
24 
26  using node_t = typename expressionset_t::node_t;
27 
29  void operator()(const node_t& v)
30  {
31  clear();
32  v.accept(*this);
33  }
34 
36  void operator()(const std::shared_ptr<const node_t>& v)
37  {
38  operator()(*v);
39  }
40 
41  void clear()
42  {
43  atom = 0;
44  complement = 0;
45  conjunction = 0;
46  depth = 0;
47  infiltration = 0;
48  ldiv = 0;
49  lweight = 0;
50  one = 0;
51  prod = 0;
52  rweight = 0;
53  shuffle = 0;
54  star = 0;
55  sum = 0;
56  transposition = 0;
57  tuple = 0;
58  zero = 0;
59  }
60 
62  template <typename OtherExpSet>
64  {
65  atom += other.atom;
66  complement += other.complement;
67  conjunction += other.conjunction;
68  depth = std::max(depth, other.depth);
69  infiltration += other.infiltration;
70  ldiv += other.ldiv;
71  lweight += other.lweight;
72  one += other.one;
73  prod += other.prod;
74  rweight += other.rweight;
75  shuffle += other.shuffle;
76  star += other.star;
77  sum += other.sum;
78  transposition += other.transposition;
79  tuple += other.tuple;
80  zero += other.zero;
81  return *this;
82  }
83 
85  constexpr static const char* me() { return "info"; }
86 
88  size_t depth = 0;
89 
90 #define DEFINE(Type) \
91  public: \
92  size_t Type = 0; \
93  private: \
94  VCSN_RAT_VISIT(Type, v)
95 
96  DEFINE(atom) { ++atom; (void) v; depth = 0; }
100  DEFINE(ldiv) { ++ldiv; visit_(v); }
101  DEFINE(lweight) { ++lweight; v.sub()->accept(*this); ++depth; }
102  DEFINE(one) { ++one; (void) v; depth = 0; }
104  DEFINE(rweight) { ++rweight; v.sub()->accept(*this); ++depth; }
106  DEFINE(star) { ++star; visit_(v); }
107  DEFINE(sum) { ++sum; visit_(v); }
109  DEFINE(zero) { ++zero; (void) v; depth = 0; }
110 #undef DEFINE
111 
112  private:
113  template <type_t Type>
115 
117  template <rat::exp::type_t Type>
118  void visit_(const unary_t<Type>& v)
119  {
120  v.sub()->accept(*this);
121  ++depth;
122  }
123 
124  template <type_t Type>
126 
128  template <exp::type_t Type>
129  void visit_(const variadic_t<Type>& v)
130  {
131  size_t d = 0;
132  for (const auto& c: v)
133  {
134  c->accept(*this);
135  d = std::max(d, depth);
136  }
137  depth = d + 1;
138  }
139 
140  /*---------.
141  | tuple. |
142  `---------*/
143 
144  public:
146  size_t tuple = 0;
147  using tuple_t = typename super_t::tuple_t;
148 
149  private:
150  template <bool = context_t::is_lat,
151  typename Dummy = void>
152  struct visit_tuple
153  {
155  template <size_t I>
156  void info_(const tuple_t& v)
157  {
158  using expset_t = typename expressionset_t::template project_t<I>;
159  visitor_ += make_info<expset_t>(std::get<I>(v.sub()));
160  }
161 
163  template <size_t... I>
165  {
166  using swallow = int[];
167  (void) swallow
168  {
169  (info_<I>(v),
170  0)...
171  };
172  }
173 
175  void operator()(const tuple_t& v)
176  {
178  ++visitor_.tuple;
179  ++visitor_.depth;
180  }
182  };
183 
184  template <typename Dummy>
185  struct visit_tuple<false, Dummy>
186  {
187  void operator()(const tuple_t&)
188  {
190  }
192  };
193 
194  void visit(const tuple_t& v, std::true_type) override
195  {
196  visit_tuple<>{*this}(v);
197  }
198  };
199 
200  template <typename ExpSet>
201  info<ExpSet> make_info(const typename ExpSet::value_t& r)
202  {
203  auto s = info<ExpSet>{};
204  s(r);
205  return s;
206  }
207  } // namespace rat
208 } // namespace vcsn
static constexpr const char * me()
Name of this algorithm, for error messages.
Definition: info.hh:85
size_t zero
Definition: info.hh:109
void info_(const tuple_t &v, detail::index_sequence< I... >)
Info all the tapes.
Definition: info.hh:164
info< ExpSet > make_info(const typename ExpSet::value_t &r)
Definition: info.hh:201
typename expressionset_t::node_t node_t
Definition: info.hh:26
size_t shuffle
Definition: info.hh:105
size_t conjunction
Definition: info.hh:98
Definition: a-star.hh:8
size_t sum
Definition: info.hh:107
size_t lweight
Definition: info.hh:101
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:55
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
An inner node with multiple children.
Definition: expression.hh:118
size_t rweight
Definition: info.hh:104
void clear()
Definition: info.hh:41
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
const value_t sub() const
Definition: expression.hxx:141
void visit_(const variadic_t< Type > &v)
Factor the visitation of variadic nodes.
Definition: info.hh:129
context_t_of< expressionset_t > context_t
Definition: info.hh:25
#define DEFINE(Type)
Definition: info.hh:90
size_t tuple
Number of tuple operators.
Definition: info.hh:146
size_t transposition
Definition: info.hh:108
Gather information of the number of the different node types.
Definition: fwd.hh:20
size_t infiltration
Definition: info.hh:99
void visit(const tuple_t &v, std::true_type) override
Definition: info.hh:194
size_t complement
Definition: info.hh:97
typename expressionset_t::const_visitor super_t
Definition: info.hh:22
void operator()(const std::shared_ptr< const node_t > &v)
Entry point: compute info about v.
Definition: info.hh:36
size_t one
Definition: info.hh:102
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Definition: traits.hh:53
typename super_t::tuple_t tuple_t
Definition: info.hh:147
An inner node implementing a weight.
Definition: expression.hh:264
size_t prod
Definition: info.hh:103
size_t depth
Depth of the tree.
Definition: info.hh:88
void operator()(const node_t &v)
For each node type, count its number of occurrences.
Definition: info.hh:29
size_t ldiv
Definition: info.hh:100
std::ostream & info(const Aut &aut, std::ostream &out, bool detailed=false)
Definition: info.hh:72
info & operator+=(const info< OtherExpSet > &other)
Add the result from another info operator.
Definition: info.hh:63
Implementation of nodes of tuple of rational expressions.
Definition: expression.hh:182
ExpSet expressionset_t
Definition: info.hh:21
void visit_(const unary_t< Type > &v)
Factor the visitation of unary nodes.
Definition: info.hh:118
size_t atom
Definition: info.hh:96
void info_(const tuple_t &v)
Info about tape I.
Definition: info.hh:156
size_t star
Definition: info.hh:106
void operator()(const tuple_t &v)
Entry point.
Definition: info.hh:175