|
ADS
Algorithms and Data Structures
|
The engineered intersection of two sorted sets, beyond the book [see SortedIntersection.h for the algorithms of Ferragina, chapter 6, and SortedListSet.h for the merge of section 8.3]: intersect() writes the items common to \( A \) of \( n \) items and \( B \) of \( m \) items, both strictly increasing, into out, and gives their number. More...
#include "ADS/Contract.h"#include "ADS/Simd.h"#include <cstddef>#include <vector>#include "ADS/set/impl/VectorIntersection.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T> | |
| std::size_t | ADS::intersect (const T *a, std::size_t n, const T *b, std::size_t m, T *out) |
| the items common to \( a[ 0 .. n ) \) and \( b[ 0 .. m ) \), written to out, and their number | |
| template<class T> | |
| std::vector< T > | ADS::intersect (const std::vector< T > &A, const std::vector< T > &B) |
| the items common to \( A \) and \( B \), by intersect() above on their data | |
The engineered intersection of two sorted sets, beyond the book [see SortedIntersection.h for the algorithms of Ferragina, chapter 6, and SortedListSet.h for the merge of section 8.3]: intersect() writes the items common to \( A \) of \( n \) items and \( B \) of \( m \) items, both strictly increasing, into out, and gives their number.
Compared with the literature: the blocks compared all against all are the method of Schlegel, Willhalm and Lehner on SSE (with the instruction of the comparison of strings) and of Lemire, Boytsov and Kurz, whose library switches to galloping on a ratio of 50; the compressed bitmaps of Roaring [see RoaringBitmap.h] answer by and-ing the containers of \( 2^{16} \) values instead, which is faster on dense sets and slower on sparse ones.
The contracts [see Contract.h]: \( A \) and \( B \) strictly increasing, audits; out has room for \( \min( n , m ) + 8 \) items (the vectors store 8 at a time); the result is the intersection, strictly increasing, a postcondition checked as an audit against std::set_intersection. The functions are defined in VectorIntersection.tpp.