ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::ThreadedTree< K > Class Template Reference

a binary search tree with threads in symmetric order More...

#include <ADS/tree/ThreadedTree.h>

Classes

class  const_iterator
 the constant iterator in symmetric order, by the threads More...

Public types

using value_type = K
 the type of the keys
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances
using reference = const K &
 a constant reference
using const_reference = const K &
 a constant reference
using iterator = const_iterator
 a constant iterator

Public member functions

 ThreadedTree (void)
 the empty tree, the head node alone, its left link a thread to itself
 ThreadedTree (const ThreadedTree &)=delete
 no copy
ThreadedTree & operator= (const ThreadedTree &)=delete
 no copy
 ~ThreadedTree ()
 frees the nodes
void insert (const K &k)
 inserts \( k \), if it is not there
bool contains (const K &k) const
 whether \( k \) is there, by the search of a binary search tree that stops at a thread
std::size_t size (void) const
 the number of keys
template<class F>
void forEach (F &&f) const
 f( k ) on the keys by increasing order, by the threads: no stack, no recursion
std::vector< K > reversed (void) const
 the keys by decreasing order, by the left threads, as forEach() with the predecessors
const_iterator begin (void) const
 the iterator on the least key, the successor of the head
const_iterator end (void) const
 the iterator past the largest key, the head
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()

Detailed description

template<std::totally_ordered K>
class ADS::ThreadedTree< K >

a binary search tree with threads in symmetric order

Member typedef documentation

◆ const_reference

template<std::totally_ordered K>
using ADS::ThreadedTree< K >::const_reference = const K &

a constant reference

◆ difference_type

template<std::totally_ordered K>
using ADS::ThreadedTree< K >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<std::totally_ordered K>
using ADS::ThreadedTree< K >::iterator = const_iterator

a constant iterator

◆ reference

template<std::totally_ordered K>
using ADS::ThreadedTree< K >::reference = const K &

a constant reference

◆ size_type

template<std::totally_ordered K>
using ADS::ThreadedTree< K >::size_type = std::size_t

the type of the sizes

◆ value_type

template<std::totally_ordered K>
using ADS::ThreadedTree< K >::value_type = K

the type of the keys

Constructor and destructor documentation

◆ ThreadedTree() [1/2]

template<std::totally_ordered K>
ADS::ThreadedTree< K >::ThreadedTree ( void )

the empty tree, the head node alone, its left link a thread to itself

◆ ThreadedTree() [2/2]

template<std::totally_ordered K>
ADS::ThreadedTree< K >::ThreadedTree ( const ThreadedTree< K > & )
delete

no copy

◆ ~ThreadedTree()

template<std::totally_ordered K>
ADS::ThreadedTree< K >::~ThreadedTree ( )

frees the nodes

Member function documentation

◆ begin()

template<std::totally_ordered K>
const_iterator ADS::ThreadedTree< K >::begin ( void ) const
inlinenodiscard

the iterator on the least key, the successor of the head

◆ cbegin()

template<std::totally_ordered K>
const_iterator ADS::ThreadedTree< K >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<std::totally_ordered K>
const_iterator ADS::ThreadedTree< K >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

template<std::totally_ordered K>
bool ADS::ThreadedTree< K >::contains ( const K & k) const
nodiscard

whether \( k \) is there, by the search of a binary search tree that stops at a thread

◆ end()

template<std::totally_ordered K>
const_iterator ADS::ThreadedTree< K >::end ( void ) const
inlinenodiscard

the iterator past the largest key, the head

◆ forEach()

template<std::totally_ordered K>
template<class F>
void ADS::ThreadedTree< K >::forEach ( F && f) const

f( k ) on the keys by increasing order, by the threads: no stack, no recursion

◆ insert()

template<std::totally_ordered K>
void ADS::ThreadedTree< K >::insert ( const K & k)

inserts \( k \), if it is not there

In pseudocode (Knuth, section 2.3.1, the insertion into a threaded tree, beyond the book): the new leaf takes over the thread that the search ends on, and threads back to its parent on the other side:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( k ) \cr 2 & \quad x \gets \text{the root} \cr 3 & \quad \textbf{loop} \cr 4 & \qquad \textbf{if}\ k = x.\mathit{key}\ \textbf{then return} \cr 5 & \qquad \textbf{if}\ k < x.\mathit{key}\ \textbf{and}\ x.\mathit{left} \text{ is a thread}\ \textbf{then} \cr 6 & \qquad\quad x.\mathit{left} \gets \text{a leaf } ( k ,\ \text{left thread } x.\mathit{left} ,\ \text{right thread } x ); \ \textbf{return} \cr 7 & \qquad \textbf{if}\ k > x.\mathit{key}\ \textbf{and} \ x.\mathit{right} \text{ is a thread}\ \textbf{then} \cr 8 & \qquad\quad x.\mathit{right} \gets \text{a leaf } ( k ,\ \text{left thread } x ,\ \text{right thread } x.\mathit{right} ); \ \textbf{return} \cr 9 & \qquad x \gets x.\mathit{left} \text{ if } k < x.\mathit{key} \text{, } x.\mathit{right} \text{ otherwise} \end{array}} \]

Postcondition
\( k \) is there

◆ operator=()

template<std::totally_ordered K>
ThreadedTree & ADS::ThreadedTree< K >::operator= ( const ThreadedTree< K > & )
delete

no copy

◆ reversed()

template<std::totally_ordered K>
std::vector< K > ADS::ThreadedTree< K >::reversed ( void ) const
nodiscard

the keys by decreasing order, by the left threads, as forEach() with the predecessors

◆ size()

template<std::totally_ordered K>
std::size_t ADS::ThreadedTree< K >::size ( void ) const
nodiscard

the number of keys


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