ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::RangeTree< T > Class Template Reference

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

Detailed description

template<std::totally_ordered T>
requires std::numeric_limits< T >::is_specialized
class ADS::RangeTree< T >

a multiset of points of \( T \times T \), with the count of the points of a rectangle

Member typedef documentation

◆ Point

template<std::totally_ordered T>
using ADS::RangeTree< T >::Point = std::pair< T , T >

\( ( x , y ) \)

Constructor and destructor documentation

◆ RangeTree() [1/3]

template<std::totally_ordered T>
ADS::RangeTree< T >::RangeTree ( void )
default

no point

◆ RangeTree() [2/3]

template<std::totally_ordered T>
ADS::RangeTree< T >::RangeTree ( std::vector< Point > P)
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}} \]

◆ RangeTree() [3/3]

template<std::totally_ordered T>
template<Executor E>
ADS::RangeTree< T >::RangeTree ( E & ex,
std::vector< Point > P )

the points of \( P \), as above, on the threads of ex

Member function documentation

◆ count()

template<std::totally_ordered T>
std::size_t ADS::RangeTree< T >::count ( const T & x1,
const T & x2,
const T & y1,
const T & y2 ) const
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().

◆ insert()

template<std::totally_ordered T>
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}} \]

◆ remove()

template<std::totally_ordered T>
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}} \]

◆ size()

template<std::totally_ordered T>
std::size_t ADS::RangeTree< T >::size ( void ) const
inlinenodiscard

the points, with their copies


The documentation for this class was generated from the following file: