ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::BTreeMap< K, V, Less, B, R, A > Class Template Reference

an ordered map on a B+-tree of nodes of \( B \) bytes, by the order less(), with the counts of the pairs below each child if R (the ranks) More...

#include <ADS/tree/BTreeMap.h>

Classes

class  const_iterator
 the iterator on the pairs by increasing keys: a leaf, a place in it and the parent of the leaf More...

Public types

using Key = K
 the type of the keys
using Value = V
 the type of the values
using value_type = std::pair< K , V >
 the pairs ( key , value ) by value, which own their copies
using key_type = K
 the type of the keys
using mapped_type = V
 the type of the values
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances
using reference = PairRef< const K & , const V & >
 references, by value
using const_reference = reference
 the same
using iterator = const_iterator
 the constant iterator
using allocator_type = A
 the type of the allocator

Public member functions

 BTreeMap (Less less=Less())
 the empty map, by the order less
 BTreeMap (Less less, const A &alloc)
 the empty map, by the order less, the blocks of its nodes from alloc
 BTreeMap (const A &alloc)
 the empty map, the blocks of its nodes from alloc
 BTreeMap (const BTreeMap &o)
 a copy of o, node by node
 BTreeMap (const BTreeMap &o)
 a copy of o, node by node, on the allocator that select_on_container_copy_construction() gives
 BTreeMap (const BTreeMap &o, const A &alloc)
 a copy of o, node by node, on alloc
 BTreeMap (BTreeMap &&o) noexcept
 the nodes of o, which is left empty
 BTreeMap (BTreeMap &&o, const A &alloc)
 the pairs of o, which is left empty, on alloc: its nodes if the allocators are equal, else a copy of its pairs
BTreeMap & operator= (BTreeMap o) noexcept
 the pairs of o, by copy and swap
BTreeMap & operator= (const BTreeMap &o)
 the copy assignment, with the allocator of o if it propagates
BTreeMap & operator= (BTreeMap &&o)
 the move assignment: the nodes of o if its allocator propagates or is equal, else a copy of its pairs
 ~BTreeMap ()
 frees the nodes
std::optional< V > lookup (const K &k) const
 the value of \( k \), if there
const V * find (const K &k) const
 the value of \( k \), to change in place, or nullptr, by the descent of lookup()
V * find (const K &k)
 the value of \( k \), to change in place, or nullptr, by the descent of lookup()
bool insert (const K &k, const V &v)
 gives \( k \) the value \( v \); true if \( k \) was not there
bool remove (const K &k)
 removes \( k \); true if it was there
bool contains (const K &k) const
 whether \( k \) is there, by the descent of lookup()
std::size_t size (void) const
 the number \( n \) of pairs
bool empty (void) const
 true if there is no pair
int height (void) const
 the levels of the tree, 0 if empty, 1 if a single leaf
void clear (void)
 removes the pairs, the pools keeping their memory
template<std::input_iterator It>
void build (It first, It last)
 replaces the pairs with those of [ first , last ), pairs ( key , value ) by strictly increasing keys, the nodes as full and as even as they can be, \( O( n ) \)
template<class F>
void forEach (F &&f) const
 f( key , value ) on each pair, by increasing keys, along the iterators
template<class F>
void forRange (const K &lo, const K &hi, F &&f) const
 f( key , value ) on each pair of key in \( [ \mathit{lo} , \mathit{hi} ) \), by increasing keys, \( O( ( L + I ) \log n + k ) \) for \( k \) pairs
void swap (BTreeMap &o) noexcept(detail::swapNoexcept< A >)
 exchanges the nodes and the pools with o, each pool with its allocator
allocator_type get_allocator (void) const
 the allocator of the blocks of the nodes
const_iterator begin (void) const
 the iterator on the smallest key
const_iterator end (void) const
 the iterator past the largest key
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()
const_iterator lowerBound (const K &k) const
 the first pair whose key is not smaller than \( k \), the place of \( k \) in the leaf reached by the descent of lookup()
const K * findKey (const K &k) const
 the address of the key \( k \), nil if absent, in \( O( ( L + I ) \log n ) \) time: the find( x ) of a USet of Morin [see DictionarySet]; valid until the key is removed
const K * lowerBoundKey (const K &k) const
 the address of the smallest key not smaller than \( k \), nil if none, in \( O( ( L + I ) \log n ) \) time: the find( x ) of an SSet of Morin [see DictionarySet]; valid until the next change
const_iterator upperBound (const K &k) const
 the first pair whose key is larger than \( k \), the place after the keys not larger than \( k \) in the leaf reached by the descent of lookup()
