Boost Graph Library:添加具有相同标识的顶点
如何使用 BGL 表示文件路径? 考虑这样的路径: root/a/a/a/a/a
相应的图形将是 'root'->'a'->'a'->...
是否可能添加共享相同名称的多个顶点? 找不到明确的答案。
How can I represent file path using BGL?
Consider path like: root/a/a/a/a/a
Corresponding graph would be 'root'->'a'->'a'->...
Is it possible to add multiple vertices sharing the same name?
Could not find clear answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然。只要名称不是标识符(身份意味着唯一)。
文件系统路径的整体思想是路径是唯一的。因此,您可能想要的是将唯一名称作为节点的路径,并在显示时选择要显示路径的哪一部分。
对于使用内部顶点名称的优雅演示1:
现在您可以向图形添加任何路径:
我们必须告诉 BGL 使用
std::identity
从fs 获取内部名称: :path
:现在,演示:
使用顶点 ID 进行打印:
使用唯一节点路径进行打印:
仅使用本地名称进行打印:
现场演示
Live On Compiler Explorer
打印(在我的机器上,其中
test.cpp
存在于/home/sehe/Projects/stackoverflow
中):额外的
Graphviz 输出:
给出 此图可视化
¹ 参见例如 如何配置boost::图使用我自己的(稳定)索引作为顶点?
Sure. As long as the name is not the identifier (identity implies unique).
The whole idea of filesystem paths is that the paths are unique. So, what you would probably want is to have the unique name be the path to the node, and when displaying, choose what part of the path you want to display.
For an elegant demonstration using internal vertex names¹:
Now you can add any path to the graph:
We'll have to tell BGL to use
std::identity
to get the internal name fromfs::path
:Now, demonstrating:
To print using the vertex ids:
To print using the unique node paths:
To print using only the local names:
Live Demo
Live On Compiler Explorer
Prints (on my machine, where
test.cpp
exists in/home/sehe/Projects/stackoverflow
):BONUS
Graphviz output:
Gives this graphviz
¹ see e.g. How to configure boost::graph to use my own (stable) index for vertices?