Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Gen_B_Tree< Key, Compare, MinDegree > Class Template Reference

Generic B-Tree with configurable minimum degree. More...

#include <tpl_b_tree.H>

Collaboration diagram for Aleph::Gen_B_Tree< Key, Compare, MinDegree >:
[legend]

Public Types

using key_type = Key
 Stored key type.
 

Public Member Functions

 Gen_B_Tree (const Compare &cmp=Compare())
 Construct an empty B-Tree.
 
template<std::input_iterator It>
 Gen_B_Tree (It first, It last, const Compare &cmp=Compare())
 Construct a B-Tree from an iterator range.
 
 Gen_B_Tree (std::initializer_list< Key > init, const Compare &cmp=Compare())
 Construct a B-Tree from an initializer list.
 
 Gen_B_Tree (const Gen_B_Tree &other)
 Copy constructor performing a deep copy.
 
 Gen_B_Tree (Gen_B_Tree &&other) noexcept(std::is_nothrow_copy_constructible_v< Compare >)
 Move constructor: take the keys of another tree, which is left empty.
 
Gen_B_Tree & operator= (const Gen_B_Tree &other)
 Copy assignment.
 
Gen_B_Tree & operator= (Gen_B_Tree &&other) noexcept(noexcept(swap(other)))
 Move assignment: exchange this tree with another, which is left with the previous keys of this one.
 
void swap (Gen_B_Tree &other) noexcept(std::is_nothrow_swappable_v< Compare >)
 Exchange the keys and the comparators of this tree and another.
 
const Compare & key_comp () const noexcept
 Return the comparison object (read-only).
 
const Compare & get_compare () const noexcept
 Return the comparison object (read-only).
 
bool empty () const noexcept
 Return whether the tree has no keys.
 
bool is_empty () const noexcept
 Synonym for empty() in traditional Aleph style.
 
size_t size () const noexcept
 Return the number of stored keys.
 
size_t height () const noexcept
 Return the current tree height.
 
void clear () noexcept
 Remove every key from the tree.
 
bool contains (const Key &key) const
 Return whether a key is present.
 
bool search (const Key &key) const
 Synonym for contains().
 
bool insert (const Key &key)
 Insert a key if it is not already present.
 
bool insert (Key &&key)
 Insert a key by move if it is not already present.
 
bool remove (const Key &key)
 Remove a key if present.
 
std::optional< Key > min_key () const
 Return the minimum key, if any.
 
std::optional< Key > max_key () const
 Return the maximum key, if any.
 
std::optional< Key > lower_bound (const Key &key) const
 Return the first key not less than key.
 
std::optional< Key > upper_bound (const Key &key) const
 Return the first key strictly greater than key.
 
Array< Key > keys () const
 Materialize the tree contents in sorted order.
 
bool verify () const
 Verify structural B-Tree invariants.
 

Private Types

using Node = detail::BTreeNode< Key >
 

Private Member Functions

size_t lower_bound_index (const Array< Key > &keys, const Key &key) const
 
size_t upper_bound_index (const Array< Key > &keys, const Key &key) const
 
bool equals (const Key &lhs, const Key &rhs) const
 
template<std::input_iterator It>
void insert_range (It first, It last)
 
std::unique_ptr< Node > clone_node (const Node *node) const
 
size_t height_of (const Node *node) const noexcept
 
bool contains_in (const Node *node, const Key &key) const
 
void split_child (Node *parent, const size_t idx)
 
void insert_nonfull (Node *node, const Key &key)
 
std::optional< Key > min_in (const Node *node) const
 
std::optional< Key > max_in (const Node *node) const
 
void borrow_from_prev (Node *parent, const size_t idx)
 
void borrow_from_next (Node *parent, const size_t idx)
 
void merge_children (Node *parent, const size_t idx)
 
size_t ensure_child_has_extra (Node *parent, const size_t idx)
 
bool remove_from (Node *node, const Key &key)
 
void collect_keys (const Node *node, Array< Key > &out) const
 
bool verify_node (const Node *node, const std::optional< Key > &min_key, const std::optional< Key > &max_key, const size_t depth, size_t &leaf_depth, size_t &counted) const
 

