C++ - 区间树的实现

发布于 2024-10-26 13:31:17 字数 197 浏览 1 评论 0原文

有人知道 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 技术交流群。

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

发布评论

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

评论(5

疑心病 2024-11-02 13:31:17

我有完全相同的需求。我找不到任何合适的(简单的、现代的、可移植的)实现,所以我使用了 python 实现由 Brent Pedersen 作为指导,并编写了一个简单的 C++ 版本。 IntervalTree 的行为类似于标准 STL 容器,但由于其简单性(例如没有迭代器)而有一些警告。你像这样使用它(“T”是任意类型):

vector<Interval<T> > intervals;
// ... make intervals!
IntervalTree<T> tree(intervals);

并且你像这样查询它:

vector<Interval<T> > results;
tree.findContained(start, stop, results);
// results now contains Intervals which are fully contained in the query interval
results.clear();
tree.findOverlapping(start, stop, results);
// results now contains Intervals which overlap the query interval

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):

vector<Interval<T> > intervals;
// ... make intervals!
IntervalTree<T> tree(intervals);

And you query it like this:

vector<Interval<T> > results;
tree.findContained(start, stop, results);
// results now contains Intervals which are fully contained in the query interval
results.clear();
tree.findOverlapping(start, stop, results);
// results now contains Intervals which overlap the query interval
梦年海沫深 2024-11-02 13:31:17

类似升压? 增强 ICL

Boost Interval 容器库

Boost-like ? Boost ICL!

The Boost Interval Container Library

夜夜流光相皎洁 2024-11-02 13:31:17

似乎是其中之一 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).

酒几许 2024-11-02 13:31:17

我将区间树的简单实现上传到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.

未蓝澄海的烟 2024-11-02 13:31:17

如果您不介意将 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.

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