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

The two-dimensional range tree of Bentley as an augmented map, beyond the book: a multiset of points \( ( x , y ) \) of the plane, kept in a map [see JoinTree.h] whose keys are the points in lexicographic order, whose values are their multiplicities, and whose augmentation is the sorted sequence of the ordinates of the subtree, with their copies: the monoid of the sorted sequences under the merge, whose identity is the empty sequence. More...

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

Go to the source code of this file.

Classes

class  ADS::RangeTree< T >
 a multiset of points of \( T \times T \), with the count of the points of a rectangle More...
struct  ADS::RangeTree< T >::Ordinates
 the augmentation: the sorted ordinates, with their copies More...

Namespaces

namespace  ADS

Detailed description

The two-dimensional range tree of Bentley as an augmented map, beyond the book: a multiset of points \( ( x , y ) \) of the plane, kept in a map [see JoinTree.h] whose keys are the points in lexicographic order, whose values are their multiplicities, and whose augmentation is the sorted sequence of the ordinates of the subtree, with their copies: the monoid of the sorted sequences under the merge, whose identity is the empty sequence.

The map is balanced by weight; the merge is not of constant cost, and a subtree of \( s \) points keeps \( s \) ordinates, so that the structure takes \( O( n \log n ) \) space, as the range tree does.

count( x1 , x2 , y1 , y2 ) counts the points of the rectangle \( [ x_1 , x_2 ] \times [ y_1 , y_2 ] \): the points with \( x_1 \le x \le x_2 \) are the keys between \( ( x_1 , -\infty ) \) and \( ( x_2 , +\infty ) \), a range of the order, which the map covers by \( O( \log n ) \) pieces [see JoinTree::augVisit()], whole subtrees and single points; in each piece two binary searches on its sorted ordinates count those in \( [ y_1 , y_2 ] \), whence \( O( \log^2 n ) \) time. The fractional cascading of Lueker and of Willard would bring it to \( O( \log n ) \), at the price of the pointers between the sequences, which a merge would have to rebuild.

The points are given all at once to the constructor, which inserts them by multiInsert() [see JoinAlgorithms.h], on the threads of an executor if given one: the tree is built by joins of balanced halves, and each join merges the sequences of its two sides, \( O( n \log n ) \) work in all. A point inserted or removed afterwards costs \( O( n ) \), since the sequences of all its ancestors change, the root's included: the dynamic range tree that the augmented maps of Sun and Blelloch keep in \( O( \log^2 n ) \) per update shares the inner trees between the versions (persistence), which these maps, destructive, do not.

The contracts [see Contract.h]: \( x_1 \le x_2 \) and \( y_1 \le y_2 \) are not required (an empty rectangle counts 0); the invariant is that of the map, the sorted ordinates included. The operations are defined in RangeTree.tpp.

See also
J. L. Bentley, Decomposable searching problems, Information Processing Letters 8(5), 244-251, 1979, doi:10.1016/0020-0190(79)90117-0
J. L. Bentley, Multidimensional divide-and-conquer, Communications of the ACM 23(4), 214-229, 1980, doi:10.1145/358841.358850
G. S. Lueker, A data structure for orthogonal range queries, 19th Annual Symposium on Foundations of Computer Science (FOCS), 28-34, 1978, doi:10.1109/SFCS.1978.1
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