如何查看所有数据结构依赖性是否已解决?

发布于 2024-12-28 11:07:54 字数 531 浏览 3 评论 0原文

让我们想象一下演示情况,我们有如此简单的结构

struct service
{
 std::string name
 std::set<std::string> depends_on_service_name;
};

我们有一些原始数据(文本文件、io 流或什么 ewer)进入我们的解析器,将其转换为服务结构实例并将它们放入 std::map; services 我们需要一种方法来检查所有地图项是否都已解决depends_on_service_name(这意味着每个 services[item].name 在地图中应有 services[item].name代码>服务[other_item].depends_on_service_name)。是否有任何标准方法可以在手动 for_each 的提升中检查此类内容是每次 parser 将新项目附加到地图时的方法?

Lets imagine demo situation that we have such simple structure

struct service
{
 std::string name
 std::set<std::string> depends_on_service_name;
};

We have some raw data (text file, io stream or what ewer) coming into our parser that turns it into service struct instances and puts them into std::map<service> services we need a way to chack if all map items have all there depends_on_service_name resolved (meaning there shall be services[item].name in map for each service[other_item].depends_on_service_name). Is there any standart way to check for such things in boost of manual for_each is the way to go each time parser appends new item(s) into map?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

护你周全 2025-01-04 11:07:54

这里的“方法”是在输入验证和抽象期间解决这个问题。您正在使用服务映射来表示有向(可能是非循环)图,并且您应该这样表示它(例如使用Boost.Graph),而不是使用集合和映射来滚动您自己的图结构。当你构建这个显式的图结构时,缺失的服务自然会被发现。

The "way to go" here is to solve this problem during input verification and abstraction. You are representing a directed (probably acyclic) graph with the service map, and you should represent it as such (e.g. using Boost.Graph) instead of rolling your own graph structure with sets and maps. While you are building this explicit graph structure, missing services will naturally be discovered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文