const_iterator erase (const_iterator it)
 removes the pair of it, and gives the one after it: remove( k ) and then lowerBound( k ), \( k \) the key of it
std::size_t rank (const K &k) const
 the pairs whose key is smaller than \( k \), \( O( ( L + I ) \log n ) \) time
const_iterator select (std::size_t i) const
 the pair of rank \( i \) (from 0), end() if \( i \ge n \)

Static public attributes

static constexpr std::size_t L
 the pairs of a leaf
static constexpr std::size_t I
 the keys of an internal node

Detailed description

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
requires std::default_initializable< K > && std::default_initializable< V >
class ADS::BTreeMap< K, V, Less, B, R, A >

an ordered map on a B+-tree of nodes of \( B \) bytes, by the order less(), with the counts of the pairs below each child if R (the ranks)

Member typedef documentation

◆ allocator_type

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::allocator_type = A

the type of the allocator

◆ const_reference

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::const_reference = reference

the same

◆ difference_type

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::iterator = const_iterator

the constant iterator

◆ Key

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::Key = K

the type of the keys

◆ key_type

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::key_type = K

the type of the keys

◆ mapped_type

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::mapped_type = V

the type of the values

◆ reference

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::reference = PairRef< const K & , const V & >

references, by value

◆ size_type

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::size_type = std::size_t

the type of the sizes

◆ Value

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::Value = V

the type of the values

◆ value_type

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
using ADS::BTreeMap< K, V, Less, B, R, A >::value_type = std::pair< K , V >

the pairs ( key , value ) by value, which own their copies

Constructor and destructor documentation

