27 # ifndef TOPOLOGICAL_SORT_H 28 # define TOPOLOGICAL_SORT_H 30 # include <tpl_dynListQueue.H> 31 # include <tpl_graph.H> 55 noexcept(std::is_nothrow_move_assignable<SA>::value)
56 : sa(__sa), gptr(
nullptr) { }
59 noexcept(std::is_nothrow_copy_assignable<SA>::value)
60 : sa(__sa), gptr(
nullptr) { }
64 template <
template <
class>
class List>
65 void topological_sort(
typename GT::Node * curr,
66 List<typename GT::Node*> &
list)
68 assert(gptr !=
nullptr);
75 const auto & n = gptr->get_num_nodes();
78 for (Itor<GT,SA> it(curr,sa); it.has_curr() and list.size() < n; it.next_ne())
79 topological_sort(it.get_tgt_node_ne(), list);
95 template <
template <
class>
class List>
96 List<typename GT::Node*>
perform (
const GT & g)
98 g.reset_bit_nodes(Depth_First);
101 List<typename GT::Node*> list;
104 const auto & n = gptr->get_num_nodes();
105 for (
auto it = g.get_node_it(); it.has_curr() and list.size() < n;
108 auto curr = it.get_current_node_ne();
110 topological_sort(curr, list);
120 perform<DynDlist>(g).swap(list);
143 noexcept(std::is_nothrow_move_assignable<SA>::value)
147 noexcept(std::is_nothrow_copy_assignable<SA>::value)
161 template <
template <
class>
class List>
162 List<typename GT::Node*>
perform (
const GT & g)
164 g.reset_counter_nodes();
166 List<typename GT::Node*>
list;
174 for (
auto it = g.get_node_it(); it.has_curr(); it.next_ne())
176 auto p = it.get_current_node_ne();
190 for (Itor<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
192 auto tgt = it.get_tgt_node_ne();
213 template <
template <
class>
class RankList =
DynList,
214 template <
class>
class List =
DynList>
215 RankList<List<typename GT::Node*>>
ranks(
const GT & g)
217 g.reset_counter_nodes();
220 for (
typename GT::Node_Iterator i(g); i.has_curr(); i.next_ne())
221 for (Itor<GT, SA> j(i.get_current_node_ne(), sa);
222 j.has_curr(); j.next_ne())
227 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next_ne())
229 auto p = it.get_current_node_ne();
234 RankList<List<typename GT::Node*>> ranks;
237 List<typename GT::Node*> rank;
246 for (Itor<GT, SA> it(p, sa); it.has_curr(); it.next_ne())
248 auto tgt = it.get_tgt_node_ne();
254 ranks.append(std::move(rank));
264 this->ranks<>(g).swap(
list);
269 this->ranks<DynList>(g).swap(
list);
275 this->perform<DynDlist>(g).swap(list);
281 # endif // TOPOLOGICAL_SORT_H Definition: topological_sort.H:47
Definition: tpl_graph.H:1225
void operator()(const GT &g, DynDlist< typename GT::Node *> &list)
Definition: topological_sort.H:118
Definition: topological_sort.H:136
bool is_empty() const noexcept
rioReturn true if this is empty
Definition: tpl_dynListQueue.H:112
Definition: tpl_dynDlist.H:51
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:327
RankList< List< typename GT::Node * > > ranks(const GT &g)
Definition: topological_sort.H:215
Definition: tpl_dynListQueue.H:50
#define NODE_COUNTER(p)
Definition: aleph-graph.H:311
void swap(DynListQueue &__q) noexcept
Swap this with __q in constant time.
Definition: tpl_dynListQueue.H:65
List< typename GT::Node * > perform(const GT &g)
Definition: topological_sort.H:96
Definition: tpl_graph.H:1063
Definition: tpl_graph.H:1796
#define NODE_BITS(p)
Definition: aleph-graph.H:305
T get()
Definition: tpl_dynListQueue.H:165
T & put(const T &data)
The type of element.
Definition: tpl_dynListQueue.H:125
List< typename GT::Node * > perform(const GT &g)
Definition: topological_sort.H:162