ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
DynamicPGMIndex.h File Reference

The dynamic PGM-index of Ferragina and Vinciguerra, beyond the book: an ordered map from arithmetic keys to values, with insertions and removals, made of static PGM-indices [see PGMIndex.h] by the logarithmic method of Bentley and Saxe (see The PGM-index compressed and dynamic). More...

#include "ADS/Contract.h"
#include "ADS/dictionary/FastHash.h"
#include "ADS/memory/Prefetch.h"
#include "ADS/search/PGMIndex.h"
#include "ADS/set/BlockedBloomFilter.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <type_traits>
#include <utility>
#include <vector>
#include "ADS/search/impl/DynamicPGMIndex.tpp"

Go to the source code of this file.

Classes

class  ADS::DynamicPGMIndex< K, V, E, B, I >
 the ordered map from the arithmetic keys K to the values V of the dynamic PGM-index, with the error \( \epsilon = E \) in the levels, the ratio \( B \) of the sizes of two levels and the least capacity \( I \) of a level with a PGM-index More...

Namespaces

namespace  ADS

Detailed description

The dynamic PGM-index of Ferragina and Vinciguerra, beyond the book: an ordered map from arithmetic keys to values, with insertions and removals, made of static PGM-indices [see PGMIndex.h] by the logarithmic method of Bentley and Saxe (see The PGM-index compressed and dynamic).

The pairs lie in a buffer of \( b_0 = 128 \) pairs, sorted, and in levels \( L_1 , L_2 , \ldots \), the level \( L_i \) a sorted array of at most \( b_0 B^i \) pairs, each key at most once per level; a key may be in several levels, and its pair in the newest one, the buffer first and then by increasing \( i \), is the one that counts. A removal is the insertion of a tombstone, a pair that marks the key as absent. An insertion that finds the buffer full merges it, with the new pair, into the first level \( L_t \) that has room for it and for the levels before it, merging those too (the newest pair of each key kept); the tombstones are dropped when \( L_t \) is the last level, since no older pair is left for them to hide. Hence:

  • a pair is merged into a level at most once per level, \( B \) times at most before the level overflows into the next one, and the merge and the construction of a PGM-index are linear: an insertion or a removal costs \( O( B \log_B( n / b_0 ) ) \) amortized time;
  • a lookup searches the buffer and then the levels from the newest, and stops at the first one that has the key;
  • lowerBound() and forEach() merge the levels from their places of the key, the newest pair of each key deciding, and skip the keys whose newest pair is a tombstone; lowerBound() keeps no list of places for the first round of the merge, and goes on to the next rounds only when the least key is a tombstone.

The layout, which decides the constants:

  • as in the implementation of the paper, only the levels of capacity at least \( I \) (\( 2^{24} \) by default) have a PGM-index, whose keys are those of the level with no other copy; the smaller ones, where a model does not pay for its building at each merge, are searched by a binary search with no branch that prefetches the next two probes;
  • the keys and the values of a level, and of the buffer, are two arrays, so that a search reads the keys alone, and the tombstones are the sorted list of their keys apart (they are few), so that the merges and the shifts of the buffer move the keys and the values only;
  • a level of capacity at least \( 2^{12} \) has a blocked filter of Bloom of its keys [see BlockedBloomFilter.h], 10 bits per key, as the levels of the stores by log-structured merge have, so that a lookup reads one line of cache of a level that does not have the key instead of searching it: a miss costs a probe per level, and a hit a probe per newer level and one search. The keys that a merge brings into a level go into its filter, made for twice the keys it had, until it is full, and only then is it built again: a key enters the filter of a level a constant number of times, instead of at each merge into it;
  • a merge copies the pair of the smaller key with a branch, which the merges of a short run into a long one, the most, predict well, and the tails as blocks; its two runs are kept for the next merge, so that it allocates no memory once the levels have grown.

The number of distinct keys is not kept: it would cost a lookup per insertion; entries() counts the pairs stored, tombstones and older pairs included.

The contracts [see Contract.h]: \( B \ge 2 \), the pairs of the constructor sorted by key with no key twice (an audit). The functions are defined in DynamicPGMIndex.tpp.

See also
P. Ferragina, G. Vinciguerra, The PGM-index: a fully-dynamic compressed learned index with provable worst-case bounds, Proceedings of the VLDB Endowment 13(8), 1162-1175, 2020, doi:10.14778/3389133.3389135
J. L. Bentley, J. B. Saxe, Decomposable searching problems I: static-to-dynamic transformation, Journal of Algorithms 1(4), 301-358, 1980, doi:10.1016/0196-6774(80)90015-2
P. O'Neil, E. Cheng, D. Gawlick, E. O'Neil, The log-structured merge-tree (LSM-tree), Acta Informatica 33(4), 351-385, 1996, doi:10.1007/s002360050048
N. Dayan, M. Athanassoulis, S. Idreos, Monkey: optimal navigable key-value store, Proceedings of SIGMOD 2017, 79-94, 2017, doi:10.1145/3035918.3064054 (the filters of the levels)
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa