Skip to content

Commit 1bc2b97

Browse files
committed
Add get_predecessors()
1 parent c21dfd9 commit 1bc2b97

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/util/graph.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ class grapht
312312

313313
std::list<node_indext> topsort() const;
314314

315+
std::vector<node_indext> get_predecessors(const node_indext &n) const;
315316
std::vector<node_indext> get_successors(const node_indext &n) const;
316317
void output_dot(std::ostream &out) const;
317318
void for_each_successor(
@@ -934,6 +935,19 @@ void output_dot_generic(
934935
});
935936
}
936937

938+
template <class N>
939+
std::vector<typename grapht<N>::node_indext>
940+
grapht<N>::get_predecessors(const node_indext &n) const
941+
{
942+
std::vector<node_indext> result;
943+
std::transform(
944+
nodes[n].in.begin(),
945+
nodes[n].in.end(),
946+
std::back_inserter(result),
947+
[&](const std::pair<node_indext, edget> &edge) { return edge.first; });
948+
return result;
949+
}
950+
937951
template <class N>
938952
std::vector<typename grapht<N>::node_indext>
939953
grapht<N>::get_successors(const node_indext &n) const

0 commit comments

Comments
 (0)