|
ADS
Algorithms and Data Structures
|
a multiset of points of \( T \times T \), with the count of the points of a rectangle More...
#include <ADS/geometry/RangeTree.h>
Classes | |
| struct | Ordinates |
| the augmentation: the sorted ordinates, with their copies More... | |
Public types | |
| using | Point = std::pair< T , T > |
| \( ( x , y ) \) | |
Public member functions | |
| RangeTree (void)=default | |
| no point | |
| RangeTree (std::vector< Point > P) | |
| the points of \( P \), sorted, counted and inserted by multiInsert(), \( O( n \log n ) \) | |
| template<Executor E> | |
| RangeTree (E &ex, std::vector< Point > P) | |
| the points of \( P \), as above, on the threads of ex | |
| void | insert (const T &x, const T &y) |
| one more copy of \( ( x , y ) \), \( O( n ) \), since the ordinates of all its ancestors are merged again | |
| void | remove (const T &x, const T &y) |
| one copy less of \( ( x , y ) \), if there, \( O( n ) \) | |
| std::size_t | size (void) const |
| the points, with their copies | |
| std::size_t | count (const T &x1, const T &x2, const T &y1, const T &y2) const |
| the points of \( [ x_1 , x_2 ] \times [ y_1 , y_2 ] \), with their copies, \( O( \log^2 n ) \) | |
a multiset of points of \( T \times T \), with the count of the points of a rectangle
| using ADS::RangeTree< T >::Point = std::pair< T , T > |
\( ( x , y ) \)
|
default |
no point
|
explicit |
the points of \( P \), sorted, counted and inserted by multiInsert(), \( O( n \log n ) \)
In pseudocode (the construction of the augmented maps of Sun and Blelloch, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{RangeTree}( P ) \cr 2 & \quad \text{sort } P \text{ by } ( x , y ) \cr 3 & \quad B \gets \text{the distinct points of } P \text{, each with its } \text{copies} \cr 4 & \quad \mathrm{multiInsert}( T , B )\quad \triangleright\ \text{each } \text{join merges the ordinates of its sides} \cr 5 & \quad n \gets |P| \end{array}} \]
| ADS::RangeTree< T >::RangeTree | ( | E & | ex, |
| std::vector< Point > | P ) |
the points of \( P \), as above, on the threads of ex
|
nodiscard |
the points of \( [ x_1 , x_2 ] \times [ y_1 , y_2 ] \), with their copies, \( O( \log^2 n ) \)
In pseudocode (the range tree of Bentley on an augmented map, beyond the book), \( Y \) the sorted ordinates of a piece:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{count}( x_1 , x_2 , y_1 , y_2 ) \cr 2 & \quad \textbf{if}\ x_2 < x_1\ \textbf{or}\ y_2 < y_1\ \textbf{then return}\ 0 \cr 3 & \quad c \gets 0 \cr 4 & \quad \textbf{foreach}\ \text{piece of the keys from } ( x_1 , -\infty ) \text{ to } ( x_2 , +\infty )\ \textbf{do} \cr 5 & \qquad c \gets c + \mathrm{upperBound}( Y , y_2 ) - \mathrm{lowerBound}( Y , y_1 ) \cr 6 & \quad \textbf{return}\ c \end{array}} \]
where the pieces, \( O( \log n ) \) subtrees and single points, are those of JoinTree::augVisit().
| void ADS::RangeTree< T >::insert | ( | const T & | x, |
| const T & | y ) |
one more copy of \( ( x , y ) \), \( O( n ) \), since the ordinates of all its ancestors are merged again
In pseudocode:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( x , y ) \cr 2 & \quad c \gets \text{the copies of } ( x , y ) \text{ in } T \text{, 0 if none} \cr 3 & \quad \mathrm{insert}( T , ( x , y ) , c + 1 );\ n \gets n + 1 \end{array}} \]
| void ADS::RangeTree< T >::remove | ( | const T & | x, |
| const T & | y ) |
one copy less of \( ( x , y ) \), if there, \( O( n ) \)
In pseudocode:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{remove}( x , y ) \cr 2 & \quad c \gets \text{the copies of } ( x , y ) \text{ in } T \cr 3 & \quad \textbf{if}\ c = \textbf{nil}\ \textbf{then return} \cr 4 & \quad \textbf{if}\ c = 1\ \textbf{then}\ \mathrm{remove}( T , ( x , y ) )\ \textbf{else}\ \mathrm{insert}( T , ( x , y ) , c - 1 ) \cr 5 & \quad n \gets n - 1 \end{array}} \]
|
inlinenodiscard |
the points, with their copies