Static Private Member Functions

template<typename T , typename U >
static void insert_at (Array< T > &array, const size_t idx, U &&value)
 
template<typename T >
static T erase_at (Array< T > &array, const size_t idx)
 
template<typename T >
static void truncate (Array< T > &array, const size_t new_size)
 
template<typename T >
static void append_copy_range (Array< T > &dst, const Array< T > &src, const size_t from)
 
template<typename T >
static void append_move_range (Array< T > &dst, Array< T > &src, const size_t from)
 

Private Attributes

std::unique_ptr< Node > root_
 
size_t size_ = 0
 
Compare cmp_
 

Static Private Attributes

static constexpr size_t MaxKeys = 2 * MinDegree - 1
 
static constexpr size_t MinKeys = MinDegree - 1
 

Detailed Description

template<typename Key, class Compare = Aleph::less<Key>, size_t MinDegree = 16>
requires StrictWeakOrder<Compare, Key>
class Aleph::Gen_B_Tree< Key, Compare, MinDegree >

Generic B-Tree with configurable minimum degree.

Gen_B_Tree models an ordered set of unique keys. Unlike the raw binary-tree types in Aleph-w, this container owns its internal nodes and stores keys directly in them, which makes it a higher-level tree suited for page-like branching factors.

Template Parameters
KeyKey type stored in the tree.
CompareStrict weak ordering used to sort keys.
MinDegreeMinimum degree t of the B-Tree. Valid values are t >= 2.
Complexity
Example
tree.insert(40);
tree.insert(10);
tree.insert(90);
if (tree.contains(10))
std::cout << "found\n";
tree.remove(40);
auto ordered = tree.keys();
Generic B-Tree with configurable minimum degree.
Definition tpl_b_tree.H:135
bool remove(const Key &key)
Remove a key if present.
Definition tpl_b_tree.H:801
bool insert(const Key &key)
Insert a key if it is not already present.
Definition tpl_b_tree.H:756
bool contains(const Key &key) const
Return whether a key is present.
Definition tpl_b_tree.H:733
Array< Key > keys() const
Materialize the tree contents in sorted order.
Definition tpl_b_tree.H:910
Note
This tree stores unique keys. Duplicate inserts return false.
For leaf-linked range scans, see Aleph::BPlus_Tree.
Thread Safety
Instances are not synchronized. Concurrent access to the same tree requires external synchronization.
Exception Safety
Read-only operations do not allocate. Mutating operations preserve the tree invariants if Compare and Key operations do not throw in the middle of internal node updates; allocation failures propagate as std::bad_alloc.

Definition at line 134 of file tpl_b_tree.H.

Member Typedef Documentation

◆ key_type

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
using Aleph::Gen_B_Tree< Key, Compare, MinDegree >::key_type = Key

Stored key type.

Definition at line 555 of file tpl_b_tree.H.

◆ Node

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
using Aleph::Gen_B_Tree< Key, Compare, MinDegree >::Node = detail::BTreeNode<Key>
private

Definition at line 139 of file tpl_b_tree.H.

Constructor & Destructor Documentation

◆ Gen_B_Tree() [1/5]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
Aleph::Gen_B_Tree< Key, Compare, MinDegree >::Gen_B_Tree ( const Compare &  cmp = Compare())
inlineexplicit

Construct an empty B-Tree.

Parameters
cmpComparison functor used to sort keys.
Exceptions
Nothing.
Note
O(1).

Definition at line 562 of file tpl_b_tree.H.

◆ Gen_B_Tree() [2/5]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
template<std::input_iterator It>
Aleph::Gen_B_Tree< Key, Compare, MinDegree >::Gen_B_Tree ( It  first,
It  last,
const Compare &  cmp = Compare() 
)
inline

Construct a B-Tree from an iterator range.

Parameters
firstFirst element to insert.
lastOne-past-the-end iterator.
cmpComparison functor used to sort keys.
Exceptions
std::bad_allocif internal storage allocation fails.
Note
O(m log m) where m = distance(first, last).

Definition at line 571 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert_range().