◆ BTreeMap() [1/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( Less less = Less())
explicit

the empty map, by the order less

◆ BTreeMap() [2/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( Less less,
const A & alloc )

the empty map, by the order less, the blocks of its nodes from alloc

◆ BTreeMap() [3/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( const A & alloc)
inlineexplicit

the empty map, the blocks of its nodes from alloc

◆ BTreeMap() [4/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( const BTreeMap< K, V, Less, B, R, A > & o)

a copy of o, node by node

◆ BTreeMap() [5/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( const BTreeMap< K, V, Less, B, R, A > & o)
inline

a copy of o, node by node, on the allocator that select_on_container_copy_construction() gives

◆ BTreeMap() [6/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( const BTreeMap< K, V, Less, B, R, A > & o,
const A & alloc )

a copy of o, node by node, on alloc

◆ BTreeMap() [7/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( BTreeMap< K, V, Less, B, R, A > && o)
noexcept

the nodes of o, which is left empty

◆ BTreeMap() [8/8]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::BTreeMap ( BTreeMap< K, V, Less, B, R, A > && o,
const A & alloc )

the pairs of o, which is left empty, on alloc: its nodes if the allocators are equal, else a copy of its pairs

◆ ~BTreeMap()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
ADS::BTreeMap< K, V, Less, B, R, A >::~BTreeMap ( )

frees the nodes

Member function documentation

◆ begin()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::begin ( void ) const
nodiscard

the iterator on the smallest key

◆ build()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
template<std::input_iterator It>
void ADS::BTreeMap< K, V, Less, B, R, A >::build ( It first,
It last )

replaces the pairs with those of [ first , last ), pairs ( key , value ) by strictly increasing keys, the nodes as full and as even as they can be, \( O( n ) \)

In pseudocode (the bulk loading of a B+-tree, Graefe, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( P )\quad \triangleright \ P \text{ the } n \text{ pairs, by increasing keys} \cr 2 & \quad \mathit{level} \gets \lceil n / L \rceil \text{ leaves, each } \text{with } \lfloor n / \lceil n / L \rceil \rfloor \text{ or one } \text{more pairs of } P \text{ in order, linked} \cr 3 & \quad \textbf{while}\ \mathit{level} \text{ has more than one } \text{node}\ \textbf{do} \cr 4 & \qquad g \gets \lceil |\mathit{level}| / ( I + 1 ) \rceil \cr 5 & \qquad \mathit{level} \gets g \text{ internal nodes, each with } \text{the next nodes of } \mathit{level} \text{ as children,} \cr 6 & \qquad\quad \text{as evenly as possible, and the largest key } \text{below each child} \cr & \qquad\quad \text{but the last as a bound} \cr 7 & \quad \mathit{root} \gets \text{the node of } \mathit{level} \end{array}} \]

Precondition
the keys are strictly increasing (an audit)

◆ cbegin()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::cend ( void ) const
inlinenodiscard

as end()

◆ clear()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
void ADS::BTreeMap< K, V, Less, B, R, A >::clear ( void )

removes the pairs, the pools keeping their memory

◆ contains()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
bool ADS::BTreeMap< K, V, Less, B, R, A >::contains ( const K & k) const
nodiscard

whether \( k \) is there, by the descent of lookup()

◆ empty()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
bool ADS::BTreeMap< K, V, Less, B, R, A >::empty ( void ) const
nodiscard

true if there is no pair

◆ end()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::end ( void ) const
nodiscard

the iterator past the largest key

◆ erase()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::erase ( const_iterator it)

removes the pair of it, and gives the one after it: remove( k ) and then lowerBound( k ), \( k \) the key of it

◆ find() [1/2]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
V * ADS::BTreeMap< K, V, Less, B, R, A >::find ( const K & k)
nodiscard

the value of \( k \), to change in place, or nullptr, by the descent of lookup()

◆ find() [2/2]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const V * ADS::BTreeMap< K, V, Less, B, R, A >::find ( const K & k) const
nodiscard

the value of \( k \), to change in place, or nullptr, by the descent of lookup()

◆ findKey()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const K * ADS::BTreeMap< K, V, Less, B, R, A >::findKey ( const K & k) const
nodiscard

the address of the key \( k \), nil if absent, in \( O( ( L + I ) \log n ) \) time: the find( x ) of a USet of Morin [see DictionarySet]; valid until the key is removed

◆ forEach()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
template<class F>
void ADS::BTreeMap< K, V, Less, B, R, A >::forEach ( F && f) const

f( key , value ) on each pair, by increasing keys, along the iterators

◆ forRange()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
template<class F>
void ADS::BTreeMap< K, V, Less, B, R, A >::forRange ( const K & lo,
const K & hi,
F && f ) const

f( key , value ) on each pair of key in \( [ \mathit{lo} , \mathit{hi} ) \), by increasing keys, \( O( ( L + I ) \log n + k ) \) for \( k \) pairs

In pseudocode (the scan of the leaves of a B+-tree, Comer, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{forRange}( \mathit{lo} , \mathit{hi} , f ) \cr 2 & \quad \textbf{foreach}\ ( k , v ) \text{ from } \mathrm{lowerBound}( \mathit{lo} ) \text{ on}\ \textbf{do} \cr 3 & \qquad \textbf{if}\ k \ge \mathit{hi}\ \textbf{then return} \cr 4 & \qquad f( k , v ) \end{array}} \]

◆ get_allocator()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
allocator_type ADS::BTreeMap< K, V, Less, B, R, A >::get_allocator ( void ) const
inlinenodiscard

the allocator of the blocks of the nodes

◆ height()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
int ADS::BTreeMap< K, V, Less, B, R, A >::height ( void ) const
nodiscard

the levels of the tree, 0 if empty, 1 if a single leaf

◆ insert()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
bool ADS::BTreeMap< K, V, Less, B, R, A >::insert ( const K & k,
const V & v )

gives \( k \) the value \( v \); true if \( k \) was not there

In pseudocode (the insertion of a B+-tree, Comer, beyond the book), \( \pi \) the path of the descent, the places \( ( u , i ) \) of the internal nodes:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( k , v ) \cr 2 & \quad \textbf{if}\ \text{the tree is empty}\ \textbf{then} \ \mathit{root} \gets \text{a leaf with } ( k , v ); \ \textbf{return true} \cr 3 & \quad \textbf{if}\ k > \text{the largest key}\ \textbf{and} \ \text{the last leaf has room}\ \textbf{then} \cr 4 & \qquad \text{append } ( k , v ) \text{ to the last leaf}; \ \textbf{return true}\quad \triangleright\ \text{no descent} \cr 5 & \quad x \gets \text{the leaf reached from the root, } \text{recording the path } \pi;\ p \gets \mathrm{place}( x , k ) \cr 6 & \quad \textbf{if}\ x.k[ p ] = k\ \textbf{then}\ x.v[ p ] \gets v;\ \textbf{return false} \cr 7 & \quad \textbf{if}\ x.n < L\ \textbf{then}\ \text{put } ( k , v ) \text{ at the place } p \text{ of } x \cr 8 & \quad \textbf{else if}\ x \text{ is the last leaf and } p = L \ \textbf{then}\ r \gets \text{a new leaf with } ( k , v ) \text{ } \text{alone};\ \mathrm{climb}( x.k[ L - 1 ] , r , \pi ) \cr 9 & \quad \textbf{else if}\ x \text{ is the first leaf and } p = 0 \ \textbf{then}\ l \gets \text{a new leaf with } ( k , v ) \text{ } \text{alone, before } x;\ \mathrm{climb}( k , l , \pi ) \cr 10 & \quad \textbf{else} \cr 11 & \qquad r \gets \text{a new leaf after } x \text{ with the last } \lfloor ( L + 1 ) / 2 \rfloor \text{ of the } L + 1 \text{ pairs} \cr 12 & \qquad \mathrm{climb}( \text{the largest key left in } x , r , \pi ) \cr 13 & \quad \textbf{return true} \cr 14 & \textbf{procedure}\ \mathrm{climb}( s , r , \pi )\quad \triangleright\ \text{a child split: } s \text{ bounds its left } \text{part, } r \text{ is new} \cr 15 & \quad \textbf{foreach}\ ( u , i ) \text{ of } \pi \text{, from } \text{the leaf up}\ \textbf{do} \cr 16 & \qquad \textbf{if}\ u.n < I\ \textbf{then}\ \text{put } s \text{ and } r \text{ after the child } i \text{ of } u; \ \textbf{return} \cr 17 & \qquad \text{split the } I + 1 \text{ keys and } I + 2 \text{ } \text{children into } u \text{ and a new } w \text{ after it,} \cr & \qquad\quad \text{almost all in } u \text{ on the right edge, in } w \text{ on the left edge, half each otherwise} \cr 18 & \qquad s \gets \text{the key between } u \text{ and } w;\ r \gets w \cr 19 & \quad \mathit{root} \gets \text{a new node with the key } s \text{ and the children the old root and } r \end{array}} \]

and with R the counts along \( \pi \) grow by 1, and those of the nodes that split are counted again.

◆ lookup()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
std::optional< V > ADS::BTreeMap< K, V, Less, B, R, A >::lookup ( const K & k) const
nodiscard

the value of \( k \), if there

In pseudocode (the search of a B+-tree, Comer, with the prefetching of Chen, Gibbons and Mowry, beyond the book), \( h \) the height:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lookup}( k ) \cr 2 & \quad u \gets \mathit{root} \cr 3 & \quad \textbf{for}\ h' \gets h\ \textbf{downto}\ 2\ \textbf{do} \cr 4 & \qquad u \gets u.c[ \mathrm{place}( u , k ) ];\ \text{prefetch the } \text{keys of } u \cr 5 & \quad p \gets \mathrm{place}( u , k ) \cr 6 & \quad \textbf{if}\ p < u.n\ \textbf{and}\ u.k[ p ] = k \ \textbf{then return}\ u.v[ p ]\ \textbf{else return nil} \end{array}} \]

where \( \mathrm{place}( u , k ) \) is the number of the keys of \( u \) smaller than \( k \), counted on all the padded places at once on the arithmetic keys, by a binary search on the others.

◆ lowerBound()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::lowerBound ( const K & k) const
nodiscard

the first pair whose key is not smaller than \( k \), the place of \( k \) in the leaf reached by the descent of lookup()

◆ lowerBoundKey()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const K * ADS::BTreeMap< K, V, Less, B, R, A >::lowerBoundKey ( const K & k) const
nodiscard

the address of the smallest key not smaller than \( k \), nil if none, in \( O( ( L + I ) \log n ) \) time: the find( x ) of an SSet of Morin [see DictionarySet]; valid until the next change

◆ operator=() [1/3]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
BTreeMap & ADS::BTreeMap< K, V, Less, B, R, A >::operator= ( BTreeMap< K, V, Less, B, R, A > && o)
inline

the move assignment: the nodes of o if its allocator propagates or is equal, else a copy of its pairs

◆ operator=() [2/3]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
BTreeMap & ADS::BTreeMap< K, V, Less, B, R, A >::operator= ( BTreeMap< K, V, Less, B, R, A > o)
noexcept

the pairs of o, by copy and swap

◆ operator=() [3/3]

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
BTreeMap & ADS::BTreeMap< K, V, Less, B, R, A >::operator= ( const BTreeMap< K, V, Less, B, R, A > & o)
inline

the copy assignment, with the allocator of o if it propagates

◆ rank()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
std::size_t ADS::BTreeMap< K, V, Less, B, R, A >::rank ( const K & k) const
nodiscard

the pairs whose key is smaller than \( k \), \( O( ( L + I ) \log n ) \) time

In pseudocode (the rank of the order-statistic trees of Cormen et al., on a B-tree, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{rank}( k ) \cr 2 & \quad r \gets 0;\ u \gets \mathit{root} \cr 3 & \quad \textbf{while}\ u \text{ is internal}\ \textbf{do} \cr 4 & \qquad i \gets \mathrm{place}( u , k );\ r \gets r + \sum_{j < i} u.\mathit{cnt}[ j ];\ u \gets u.c[ i ] \cr 5 & \quad \textbf{return}\ r + \mathrm{place}( u , k ) \end{array}} \]

◆ remove()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
bool ADS::BTreeMap< K, V, Less, B, R, A >::remove ( const K & k)

removes \( k \); true if it was there

In pseudocode (the removal of a B+-tree, Comer, beyond the book), \( \pi \) the path of the descent:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( k ) \cr 2 & \quad x \gets \text{the leaf reached from the root, } \text{recording the path } \pi;\ p \gets \mathrm{place}( x , k ) \cr 3 & \quad \textbf{if}\ x.k[ p ] \ne k\ \textbf{then return false} \cr 4 & \quad \text{take the pair of place } p \text{ out of } x \cr 5 & \quad \textbf{if}\ x \text{ is the root and empty} \ \textbf{then}\ \text{the tree is empty} \cr 6 & \quad \textbf{else if}\ x.n < L / 2\ \textbf{then} \ \mathrm{shrink}( x , \pi ) \cr 7 & \quad \textbf{return true} \cr 8 & \textbf{procedure}\ \mathrm{shrink}( x , \pi )\quad \triangleright\ x \text{ is less than half full} \cr 9 & \quad ( u , i ) \gets \text{the last place of } \pi;\ l , r \gets \text{the children of } u \text{ around } x \cr 10 & \quad \textbf{if}\ l \text{ and } r \text{ fit in one node} \ \textbf{then} \cr 11 & \qquad \text{move } r \text{ (and, if internal, the bound of } u \text{ between them) into } l;\ \text{take } r \text{ out of } u \cr 12 & \qquad \textbf{if}\ u \text{ is the root with no key} \ \textbf{then}\ \mathit{root} \gets l \cr 13 & \qquad \textbf{else if}\ u \text{ is less than half full} \ \textbf{then}\ \mathrm{shrink}( u , \pi \text{ without its last } \text{place} ) \cr 14 & \quad \textbf{else}\ \text{move items between } l \text{ and } r \text{ until they hold half each, and set the bound of } u \end{array}} \]

