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

the table with direct access of the keys in \( [ a , b ] \), \( H( k ) = k - a \): every operation in \( O( 1 ) \) time, \( b - a + 1 \) places of memory More...

#include <ADS/dictionary/DirectTable.h>

Classes

struct  Places
 the places of the table, for SlotIterator More...

Public types

using Key = long
 the type of the keys
using Value = V
 the type of the values
using value_type = std::pair< long , V >
 the type of the items, for the standard library
using key_type = long
 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 between two iterators
using reference = PairRef< long , const V & >
 a reference to an item
using const_reference = PairRef< long , const V & >
 a constant reference to an item
using const_iterator = SlotIterator< DirectTable , Places >
 the iterator on the items, constant
using iterator = const_iterator
 the iterator on the items

Public member functions

 DirectTable (long a, long b)
 the empty table of the keys in \( [ a , b ] \)
std::optional< V > lookup (long k) const
 the value of \( k \), the place \( A[ k - a ] \), or nothing
void insert (long k, const V &v)
 associates \( v \) to \( k \), writing it in \( A[ k - a ] \)
void remove (long k)
 removes \( k \), if it is there, emptying \( A[ k - a ] \)
std::size_t size (void) const
 the number of keys
std::size_t capacity (void) const
 the size \( m = b - a + 1 \) of the vector
const_iterator begin (void) const
 the iterator on the first item
const_iterator end (void) const
 the iterator past the last item
const_iterator cbegin (void) const
 the constant iterator on the first item
const_iterator cend (void) const
 the constant iterator past the last item

Detailed description

template<class V>
class ADS::DirectTable< V >

the table with direct access of the keys in \( [ a , b ] \), \( H( k ) = k - a \): every operation in \( O( 1 ) \) time, \( b - a + 1 \) places of memory

Member typedef documentation

◆ const_iterator

template<class V>
using ADS::DirectTable< V >::const_iterator = SlotIterator< DirectTable , Places >

the iterator on the items, constant

◆ const_reference

template<class V>
using ADS::DirectTable< V >::const_reference = PairRef< long , const V & >

a constant reference to an item

◆ difference_type

template<class V>
using ADS::DirectTable< V >::difference_type = std::ptrdiff_t

the type of the distances between two iterators

◆ iterator

template<class V>
using ADS::DirectTable< V >::iterator = const_iterator

the iterator on the items

◆ Key

template<class V>
using ADS::DirectTable< V >::Key = long

the type of the keys

◆ key_type

template<class V>
using ADS::DirectTable< V >::key_type = long

the type of the keys

◆ mapped_type

template<class V>
using ADS::DirectTable< V >::mapped_type = V

the type of the values

◆ reference

template<class V>
using ADS::DirectTable< V >::reference = PairRef< long , const V & >

a reference to an item

◆ size_type

template<class V>
using ADS::DirectTable< V >::size_type = std::size_t

the type of the sizes

◆ Value

template<class V>
using ADS::DirectTable< V >::Value = V

the type of the values

◆ value_type

template<class V>
using ADS::DirectTable< V >::value_type = std::pair< long , V >

the type of the items, for the standard library

Constructor and destructor documentation

◆ DirectTable()

template<class V>
ADS::DirectTable< V >::DirectTable ( long a,
long b )

the empty table of the keys in \( [ a , b ] \)

Precondition
\( a \le b \), and \( b - a + 1 \) places fit in a std::size_t (not the whole range of long)

Member function documentation

◆ begin()

template<class V>
const_iterator ADS::DirectTable< V >::begin ( void ) const
inlinenodiscard

the iterator on the first item

◆ capacity()

template<class V>
std::size_t ADS::DirectTable< V >::capacity ( void ) const
nodiscard

the size \( m = b - a + 1 \) of the vector

◆ cbegin()

template<class V>
const_iterator ADS::DirectTable< V >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class V>
const_iterator ADS::DirectTable< V >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ end()

template<class V>
const_iterator ADS::DirectTable< V >::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ insert()

template<class V>
void ADS::DirectTable< V >::insert ( long k,
const V & v )

associates \( v \) to \( k \), writing it in \( A[ k - a ] \)

Precondition
\( k \in [ a , b ] \)
Postcondition
lookup( k ) is \( v \)

◆ lookup()

template<class V>
std::optional< V > ADS::DirectTable< V >::lookup ( long k) const
nodiscard

the value of \( k \), the place \( A[ k - a ] \), or nothing

In pseudocode (chapter 7), \( A[ 0 .. m - 1 ] \) the places, each empty (nil) or holding a value, and \( n \) the places not empty:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lookup}( k )\quad \triangleright \ \text{the key } k \text{ in the cell } k - a \cr 2 & \quad \textbf{return}\ A[ k - a ]\quad \triangleright\ \textbf{nil} \text{ if } k \text{ is absent} \cr 3 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr 4 & \quad n \gets n + [ A[ k - a ] = \textbf{nil} ];\ A[ k - a ] \gets v \cr 5 & \textbf{procedure}\ \mathrm{remove}( k ) \cr 6 & \quad n \gets n - [ A[ k - a ] \ne \textbf{nil} ];\ A[ k - a ] \gets \textbf{nil} \end{array}} \]

Precondition
\( k \in [ a , b ] \)

◆ remove()

template<class V>
void ADS::DirectTable< V >::remove ( long k)

removes \( k \), if it is there, emptying \( A[ k - a ] \)

Precondition
\( k \in [ a , b ] \)
Postcondition
lookup( k ) is nothing

◆ size()

template<class V>
std::size_t ADS::DirectTable< V >::size ( void ) const
nodiscard

the number of keys


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