21#include <spdlog/spdlog.h>
22#include <absl/container/flat_hash_map.h>
23#include <absl/container/flat_hash_set.h>
25#define STRINGIFY(x) #x
26#define TOSTRING(x) STRINGIFY(x)
39 template<
class DataT,
class ChildT,
template<
typename...>
class ChildListT>
41 const absl::flat_hash_map<std::string, DataT> & data,
42 std::function<ChildListT<ChildT>(
const DataT &)> get_childreen,
43 std::function<std::string(
const ChildT &)> get_child_name)
45 std::vector<std::string> sorted;
46 absl::flat_hash_set<std::string> visited;
47 absl::flat_hash_set<std::string> on_stack;
49 std::function<void(
const std::string&)> visit = [&](
const std::string&
name) {
50 if (visited.contains(
name))
return;
51 if (on_stack.contains(
name)) {
52 spdlog::error(std::format(
"Cycle detected involving : {}",
name));
53 throw std::runtime_error(
"Cyclic dependency");
56 on_stack.insert(
name);
58 auto it = data.find(
name);
59 if (it == data.end()) {
60 spdlog::warn(std::format(
"Missing dependency: {}",
name));
65 std::string child_name;
66 for (
const auto& child : get_childreen(it->second))
68 child_name = get_child_name(child);
69 if(child_name.empty())
continue;
75 sorted.push_back(
name);
79 for (
const auto& [
name, _] : data) {
88 std::string
toLower(std::string value);
94 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:17
std::string toLower(std::string value)
Definition utils.cpp:83
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:40
void logException(const std::exception_ptr &exception_ptr, const std::string_view context)
Definition utils.cpp:96
bool likelyNetworkPath(const std::filesystem::path &path)
Definition utils.cpp:89
std::optional< std::string > trimAsciiWhitespace(std::string_view value)
Definition utils.cpp:57
bool equalsIgnoreCase(const std::string &a, const std::string &b)
Definition utils.cpp:50
std::int64_t nowMs()
Definition utils.cpp:43
constexpr bool always_false
Definition utils.hpp:31
std::string loadBuildTimestamp(const std::filesystem::path &path)
Definition utils.cpp:8