有没有像 Loki 的 AssocVector 那样实现但具有 Boost 的 Bimap 功能的可用工具?

发布于 2024-10-02 10:26:33 字数 181 浏览 0 评论 0原文

我想知道是否有人知道任何库代码具有 Loki 的 AssocVector 提供的性能特征(元素的引用位置,与映射相比每个元素的内存开销更低),但具有 Boost 的 BiMap 功能(能够从关系的双方)?

或者使用 std::pairs 的排序 std::vector 并添加使用该对的任一元素作为键来查找向量的功能是前进的方向吗?

I wonder if anyone is aware of any library code that has the performance characteristics provided by Loki's AssocVector (Locality of reference of the elements, lower per-element memory overhead compared to a map) but with Boost's BiMap functionality (able to query the map from both sides of the relation)?

Or would using a sorted std::vector of std::pairs and adding functionality to lookup the vector using either element of the pair as the key be the way forward?

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

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

发布评论

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

评论(1

森林散布 2024-10-09 10:26:33

这实际上取决于您想快速做什么。 Loki::AssocVector 具有 O(n) 插入和删除操作,而 boost::bimap 当与哈希一起使用时具有 O(1)表。如果您可以在数据结构的一个“视图”上接受 O(n) 次操作,而在另一个“视图”上接受 O(lg n) 次操作,那么您提出的解决方案将可以正常工作并占用很少的内存。如果一个视图上的操作占主导地位,那么对于小型数据集来说,它可能会非常快。

您还可以考虑使用 Boost.Intrusiveboost::bimap 带有专门的分配器。

It really depends on what you want to do fast. Loki::AssocVector has O(n) insert and delete, while boost::bimap has O(1) when you use it with hash tables. If you can live with O(n) operations on one "view" of your data structure and O(lg n) on the other, then your proposed solution will work fine and take little memory. It may be very fast for small data sets, if operations on one view dominate.

You may also consider using Boost.Intrusive or boost::bimap with specialized allocators.

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