◆ Gen_B_Tree() [3/5]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
Aleph::Gen_B_Tree< Key, Compare, MinDegree >::Gen_B_Tree ( std::initializer_list< Key >  init,
const Compare &  cmp = Compare() 
)
inline

Construct a B-Tree from an initializer list.

Parameters
initKeys to insert.
cmpComparison functor used to sort keys.
Exceptions
std::bad_allocif internal storage allocation fails.
Note
O(m log m) where m = init.size().

Definition at line 582 of file tpl_b_tree.H.

◆ Gen_B_Tree() [4/5]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
Aleph::Gen_B_Tree< Key, Compare, MinDegree >::Gen_B_Tree ( const Gen_B_Tree< Key, Compare, MinDegree > &  other)
inline

Copy constructor performing a deep copy.

Parameters
otherTree to copy.
Exceptions
std::bad_allocif cloning internal nodes fails.
Note
O(n) time and space.

Definition at line 591 of file tpl_b_tree.H.

◆ Gen_B_Tree() [5/5]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
Aleph::Gen_B_Tree< Key, Compare, MinDegree >::Gen_B_Tree ( Gen_B_Tree< Key, Compare, MinDegree > &&  other)
inlinenoexcept

Move constructor: take the keys of another tree, which is left empty.

The implicit move took the root but copied the size: the moved-from tree reported keys that it no longer had, and failed verify(). The comparator is copied, since the tree left empty still uses it.

Parameters
otherTree to move from.
Exceptions
Whatevercopying the comparator throws.
Note
O(1).

Definition at line 604 of file tpl_b_tree.H.

Member Function Documentation

◆ append_copy_range()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
template<typename T >
static void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::append_copy_range ( Array< T > &  dst,
const Array< T > &  src,
const size_t  from 
)
inlinestaticprivate

◆ append_move_range()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
template<typename T >
static void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::append_move_range ( Array< T > &  dst,
Array< T > &  src,
const size_t  from 
)
inlinestaticprivate

◆ borrow_from_next()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::borrow_from_next ( Node *  parent,
const size_t  idx 
)
inlineprivate

◆ borrow_from_prev()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::borrow_from_prev ( Node *  parent,
const size_t  idx 
)
inlineprivate

◆ clear()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::clear ( )
inlinenoexcept

Remove every key from the tree.

Exceptions
Nothing.
Note
O(n).

Definition at line 721 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_.

◆ clone_node()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
std::unique_ptr< Node > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::clone_node ( const Node *  node) const
inlineprivate

◆ collect_keys()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::collect_keys ( const Node *  node,
Array< Key > &  out 
) const
inlineprivate

◆ contains()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::contains ( const Key &  key) const
inline

Return whether a key is present.

Parameters
keyKey to search.
Returns
true if the key exists, otherwise false.
Exceptions
Anyexception propagated by Compare.
Note
O(log n).

