ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RangeTree.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File RangeTree.h ----------------------------*/
3/*--------------------------------------------------------------------------*/
60/*--------------------------------------------------------------------------*/
61/*----------------------------- DEFINITIONS --------------------------------*/
62/*--------------------------------------------------------------------------*/
63
64#ifndef __ADS_RangeTree
65 #define __ADS_RangeTree
66/* self-identification: #endif constant */
67
68/*--------------------------------------------------------------------------*/
69/*------------------------------ INCLUDES ----------------------------------*/
70/*--------------------------------------------------------------------------*/
71
72#include "ADS/Contract.h"
74#include "ADS/tree/JoinTree.h"
75
76#include <algorithm>
77#include <concepts>
78#include <cstddef>
79#include <limits>
80#include <utility>
81#include <vector>
82
83/*--------------------------------------------------------------------------*/
84/*--------------------------- NAMESPACE ------------------------------------*/
85/*--------------------------------------------------------------------------*/
86
87namespace ADS
88{
89
90/*--------------------------------------------------------------------------*/
91/*--------------------------- CLASS RangeTree ------------------------------*/
92/*--------------------------------------------------------------------------*/
93
96template< std::totally_ordered T >
97 requires std::numeric_limits< T >::is_specialized
99{
100
101/*--------------------------------------------------------------------------*/
102 public:
103 using Point = std::pair< T , T >;
104
107 {
109 using Value = std::vector< T >;
111 static Value identity( void ) { return( Value() ); }
114 static Value from( const Point & p , const std::size_t & c ) {
115 return( Value( c , p.second ) );
116 }
117
119 static Value combine( const Value & a , const Value & b ) {
120 Value m( a.size() + b.size() );
121 std::merge( a.begin() , a.end() , b.begin() , b.end() , m.begin() );
122 return( m );
123 }
124 };
125
127 RangeTree( void ) = default;
128
145 explicit RangeTree( std::vector< Point > P );
146
148 template< Executor E >
149 RangeTree( E & ex , std::vector< Point > P );
150
163 void insert( const T & x , const T & y );
164
178 void remove( const T & x , const T & y );
179
181 [[nodiscard]] std::size_t size( void ) const { return( f_n ); }
182
203 [[nodiscard]] std::size_t count( const T & x1 , const T & x2 , const T & y1 ,
204 const T & y2 ) const;
205
206/*--------------------------------------------------------------------------*/
207 private:
209
211 static std::vector< std::pair< Point , std::size_t > >
212 counted( std::vector< Point > & P );
213
214 Map f_map;
215 std::size_t f_n = 0;
216
217 }; // end( class RangeTree )
218
219/*--------------------------------------------------------------------------*/
220
221} // end( namespace ADS )
222
223/*--------------------------------------------------------------------------*/
224/*-------------------------- IMPLEMENTATION --------------------------------*/
225/*--------------------------------------------------------------------------*/
226
227#include "ADS/geometry/impl/RangeTree.tpp"
228
229/*--------------------------------------------------------------------------*/
230
231#endif /* RangeTree.h included */
232
233/*--------------------------------------------------------------------------*/
234/*-------------------------- End File RangeTree.h --------------------------*/
235/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
The binary search trees balanced by join alone, and the augmented maps, beyond the book: JoinTree< K ...
a DICTIONARY on a binary search tree balanced by the join of B alone, augmented by G,...
Definition JoinTree.h:291
std::pair< T, T > Point
Definition RangeTree.h:103
void remove(const T &x, const T &y)
one copy less of , if there,
RangeTree(std::vector< Point > P)
the points of , sorted, counted and inserted by multiInsert(),
RangeTree(void)=default
no point
std::size_t count(const T &x1, const T &x2, const T &y1, const T &y2) const
the points of , with their copies,
void insert(const T &x, const T &y)
one more copy of , , since the ordinates of all its ancestors are merged again
std::size_t size(void) const
the points, with their copies
Definition RangeTree.h:181
RangeTree(E &ex, std::vector< Point > P)
the points of , as above, on the threads of ex
Definition ADT.h:96
the augmentation: the sorted ordinates, with their copies
Definition RangeTree.h:107
static Value identity(void)
the empty sequence, the identity of the merge
Definition RangeTree.h:111
static Value combine(const Value &a, const Value &b)
the merge of the sorted sequences and ,
Definition RangeTree.h:119
std::vector< T > Value
the ordinates of a subtree, sorted
Definition RangeTree.h:109
static Value from(const Point &p, const std::size_t &c)
copies of the ordinate of the point
Definition RangeTree.h:114