C++ - 区间树的实现
有人知道 C++ 中任何好的间隔树
实现吗?
显然,模板驱动的东西,更好的boost
风格。
还有一个问题 - 如果有人测试过,基于 std::vector
的基本间隔树实现与排序是否可以击败通用间隔树(具有 O(lg) 操作)在实践中?
Does someone know any good interval tree
implementation in C++?
Obviously, something template-driven, better in boost
-like style.
And another question - if somebody tested, does a basic std::vector
-based interval tree implementation with sorting can beat the generic interval tree (with O(lg) operations) in practice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我有完全相同的需求。我找不到任何合适的(简单的、现代的、可移植的)实现,所以我使用了 python 实现由 Brent Pedersen 作为指导,并编写了一个简单的 C++ 版本。 IntervalTree 的行为类似于标准 STL 容器,但由于其简单性(例如没有迭代器)而有一些警告。你像这样使用它(“T”是任意类型):
并且你像这样查询它:
I had exactly the same need. I couldn't find any suitable (simple, modern, portable) implementations, so I used a python implementation by Brent Pedersen as a guide and wrote a barebones C++ version. The IntervalTree behaves like a standard STL container, with some caveats due to its simplicity (no iterators, for instance). You use it like this ("T" is an arbitrary type):
And you query it like this:
类似升压? 增强 ICL!
Boost Interval 容器库
Boost-like ? Boost ICL!
The Boost Interval Container Library
似乎是其中之一 NCBI C++ 工具包。
不过,对于它是否“好”,尚无定论(甚至是否是模板驱动的;我对 C++ 还有些陌生,所以我不完全确定它是好,但我对此也有怀疑)。
There appears to be one in the NCBI C++ Toolkit.
Jury's still out on whether it's "good," though (and even whether it's template-driven; I'm still somewhat new to C++, so I'm not entirely sure that it is, but I suspect as much).
我将区间树的简单实现上传到github: https://github.com/coolsoftware/ITree
看类itree 在 itree.h 中。
I uploaded simple implementation of Interval Tree to github: https://github.com/coolsoftware/ITree
Look class itree in itree.h.
如果您不介意将 ac# 实现转换为 c++,请转至 http://code.google.com/ p/intervaltree/.基于avl自平衡树。
if you don't mind translating a c# implementation to c++, goto http://code.google.com/p/intervaltree/ .based on an avl self balancing tree.