|
ADS
Algorithms and Data Structures
|
The intersection of two sorted sets, the core of the resolution of a query of several words by an inverted index (Ferragina, chapter 6): \( A \) of \( n \) items and \( B \) of \( m \) items, strictly increasing, \( m \leq n \) (the roles are swapped otherwise). More...
#include "ADS/Contract.h"#include "ADS/external/TwoLevelMemory.h"#include "ADS/search/BinarySearch.h"#include "ADS/sort/Sorted.h"#include <algorithm>#include <cstddef>#include <cstdint>#include <functional>#include <utility>#include <vector>#include "ADS/set/impl/SortedIntersection.tpp"Go to the source code of this file.
Classes | |
| class | ADS::PermutedBuckets |
| a set of values below \( 2^w \), permuted by \( x \mapsto ( a x + c ) \bmod 2^w \) and split by the top bits of the images into buckets of \( L \) items on average More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T, class C = std::less<>> | |
| std::vector< T > | ADS::intersectMerge (const std::vector< T > &A, const std::vector< T > &B, C less=C()) |
| the items common to \( A \) and \( B \), by merging | |
| template<class T, class C = std::less<>> | |
| std::vector< T > | ADS::intersectBinarySearch (const std::vector< T > &A, const std::vector< T > &B, C less=C()) |
| the items common to \( A \) and \( B \), by a binary search in the longer list of each item of the shorter one | |
| template<class T, class C = std::less<>> | |
| std::vector< T > | ADS::intersectMutualPartition (const std::vector< T > &A, const std::vector< T > &B, C less=C()) |
| the items common to \( A \) and \( B \), by mutual partitions | |
| template<class T, class C = std::less<>> | |
| std::vector< T > | ADS::intersectDoubling (const std::vector< T > &A, const std::vector< T > &B, C less=C()) |
| the items common to \( A \) and \( B \), by doubling searches | |
| template<class T, class C = std::less<>> | |
| std::vector< T > | ADS::intersectTwoLevel (const std::vector< T > &A, const std::vector< T > &B, std::size_t L, C less=C()) |
| the items common to \( A \) and \( B \), by the first items of the blocks of \( L \) items of \( A \) | |
| template<class T> | |
| void | ADS::twoLevelHeaders (const DiskFile< T > &A, std::size_t L, DiskFile< T > &H) |
| the first item of each block of \( L \) items of \( A \), into \( H \), by one scan | |
| template<class T, class C = std::less<>> | |
| void | ADS::intersectMergeExternal (const DiskFile< T > &A, const DiskFile< T > &B, DiskFile< T > &out, C less=C()) |
| the items common to the sorted files \( A \) and \( B \) into out, by merging, \( \lceil n / B \rceil + \lceil m / B \rceil \) reads | |
| template<class T, class C = std::less<>> | |
| void | ADS::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 \( A \) and \( B \) into out, by the headers \( H \) of the blocks of \( L \) items of \( A \) [see twoLevelHeaders()] | |
The intersection of two sorted sets, the core of the resolution of a query of several words by an inverted index (Ferragina, chapter 6): \( A \) of \( n \) items and \( B \) of \( m \) items, strictly increasing, \( m \leq n \) (the roles are swapped otherwise).
Compared with the literature: the experiments of Sanders and Transier, and of Barbay et al., find the lookup best up to lists of similar length, the two-level skipping better than the mutual partition for all but the most unequal lists, whose recursion costs more than its bound says; the adaptive algorithms of Demaine, López-Ortiz and Munro and of Barbay and Kenyon extend the galloping to \( k \) lists, and Ding and König replace the buckets by word-sized bitmaps.
The contracts [see Contract.h]: \( A \) and \( B \) strictly increasing, audits; \( L \ge 1 \); the result is the intersection, strictly increasing, a postcondition checked as an audit against intersectMerge(); \( 1 \le w \le 63 \), \( a \) odd, the values below \( 2^w \), and two PermutedBuckets intersected with the same permutation; the files of the external versions share a memory of at least \( 4 B \). The functions are defined in SortedIntersection.tpp.