Awali
Another Weighted Automata library
sort.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_ALGOS_SORT_HH
18 # define AWALI_ALGOS_SORT_HH
19 
20 
21 # include <algorithm>
22 
23 namespace awali { namespace sttc {
24 
25  template <typename Aut, typename Compare>
26  inline
27  void
28  sort(Aut a, Compare p)
29  {
30  for(auto s: a->states()) {
31  auto& out = a->all_out_(s);
32  std::sort(out.begin(), out.end(), p);
33  }
34  }
35 
36  template <size_t I, typename Tdc>
37  inline
38  void
39  sort_tape(Tdc t)
40  {
41  sort(t, [t](transition_t t1, transition_t t2) {
42  auto ls=t->context().labelset()->template set<I>();
43  return ls.less_than(std::get<I>(t->label_of(t1)),
44  std::get<I>(t->label_of(t2)));
45  });
46  }
47 
48 
49 
50 }}//end of ns awali::stc
51 
52 #endif // !AWALI_ALGOS_SORT_HH
void sort(Aut a, Compare p)
Definition: sort.hh:28
void sort_tape(Tdc t)
Definition: sort.hh:39
Main namespace of Awali.
Definition: ato.hh:22
unsigned transition_t
Definition: types.hh:22