ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
IntervalTree.h File Reference

The interval tree as an augmented map, beyond the book: a multiset of closed intervals \( [ a , b ] \) of a totally ordered type, kept in a map [see JoinTree.h] whose keys are the pairs \( ( a , b ) \) in lexicographic order, whose values are their multiplicities, and whose augmentation is the largest right end of the subtree, \( \mathit{aug}( u ) = \max \{ b : ( a , b ) \in T_u \} \), the monoid of the maximum on the right ends, whose identity is no interval. More...

#include "ADS/Contract.h"
#include "ADS/parallel/Executor.h"
#include "ADS/tree/JoinTree.h"
#include <concepts>
#include <cstddef>
#include <optional>
#include <utility>
#include <vector>
#include "ADS/geometry/impl/IntervalTree.tpp"

Go to the source code of this file.

Classes

class  ADS::IntervalTree< T >
 a multiset of closed intervals of T with stabbing queries More...
struct  ADS::IntervalTree< T >::MaxEnd
 the augmentation: the largest right end, nothing for no interval More...

Namespaces

namespace  ADS

Detailed description

The interval tree as an augmented map, beyond the book: a multiset of closed intervals \( [ a , b ] \) of a totally ordered type, kept in a map [see JoinTree.h] whose keys are the pairs \( ( a , b ) \) in lexicographic order, whose values are their multiplicities, and whose augmentation is the largest right end of the subtree, \( \mathit{aug}( u ) = \max \{ b : ( a , b ) \in T_u \} \), the monoid of the maximum on the right ends, whose identity is no interval.

The map is balanced by weight, and the augmentation is kept by its join alone, as for every augmented map.

A stabbing query asks for the intervals that contain a point \( x \). The intervals with \( a \le x \) are the keys up to \( ( x , \infty ) \), a prefix of the order, and \( x \) is in one of them if and only if the largest right end of the prefix is at least \( x \); stabbed( x ) reads that maximum on the path that separates the prefix from the rest, combining the augmented values of the left subtrees that the path leaves behind, in \( O( \log n ) \) time. stab( x , f ) reports them all by a visit that enters a subtree only if its augmented value is at least \( x \) and, for a node with \( a > x \), does not enter its right subtree: each node visited either is reported, or lies on one of the paths that lead to the reported ones, so that the visit costs \( O( \min( n , ( k + 1 ) \log n ) ) \) for \( k \) intervals reported. The intervals are inserted and removed one at a time in \( O( \log n ) \), and the constructor takes them all by multiInsert() [see JoinAlgorithms.h], on the threads of an executor if given one.

The contracts [see Contract.h]: \( a \le b \) for each interval; the invariant is that of the map, the largest right ends included. The operations are defined in IntervalTree.tpp.

See also
H. Edelsbrunner, Dynamic data structures for orthogonal intersection queries, Report F59, Institut für Informationsverarbeitung, Technische Universität Graz, 1980
E. M. McCreight, Priority search trees, SIAM Journal on Computing 14(2), 257-276, 1985, doi:10.1137/0214021
T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein, Introduction to Algorithms, 3rd ed., MIT Press, 2009, section 14.3 (the interval tree as an augmented search tree)
Y. Sun, G. E. Blelloch, Parallel range, segment and rectangle queries with augmented maps, Proceedings of the 21st Workshop on Algorithm Engineering and Experiments (ALENEX), 159-173, 2019, doi:10.1137/1.9781611975499.13
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa