mirror of https://github.com/microsoft/vcpkg.git
toposort: use lambda to obtain the neighbours of a vertex
This commit is contained in:
parent
a6f895ac8c
commit
612d941afc
|
|
@ -20,20 +20,23 @@ namespace vcpkg::Graphs
|
|||
template <class V>
|
||||
class Graph
|
||||
{
|
||||
template <class Func>
|
||||
static void find_topological_sort_internal(V vertex,
|
||||
ExplorationStatus& status,
|
||||
const std::unordered_map<V, std::unordered_set<V>>& adjacency_list,
|
||||
const Func adjacency_list_provider,
|
||||
std::unordered_map<V, ExplorationStatus>& exploration_status,
|
||||
std::vector<V>& sorted)
|
||||
{
|
||||
status = ExplorationStatus::PARTIALLY_EXPLORED;
|
||||
|
||||
for (V neighbour : adjacency_list.at(vertex))
|
||||
auto neighbours = adjacency_list_provider(vertex);
|
||||
|
||||
for (V neighbour : neighbours)
|
||||
{
|
||||
ExplorationStatus& neighbour_status = exploration_status[neighbour];
|
||||
if (neighbour_status == ExplorationStatus::NOT_EXPLORED)
|
||||
{
|
||||
find_topological_sort_internal(neighbour, neighbour_status, adjacency_list, exploration_status, sorted);
|
||||
find_topological_sort_internal(neighbour, neighbour_status, adjacency_list_provider, exploration_status, sorted);
|
||||
}
|
||||
else if (neighbour_status == ExplorationStatus::PARTIALLY_EXPLORED)
|
||||
{
|
||||
|
|
@ -85,7 +88,11 @@ namespace vcpkg::Graphs
|
|||
ExplorationStatus& status = exploration_status[vertex];
|
||||
if (status == ExplorationStatus::NOT_EXPLORED)
|
||||
{
|
||||
find_topological_sort_internal(vertex, status, this->vertices, exploration_status, sorted);
|
||||
find_topological_sort_internal(vertex,
|
||||
status,
|
||||
[this](const V& v) { return this->vertices.at(v); },
|
||||
exploration_status,
|
||||
sorted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue