From 598b29640de44271c711106b5d1a19d572fa8e17 Mon Sep 17 00:00:00 2001 From: Christian Howe Date: Tue, 19 Sep 2023 19:56:55 -0700 Subject: [PATCH] entity: expose organizer's adjacency matrix --- src/entt/entity/organizer.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/entt/entity/organizer.hpp b/src/entt/entity/organizer.hpp index e4c3139b34..567fbe115f 100644 --- a/src/entt/entity/organizer.hpp +++ b/src/entt/entity/organizer.hpp @@ -397,10 +397,25 @@ class basic_organizer final { * @return The adjacency list of the task graph. */ std::vector graph() { + return build_list(build_matrix()); + } + + /** + * @brief Builds an adjacency matrix for the current content. + * @return The adjacency matrix for the task graph + */ + entt::adjacency_matrix build_matrix() { + return builder.graph(); + } + + /** + * @brief Builds an adjacency list for the given adjacency matrix. + * @param matrix The adjacency matrix for the task graph + * @return The adjacency list for the task graph + */ + std::vector build_list(const entt::adjacency_matrix &matrix) { std::vector adjacency_list{}; adjacency_list.reserve(vertices.size()); - auto adjacency_matrix = builder.graph(); - for(auto curr: adjacency_matrix.vertices()) { const auto iterable = adjacency_matrix.in_edges(curr); std::vector successors{}; @@ -421,7 +436,8 @@ class basic_organizer final { } /*! @brief Erases all elements from a container. */ - void clear() { + void + clear() { builder.clear(); vertices.clear(); }