MADNESS
0.10.1
|
Dynamically sized Stack with small stack size optimization. More...
#include <stack.h>
Public Types | |
typedef const T & | const_reference |
Element constant reference type. More... | |
typedef T & | reference |
Element reference type. More... | |
typedef unsigned int | size_type |
An unsigned integral type. More... | |
typedef T | value_type |
Type of the stack elements. More... | |
Public Member Functions | |
Stack () | |
Construct an empty stack. More... | |
Stack (const Stack< T, N > &other) | |
Copy constructor. More... | |
Stack (Stack< T, N > &&other) | |
Move constructor. More... | |
~Stack () | |
Destructor. More... | |
size_type | capacity () const |
Capacity accessor. More... | |
void | clear () |
Empty the stack. More... | |
T * | data () |
Data accessor. More... | |
const T * | data () const |
Data accessor. More... | |
bool | empty () const |
Check if the stack is empty. More... | |
bool | empty () const volatile |
Check if the stack is empty. More... | |
Stack< T, N > & | operator= (const Stack< T, N > &other) |
Assignment operator. More... | |
Stack< T, N > & | operator= (Stack< T, N > &&other) |
Move assignment operator. More... | |
void | pop () |
Pop an item off of the stack. More... | |
void | push (const_reference value) |
Push a new item onto the stack. More... | |
void | reset () |
Empty the stack and free memory. More... | |
size_type | size () const |
Size accessor. More... | |
size_type | size () const volatile |
Size accessor. More... | |
reference | top () |
Get the last item pushed onto the stack. More... | |
const_reference | top () const |
Get the last item pushed onto the stack. More... | |
Private Types | |
typedef detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value > | StackBase_ |
Private Member Functions | |
T * | allocate (const size_type n) |
Allocate a raw buffer. More... | |
void | deallocate () |
Deallocate memory. More... | |
bool | is_small () const |
Check if the stack is using the small buffer to store data. More... | |
void | move (Stack< T, N > &other) |
Private Attributes | |
char | buffer_ [sizeof(T) *N] |
Static buffer for storing a small number of elements. More... | |
size_type | capacity_ |
The maximum size, in elements, of the data_ buffer. More... | |
T * | data_ |
Pointer to the stack data. More... | |
size_type | size_ |
Number of elements on the stack. More... | |
Additional Inherited Members | |
Static Protected Member Functions inherited from madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value > | |
static void | destroy (T *first, T *last) |
Destroy a range of non-POD objects. More... | |
static void | destroy (T *ptr) |
Destroy a non-POD object. More... | |
static void | uninitialized_copy (T *first, T *last, T *dest) |
Copy a range of POD objects. More... | |
static void | uninitialized_move (T *first, T *last, T *dest) |
Move a range of POD objects. More... | |
Dynamically sized Stack with small stack size optimization.
This object is a dynamically sized stack that functions similarly to a std::vector
. It also includes an optimization for small stack sizes that avoids memory allocations when the stack size is less than or equal to N
.
T | The type of data stored in the stack. |
N | The fixed size of the stack. |
typedef const T& madness::Stack< T, N >::const_reference |
Element constant reference type.
typedef T& madness::Stack< T, N >::reference |
Element reference type.
typedef unsigned int madness::Stack< T, N >::size_type |
An unsigned integral type.
|
private |
typedef T madness::Stack< T, N >::value_type |
Type of the stack elements.
|
inline |
Construct an empty stack.
The capacity of the stack is N
.
|
inline |
Copy constructor.
If the size of other
is less than or equal to N
, then this object will use the small buffer. Otherwise, it will allocate memory and copy the data of other
. The capacity of the object will be equal to max(N, other.size())
.
[in] | other | The stack to be copied. |
References madness::Stack< T, N >::allocate(), madness::Stack< T, N >::buffer_, madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, N, madness::Stack< T, N >::size_, T(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_copy().
|
inline |
Move constructor.
Move the data from other
to this object.
[in] | other | The original stack. |
References madness::Stack< T, N >::move().
|
inline |
|
inlineprivate |
Allocate a raw buffer.
Allocate an uninitialized buffer.
[in] | n | The size of the new buffer. |
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::operator=(), and madness::Stack< T, N >::push().
|
inline |
Capacity accessor.
References madness::Stack< T, N >::capacity_.
|
inline |
Empty the stack.
Destroy items on the stack (if any) and set the size to 0.
References madness::Stack< T, N >::data_, madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), madness::Stack< T, N >::size_, and u().
|
inline |
|
inline |
|
inlineprivate |
Deallocate memory.
Destroy the pointer if it is a dynamically allocated buffer; otherwise do nothing.
References madness::Stack< T, N >::data_, and madness::Stack< T, N >::is_small().
Referenced by madness::Stack< T, N >::~Stack(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::push(), and madness::Stack< T, N >::reset().
|
inline |
Check if the stack is empty.
References madness::Stack< T, N >::size_.
Referenced by madness::DependencyInterface::do_callbacks(), and madness::FutureImpl< T >::set_assigned().
|
inline |
Check if the stack is empty.
References madness::Stack< T, N >::size_.
|
inlineprivate |
Check if the stack is using the small buffer to store data.
References madness::Stack< T, N >::buffer_, and madness::Stack< T, N >::data_.
Referenced by madness::Stack< T, N >::deallocate(), and madness::Stack< T, N >::move().
|
inlineprivate |
other | Description needed. |
References madness::Stack< T, N >::buffer_, madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, madness::Stack< T, N >::is_small(), N, madness::Stack< T, N >::size_, T(), u(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_move().
Referenced by madness::Stack< T, N >::Stack(), and madness::Stack< T, N >::operator=().
|
inline |
Assignment operator.
If the size of other
is less than or equal to N
, then this object will use the small buffer. Otherwise, it will allocate memory and copy the data of other
. The capacity of the object will be equal to max(N, other.size())
.
[in] | other | The stack to be copied. |
References madness::Stack< T, N >::allocate(), madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, madness::Stack< T, N >::deallocate(), madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), madness::Stack< T, N >::size_, T(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_copy().
|
inline |
Move assignment operator.
Move the data from other
to this object. If other
object is is using the static buffer, the data is moved to this object's static buffer. Otherwise, the pointer to the allocated buffer is moved.
[in] | other | The other stack object to be moved |
other
is left in a default constructed state so that it can continue to be used. References madness::Stack< T, N >::data_, madness::Stack< T, N >::deallocate(), madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), madness::Stack< T, N >::move(), and madness::Stack< T, N >::size_.
|
inline |
Pop an item off of the stack.
MadnessException | (via MADNESS_ASSERT) if the stack is empty. |
References madness::Stack< T, N >::data_, madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), MADNESS_ASSERT, and madness::Stack< T, N >::size_.
Referenced by madness::DependencyInterface::do_callbacks(), and madness::FutureImpl< T >::set_assigned().
|
inline |
Push a new item onto the stack.
Push an item onto the top of the stack. If the stack size is equal to the capacity, resize the stack (double).
[in] | value | The item to be pushed onto the stack. |
References madness::Stack< T, N >::allocate(), madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, madness::Stack< T, N >::deallocate(), madness::Stack< T, N >::size_, T(), and madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::uninitialized_move().
Referenced by madness::FutureImpl< T >::add_to_assignments(), madness::DependencyInterface::dec(), madness::DependencyInterface::dec_debug(), madness::DependencyInterface::register_callback(), and madness::DependencyInterface::register_final_callback().
|
inline |
Empty the stack and free memory.
Destroy items on the stack (if any) and return it to the default constructed state.
References madness::Stack< T, N >::buffer_, madness::Stack< T, N >::capacity_, madness::Stack< T, N >::data_, madness::Stack< T, N >::deallocate(), madness::detail::StackBase< T, std::is_standard_layout< T >::value &&std::is_trivial< T >::value >::destroy(), N, madness::Stack< T, N >::size_, T(), and u().
Referenced by madness::FutureImpl< T >::set_assigned().
|
inline |
Size accessor.
References madness::Stack< T, N >::size_.
|
inline |
Size accessor.
References madness::Stack< T, N >::size_.
|
inline |
Get the last item pushed onto the stack.
MadnessException | When the stack is empty |
References madness::Stack< T, N >::data_, MADNESS_ASSERT, and madness::Stack< T, N >::size_.
Referenced by madness::DependencyInterface::do_callbacks(), and madness::FutureImpl< T >::set_assigned().
|
inline |
Get the last item pushed onto the stack.
MadnessException | When the stack is empty. |
References madness::Stack< T, N >::data_, MADNESS_ASSERT, and madness::Stack< T, N >::size_.
|
private |
Static buffer for storing a small number of elements.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::is_small(), madness::Stack< T, N >::move(), and madness::Stack< T, N >::reset().
|
private |
The maximum size, in elements, of the data_
buffer.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::capacity(), madness::Stack< T, N >::move(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::push(), and madness::Stack< T, N >::reset().
|
private |
Pointer to the stack data.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::~Stack(), madness::Stack< T, N >::clear(), madness::Stack< T, N >::data(), madness::Stack< T, N >::deallocate(), madness::Stack< T, N >::is_small(), madness::Stack< T, N >::move(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::pop(), madness::Stack< T, N >::push(), madness::Stack< T, N >::reset(), and madness::Stack< T, N >::top().
|
private |
Number of elements on the stack.
Referenced by madness::Stack< T, N >::Stack(), madness::Stack< T, N >::~Stack(), madness::Stack< T, N >::clear(), madness::Stack< T, N >::empty(), madness::Stack< T, N >::move(), madness::Stack< T, N >::operator=(), madness::Stack< T, N >::pop(), madness::Stack< T, N >::push(), madness::Stack< T, N >::reset(), madness::Stack< T, N >::size(), and madness::Stack< T, N >::top().