用于快速时间间隔查找的数据结构 [英] Data structure for quick time interval look up

查看:20
本文介绍了用于快速时间间隔查找的数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组时间间隔In = (an, bn).我需要在给定时间 t 的地方运行大量查找,并且需要快速返回包含 t 的间隔,例如,那些间隔 a <= t <= bn.

I have a set of time intervals In = (an, bn). I need to run lots of look ups where I'm given a time t and need to quickly return the intervals that contain t, e.g., those intervals such that an <= t <= bn.

对此有什么好的数据结构或算法?

What is a good data structure or algorithm for this?

如果重要的话,在我的例子中 anbn 是整数.

If it matters, in my case the an and bn are integers.

推荐答案

您正在寻找的是 Interval树(这是一种范围树).

What you are looking for is an Interval Tree (which is a type of Range Tree).

这些与其他树结构(例如,RB 树)一样具有对数查找时间,因此您应该会看到与使用 Java TreeMap 或 STL 映射等类似的性能.

These have logarithmic lookup time like other tree structures (e.g., RB trees), so you should see comparable performance to using something like a Java TreeMap or an STL map.

  • Code for Red-black trees and interval trees from MIT
  • There is a C++ implementation in the CGAL Library.
  • Here's a C# Implementation

这篇关于用于快速时间间隔查找的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