and with R the counts along \( \pi \) fall by 1, and those of the nodes that change are counted again.

◆ select()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::select ( std::size_t i) const
nodiscard

the pair of rank \( i \) (from 0), end() if \( i \ge n \)

In pseudocode (the select of the order-statistic trees of Cormen et al., on a B-tree, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{select}( i ) \cr 2 & \quad \textbf{if}\ i \ge n\ \textbf{then return}\ \mathrm{end}() \cr 3 & \quad u \gets \mathit{root} \cr 4 & \quad \textbf{while}\ u \text{ is internal}\ \textbf{do} \cr 5 & \qquad j \gets 0 \cr 6 & \qquad \textbf{while}\ i \ge u.\mathit{cnt}[ j ]\ \textbf{do}\ i \gets i - u.\mathit{cnt}[ j ];\ j \gets j + 1 \cr 7 & \qquad u \gets u.c[ j ] \cr 8 & \quad \textbf{return}\ \text{the place } i \text{ of the leaf } u \end{array}} \]

◆ size()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
std::size_t ADS::BTreeMap< K, V, Less, B, R, A >::size ( void ) const
nodiscard

the number \( n \) of pairs

◆ swap()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
void ADS::BTreeMap< K, V, Less, B, R, A >::swap ( BTreeMap< K, V, Less, B, R, A > & o)
noexcept

exchanges the nodes and the pools with o, each pool with its allocator

Precondition
the allocators are equal, if they do not propagate on a swap

◆ upperBound()

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
const_iterator ADS::BTreeMap< K, V, Less, B, R, A >::upperBound ( const K & k) const
nodiscard

the first pair whose key is larger than \( k \), the place after the keys not larger than \( k \) in the leaf reached by the descent of lookup()

Member data documentation

◆ I

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
std::size_t ADS::BTreeMap< K, V, Less, B, R, A >::I
staticconstexpr
Initial value:
=
std::clamp< std::size_t >( B / ( sizeof( K ) + sizeof( void * ) ) , 4 ,
255 )

the keys of an internal node

◆ L

template<class K, class V, class Less = std::less< K >, std::size_t B = 512, bool R = false, class A = HugePageAllocator< std::pair< const K , V > >>
std::size_t ADS::BTreeMap< K, V, Less, B, R, A >::L
staticconstexpr
Initial value:
=
std::clamp< std::size_t >( B / ( sizeof( K ) + sizeof( V ) ) , 4 , 255 )

the pairs of a leaf


The documentation for this class was generated from the following file: