Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::InlineStack< T, N > Class Template Reference

Stack of fixed capacity whose storage is inside the object. More...

#include <tpl_arrayStack.H>

Inheritance diagram for Aleph::InlineStack< T, N >:
[legend]
Collaboration diagram for Aleph::InlineStack< T, N >:
[legend]

Public Types

using Item_Type = T
 The type of element.
 

Public Member Functions

 InlineStack () noexcept=default
 Construct an empty stack. The storage is not initialized.
 
 InlineStack (const InlineStack &s) noexcept
 Copy the items in use of s.
 
InlineStack & operator= (const InlineStack &s) noexcept
 Assign the items in use of s.
 
void swap (InlineStack &s) noexcept
 Exchange the items in use of s and this, in time O(size()).
 
T & push (const T &data) noexcept
 Push a copy of data.
 
T pop () noexcept
 Pop the top; the stack must not be empty.
 
T popn (const size_t n) noexcept
 Perform n pops in constant time.
 
T & top () noexcept
 Return a modifiable reference to the top; the stack must not be empty.
 
const T & top () const noexcept
 See top().
 
T & top (const size_t i) noexcept
 Return a modifiable reference to the item i positions below the top.
 
const T & top (const size_t i) const noexcept
 See top(const size_t i).
 
T & base () noexcept
 Return a modifiable reference to the bottom; the stack must not be empty.
 
const T & base () const noexcept
 See base().
 
bool is_empty () const noexcept
 Return true if the stack is empty.
 
size_t size () const noexcept
 Return the number of items.
 
void empty () noexcept
 Empty the stack.
 
void clear () noexcept
 See empty().
 

Static Public Member Functions

static constexpr size_t capacity () noexcept
 Maximum number of items.
 

Private Attributes

T array [N]
 
size_t head = 0
 

Detailed Description

template<typename T, size_t N>
class Aleph::InlineStack< T, N >

Stack of fixed capacity whose storage is inside the object.

Unlike FixedStack, it never allocates: the capacity N is a compile-time constant and the items live in the object, so construction, copy, move and swap cannot throw. Only the items in use are copied or exchanged, so an empty or short stack costs nothing to copy even when N is large.

It is meant for bounded paths that are built and consumed in place: the path from the root of a balanced tree, whose length is bounded by Node::MaxHeight, is the typical one.

No operation checks its preconditions, except by assert(): pushing beyond N or popping an empty stack is a logic error.

Template Parameters
Ttype of the items; it must be trivially copyable (pointers, indices).
Nmaximum number of items.
See also
FixedStack ArrayStack

Definition at line 740 of file tpl_arrayStack.H.

Member Typedef Documentation

◆ Item_Type

template<typename T , size_t N>
using Aleph::InlineStack< T, N >::Item_Type = T

The type of element.

Definition at line 749 of file tpl_arrayStack.H.

Constructor & Destructor Documentation

◆ InlineStack() [1/2]

template<typename T , size_t N>
Aleph::InlineStack< T, N >::InlineStack ( )
defaultnoexcept

Construct an empty stack. The storage is not initialized.

◆ InlineStack() [2/2]

template<typename T , size_t N>
Aleph::InlineStack< T, N >::InlineStack ( const InlineStack< T, N > &  s)
inlinenoexcept

Copy the items in use of s.

Definition at line 755 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::array, and Aleph::InlineStack< T, N >::head.

Member Function Documentation

◆ base() [1/2]

template<typename T , size_t N>
const T & Aleph::InlineStack< T, N >::base ( ) const
inlinenoexcept

◆ base() [2/2]

template<typename T , size_t N>
T & Aleph::InlineStack< T, N >::base ( )
inlinenoexcept

Return a modifiable reference to the bottom; the stack must not be empty.

Definition at line 847 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::array, and Aleph::InlineStack< T, N >::head.

Referenced by TEST(), and TEST().

◆ capacity()

template<typename T , size_t N>
static constexpr size_t Aleph::InlineStack< T, N >::capacity ( )
inlinestaticconstexprnoexcept

Maximum number of items.

Definition at line 781 of file tpl_arrayStack.H.

References N.

Referenced by TEST().

◆ clear()

template<typename T , size_t N>
void Aleph::InlineStack< T, N >::clear ( )
inlinenoexcept

See empty().

Definition at line 879 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::head.

Referenced by TEST().

◆ empty()

◆ is_empty()

◆ operator=()

template<typename T , size_t N>
InlineStack & Aleph::InlineStack< T, N >::operator= ( const InlineStack< T, N > &  s)
inlinenoexcept

Assign the items in use of s.

Definition at line 762 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::array, and Aleph::InlineStack< T, N >::head.

◆ pop()

◆ popn()

template<typename T , size_t N>
T Aleph::InlineStack< T, N >::popn ( const size_t  n)
inlinenoexcept

Perform n pops in constant time.

Parameters
[in]nnumber of items to pop; at most size().
Returns
the last popped item.

Definition at line 808 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::array, and Aleph::InlineStack< T, N >::head.

Referenced by Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::fix_black_condition(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search_and_stack_rb(), and TEST().

◆ push()

template<typename T , size_t N>
T & Aleph::InlineStack< T, N >::push ( const T &  data)
inlinenoexcept

Push a copy of data.

Parameters
[in]dataitem to push; the stack must not be full.
Returns
a modifiable reference to the pushed item.

Definition at line 790 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::array, and Aleph::InlineStack< T, N >::head.

Referenced by Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::extract_max(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::extract_min(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::find_succ_and_swap(), Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::insert(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_left(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::join_right(), Aleph::GenBinHeap< NodeType, Key, Compare >::Iterator::next_ne(), Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::remove(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::remove(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search_and_stack_rb(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search_dup_and_stack_rb(), Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::search_or_insert(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::search_or_insert(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::split_key(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::split_key_dup(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_key_dup(), Aleph::Gen_Avl_Tree_Rk< NodeType, Key, Compare >::split_pos(), Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::split_pos(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ size()

template<typename T , size_t N>
size_t Aleph::InlineStack< T, N >::size ( ) const
inlinenoexcept

Return the number of items.

Definition at line 867 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::head.

Referenced by Aleph::Gen_Rb_Tree_Rk< NodeType, Key, Compare >::search_and_stack_rb(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ swap()

template<typename T , size_t N>
void Aleph::InlineStack< T, N >::swap ( InlineStack< T, N > &  s)
inlinenoexcept

Exchange the items in use of s and this, in time O(size()).

Definition at line 773 of file tpl_arrayStack.H.

Referenced by TEST().

◆ top() [1/4]

template<typename T , size_t N>
const T & Aleph::InlineStack< T, N >::top ( ) const
inlinenoexcept

◆ top() [2/4]

◆ top() [3/4]

template<typename T , size_t N>
const T & Aleph::InlineStack< T, N >::top ( const size_t  i) const
inlinenoexcept

◆ top() [4/4]

template<typename T , size_t N>
T & Aleph::InlineStack< T, N >::top ( const size_t  i)
inlinenoexcept

Return a modifiable reference to the item i positions below the top.

Parameters
[in]inumber of positions; top(0) is the top.
Returns
a modifiable reference to the item.

Definition at line 833 of file tpl_arrayStack.H.

References Aleph::InlineStack< T, N >::array, and Aleph::InlineStack< T, N >::head.

Member Data Documentation

◆ array

◆ head


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