19#include <spdlog/spdlog.h>
20#include <absl/container/flat_hash_map.h>
21#include <absl/container/flat_hash_set.h>
23#define STRINGIFY(x) #x
24#define TOSTRING(x) STRINGIFY(x)
35 template<
class DataT,
class ChildT,
template<
typename...>
class ChildListT>
37 const absl::flat_hash_map<std::string, DataT> & data,
38 std::function<ChildListT<ChildT>(
const DataT &)> get_childreen,
39 std::function<std::string(
const ChildT &)> get_child_name)
41 std::vector<std::string> sorted;
42 absl::flat_hash_set<std::string> visited;
43 absl::flat_hash_set<std::string> on_stack;
45 std::function<void(
const std::string&)> visit = [&](
const std::string&
name) {
46 if (visited.contains(
name))
return;
47 if (on_stack.contains(
name)) {
48 spdlog::error(std::format(
"Cycle detected involving : {}",
name));
49 throw std::runtime_error(
"Cyclic dependency");
52 on_stack.insert(
name);
54 auto it = data.find(
name);
55 if (it == data.end()) {
56 spdlog::warn(std::format(
"Missing dependency: {}",
name));
61 std::string child_name;
62 for (
const auto& child : get_childreen(it->second))
64 child_name = get_child_name(child);
65 if(child_name.empty())
continue;
71 sorted.push_back(
name);
75 for (
const auto& [
name, _] : data) {
84 void logException(
const std::exception_ptr & exception_ptr,
const std::string_view context);
std::string name
Definition ingestion.cpp:29
std::string currentTimestamp()
Definition utils.cpp:14
std::vector< std::string > topologicalSort(const absl::flat_hash_map< std::string, DataT > &data, std::function< ChildListT< ChildT >(const DataT &)> get_childreen, std::function< std::string(const ChildT &)> get_child_name)
Definition utils.hpp:36
void logException(const std::exception_ptr &exception_ptr, const std::string_view context)
Definition utils.cpp:48
bool isImportTraceEnabled()
Definition utils.cpp:70
bool equalsIgnoreCase(const std::string &a, const std::string &b)
Definition utils.cpp:40
constexpr bool always_false
Definition utils.hpp:29
std::string loadBuildTimestamp(const std::filesystem::path &path)
Definition utils.cpp:5