ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SortedIntersection.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------- File SortedIntersection.h ------------------------*/
3/*--------------------------------------------------------------------------*/
101/*--------------------------------------------------------------------------*/
102/*----------------------------- DEFINITIONS --------------------------------*/
103/*--------------------------------------------------------------------------*/
104
105#ifndef __ADS_SortedIntersection
106 #define __ADS_SortedIntersection
107/* self-identification: #endif constant */
108
109/*--------------------------------------------------------------------------*/
110/*------------------------------ INCLUDES ----------------------------------*/
111/*--------------------------------------------------------------------------*/
112
113#include "ADS/Contract.h"
116#include "ADS/sort/Sorted.h"
117
118#include <algorithm>
119#include <cstddef>
120#include <cstdint>
121#include <functional>
122#include <utility>
123#include <vector>
124
125/*--------------------------------------------------------------------------*/
126/*--------------------------- NAMESPACE ------------------------------------*/
127/*--------------------------------------------------------------------------*/
128
129namespace ADS
130{
131
150template< class T , class C = std::less<> >
151std::vector< T > intersectMerge( const std::vector< T > & A ,
152 const std::vector< T > & B , C less = C() );
153
173template< class T , class C = std::less<> >
174std::vector< T > intersectBinarySearch( const std::vector< T > & A ,
175 const std::vector< T > & B ,
176 C less = C() );
177
204template< class T , class C = std::less<> >
205std::vector< T > intersectMutualPartition( const std::vector< T > & A ,
206 const std::vector< T > & B ,
207 C less = C() );
208
231template< class T , class C = std::less<> >
232std::vector< T > intersectDoubling( const std::vector< T > & A ,
233 const std::vector< T > & B ,
234 C less = C() );
235
262template< class T , class C = std::less<> >
263std::vector< T > intersectTwoLevel( const std::vector< T > & A ,
264 const std::vector< T > & B ,
265 std::size_t L ,
266 C less = C() );
267
271template< class T >
272void twoLevelHeaders( const DiskFile< T > & A , std::size_t L ,
273 DiskFile< T > & H );
274
293template< class T , class C = std::less<> >
295 const DiskFile< T > & B ,
296 DiskFile< T > & out , C less = C() );
297
322template< class T , class C = std::less<> >
324 const DiskFile< T > & H , std::size_t L ,
325 const DiskFile< T > & B , DiskFile< T > & out ,
326 C less = C() );
327
328/*--------------------------------------------------------------------------*/
329/*------------------------- CLASS PermutedBuckets --------------------------*/
330/*--------------------------------------------------------------------------*/
331
336{
337
338/*--------------------------------------------------------------------------*/
339 public:
355 PermutedBuckets( const std::vector< std::uint64_t > & A , unsigned w ,
356 std::size_t L , std::uint64_t a , std::uint64_t c );
357
359 [[nodiscard]] std::size_t size( void ) const;
360
362 [[nodiscard]] std::size_t buckets( void ) const;
363
390 [[nodiscard]] std::vector< std::uint64_t >
391 intersect( const PermutedBuckets & other ,
392 std::size_t * scanned = nullptr ) const;
393
395 [[nodiscard]] std::vector< std::uint64_t > values( void ) const;
396
397/*--------------------------------------------------------------------------*/
398 private:
400 [[nodiscard]] std::uint64_t mask( void ) const;
401
403 [[nodiscard]] std::uint64_t permute( std::uint64_t x ) const;
404
406 [[nodiscard]] std::uint64_t invert( std::uint64_t y ) const;
407
408 unsigned f_w;
409 unsigned f_ell;
410 std::uint64_t f_a , f_c;
411 std::uint64_t f_ainv;
412 std::vector< std::uint64_t > f_img;
413 std::vector< std::size_t > f_off;
414
415 }; // end( class PermutedBuckets )
416
417/*--------------------------------------------------------------------------*/
418
419} // end( namespace ADS )
420
421/*--------------------------------------------------------------------------*/
422/*-------------------------- IMPLEMENTATION --------------------------------*/
423/*--------------------------------------------------------------------------*/
424
425#include "ADS/set/impl/SortedIntersection.tpp"
426
427/*--------------------------------------------------------------------------*/
428
429#endif /* SortedIntersection.h included */
430
431/*--------------------------------------------------------------------------*/
432/*---------------------- End File SortedIntersection.h ---------------------*/
433/*--------------------------------------------------------------------------*/
The binary search of section 1.2 in a sorted vector : is compared with the middle item of the part ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
The two-level memory model of Aggarwal and Vitter, simulated so that the algorithms of the external m...
a file of items on the disk of the model, in blocks of items
Definition TwoLevelMemory.h:199
std::vector< std::uint64_t > intersect(const PermutedBuckets &other, std::size_t *scanned=nullptr) const
the values common to the two sets, sorted; the items of the two sets looked at go to *scanned,...
PermutedBuckets(const std::vector< std::uint64_t > &A, unsigned w, std::size_t L, std::uint64_t a, std::uint64_t c)
the values of , distinct, in any order
std::size_t buckets(void) const
the buckets,
std::size_t size(void) const
the items
std::vector< std::uint64_t > values(void) const
the values of the set, sorted, by inverting the permutation
std::vector< T > intersectDoubling(const std::vector< T > &A, const std::vector< T > &B, C less=C())
the items common to and , by doubling searches
std::vector< T > intersectMutualPartition(const std::vector< T > &A, const std::vector< T > &B, C less=C())
the items common to and , by mutual partitions
std::vector< T > intersectBinarySearch(const std::vector< T > &A, const std::vector< T > &B, C less=C())
the items common to and , by a binary search in the longer list of each item of the shorter one
void twoLevelHeaders(const DiskFile< T > &A, std::size_t L, DiskFile< T > &H)
the first item of each block of items of , into , by one scan
void intersectTwoLevelExternal(const DiskFile< T > &A, const DiskFile< T > &H, std::size_t L, const DiskFile< T > &B, DiskFile< T > &out, C less=C())
the items common to the sorted files and into out, by the headers of the blocks of items of [see...
std::vector< T > intersectTwoLevel(const std::vector< T > &A, const std::vector< T > &B, std::size_t L, C less=C())
the items common to and , by the first items of the blocks of items of
void intersectMergeExternal(const DiskFile< T > &A, const DiskFile< T > &B, DiskFile< T > &out, C less=C())
the items common to the sorted files and into out, by merging, reads
std::vector< T > intersectMerge(const std::vector< T > &A, const std::vector< T > &B, C less=C())
the items common to and , by merging
Definition ADT.h:96