Definition at line 733 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::contains_in(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_.

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::search().

◆ contains_in()

◆ empty()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::empty ( ) const
inlinenoexcept

Return whether the tree has no keys.

Returns
true if empty, otherwise false.
Exceptions
Nothing.
Note
O(1).

Definition at line 682 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_.

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::is_empty().

◆ ensure_child_has_extra()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::ensure_child_has_extra ( Node *  parent,
const size_t  idx 
)
inlineprivate

◆ equals()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::equals ( const Key &  lhs,
const Key &  rhs 
) const
inlineprivate

◆ erase_at()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
template<typename T >
static T Aleph::Gen_B_Tree< Key, Compare, MinDegree >::erase_at ( Array< T > &  array,
const size_t  idx 
)
inlinestaticprivate

◆ get_compare()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
const Compare & Aleph::Gen_B_Tree< Key, Compare, MinDegree >::get_compare ( ) const
inlinenoexcept

Return the comparison object (read-only).

Returns
Constant reference to the comparison functor.
Note
Alias for key_comp(). Immutable after construction.
Exceptions
Nothing.

Definition at line 672 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::key_comp().

◆ height()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::height ( ) const
inlinenoexcept

Return the current tree height.

Returns
0 for an empty tree, otherwise the number of node levels.
Exceptions
Nothing.
Note
O(log n).

Definition at line 712 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::height_of(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_.

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::height_of().

◆ height_of()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::height_of ( const Node *  node) const
inlineprivatenoexcept

◆ insert() [1/2]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert ( const Key &  key)
inline

Insert a key if it is not already present.

Parameters
keyKey to insert.
Returns
true if insertion happened, false if it was duplicate.
Exceptions
std::bad_allocif node growth fails.
Anyexception propagated by Compare or Key copy/move operations.
Note
O(log n).

Definition at line 756 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::contains(), Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert_nonfull(), Aleph::Gen_B_Tree< Key, Compare, MinDegree >::MaxKeys, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_, and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::split_child().

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert_range().

◆ insert() [2/2]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert ( Key &&  key)
inline

Insert a key by move if it is not already present.

Parameters
keyKey to insert.
Returns
true if insertion happened, false if it was duplicate.
Exceptions
std::bad_allocif node growth fails.
Anyexception propagated by Compare or Key move/copy operations.
Note
O(log n).

Definition at line 789 of file tpl_b_tree.H.

References Aleph::copy(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert().

◆ insert_at()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
template<typename T , typename U >
static void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert_at ( Array< T > &  array,
const size_t  idx,
U &&  value 
)
inlinestaticprivate

◆ insert_nonfull()

◆ insert_range()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
template<std::input_iterator It>
void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::insert_range ( It  first,
It  last 
)
inlineprivate

◆ is_empty()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::is_empty ( ) const
inlinenoexcept

Synonym for empty() in traditional Aleph style.

Returns
true if empty, otherwise false.
Exceptions
Nothing.
Note
O(1).

Definition at line 692 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::empty().

◆ key_comp()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
const Compare & Aleph::Gen_B_Tree< Key, Compare, MinDegree >::key_comp ( ) const
inlinenoexcept

Return the comparison object (read-only).

Returns
Constant reference to the comparison functor.
Note
The comparator is immutable after construction to preserve tree order.
Exceptions
Nothing.

Definition at line 662 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::cmp_.

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::get_compare().

◆ keys()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
Array< Key > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::keys ( ) const
inline

◆ lower_bound()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
std::optional< Key > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::lower_bound ( const Key &  key) const
inline

Return the first key not less than key.

Parameters
keyProbe key.
Returns
Matching lower bound or std::nullopt if none exists.
Exceptions
Anyexception propagated by Compare or Key copy construction.
Note
O(log n).

Definition at line 862 of file tpl_b_tree.H.

References Aleph::detail::BTreeNode< Key >::children, Aleph::detail::BTreeNode< Key >::keys, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::keys(), Aleph::detail::BTreeNode< Key >::leaf, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::lower_bound_index(), Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, and Aleph::Array< T >::size().

◆ lower_bound_index()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::lower_bound_index ( const Array< Key > &  keys,
const Key &  key 
) const
inlineprivate

◆ max_in()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
std::optional< Key > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::max_in ( const Node *  node) const
inlineprivate

◆ max_key()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
std::optional< Key > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::max_key ( ) const
inline

Return the maximum key, if any.

Returns
Largest key in the tree or std::nullopt if empty.
Exceptions
Anyexception propagated by Key copy construction.
Note
O(log n).

Definition at line 851 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::max_in(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_.

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::verify_node().

◆ merge_children()

◆ min_in()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
std::optional< Key > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::min_in ( const Node *  node) const
inlineprivate

◆ min_key()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
std::optional< Key > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::min_key ( ) const
inline

Return the minimum key, if any.

Returns
Smallest key in the tree or std::nullopt if empty.
Exceptions
Anyexception propagated by Key copy construction.
Note
O(log n).

Definition at line 841 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::min_in(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_.

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::verify_node().

◆ operator=() [1/2]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
Gen_B_Tree & Aleph::Gen_B_Tree< Key, Compare, MinDegree >::operator= ( const Gen_B_Tree< Key, Compare, MinDegree > &  other)
inline

Copy assignment.

Parameters
otherTree to copy from.
Returns
*this.
Note
O(n) time and space (copy-and-swap).

Definition at line 613 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::cmp_, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_.

◆ operator=() [2/2]

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
Gen_B_Tree & Aleph::Gen_B_Tree< Key, Compare, MinDegree >::operator= ( Gen_B_Tree< Key, Compare, MinDegree > &&  other)
inlinenoexcept

Move assignment: exchange this tree with another, which is left with the previous keys of this one.

Parameters
otherTree to move from.
Returns
*this.
Note
O(1).

Definition at line 633 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::swap().

◆ remove()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::remove ( const Key &  key)
inline

Remove a key if present.

Parameters
keyKey to erase.
Returns
true if the key was removed, otherwise false.
Exceptions
Anyexception propagated by Compare or Key assignments.
Note
O(log n).

Definition at line 801 of file tpl_b_tree.H.

References Aleph::and, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::remove_from(), Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_.

◆ remove_from()

◆ search()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::search ( const Key &  key) const
inline

Synonym for contains().

Parameters
keyKey to search.
Returns
true if the key exists, otherwise false.
Exceptions
Anyexception propagated by Compare.
Note
O(log n).

Definition at line 744 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::contains().

◆ size()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size ( ) const
inlinenoexcept

Return the number of stored keys.

Returns
Number of unique keys stored in the tree.
Exceptions
Nothing.
Note
O(1).

Definition at line 702 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_.

◆ split_child()

◆ swap()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::swap ( Gen_B_Tree< Key, Compare, MinDegree > &  other)
inlinenoexcept

Exchange the keys and the comparators of this tree and another.

Parameters
otherTree to exchange with.
Exceptions
Whateverswapping the comparators throws. They are exchanged first, so that, if that swap throws, nothing else is exchanged, and both trees are left as they were if it left its arguments as they were.
Note
O(1).

Definition at line 647 of file tpl_b_tree.H.

References Aleph::Gen_B_Tree< Key, Compare, MinDegree >::cmp_, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_, and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::swap().

Referenced by Aleph::Gen_B_Tree< Key, Compare, MinDegree >::operator=(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::swap().

◆ truncate()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
template<typename T >
static void Aleph::Gen_B_Tree< Key, Compare, MinDegree >::truncate ( Array< T > &  array,
const size_t  new_size 
)
inlinestaticprivate

◆ upper_bound()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
std::optional< Key > Aleph::Gen_B_Tree< Key, Compare, MinDegree >::upper_bound ( const Key &  key) const
inline

Return the first key strictly greater than key.

Parameters
keyProbe key.
Returns
Matching upper bound or std::nullopt if none exists.
Exceptions
Anyexception propagated by Compare or Key copy construction.
Note
O(log n).

Definition at line 886 of file tpl_b_tree.H.

References Aleph::detail::BTreeNode< Key >::children, Aleph::detail::BTreeNode< Key >::keys, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::keys(), Aleph::detail::BTreeNode< Key >::leaf, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, Aleph::Array< T >::size(), and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::upper_bound_index().

◆ upper_bound_index()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::upper_bound_index ( const Array< Key > &  keys,
const Key &  key 
) const
inlineprivate

◆ verify()

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
bool Aleph::Gen_B_Tree< Key, Compare, MinDegree >::verify ( ) const
inline

Verify structural B-Tree invariants.

Returns
true if the tree is structurally valid, otherwise false.
Exceptions
Anyexception propagated by Compare.
Note
O(n).

Definition at line 923 of file tpl_b_tree.H.

References Aleph::and, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::root_, Aleph::Gen_B_Tree< Key, Compare, MinDegree >::size_, and Aleph::Gen_B_Tree< Key, Compare, MinDegree >::verify_node().

◆ verify_node()

Member Data Documentation

◆ cmp_

◆ MaxKeys

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
constexpr size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::MaxKeys = 2 * MinDegree - 1
staticconstexprprivate

◆ MinKeys

template<typename Key , class Compare = Aleph::less<Key>, size_t MinDegree = 16>
constexpr size_t Aleph::Gen_B_Tree< Key, Compare, MinDegree >::MinKeys = MinDegree - 1
staticconstexprprivate

◆ root_

◆ size_


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