28 # ifndef TPL_ARRAYSTACK_H 29 # define TPL_ARRAYSTACK_H 34 # include <tpl_dynDlist.H> 35 # include <ah-args-ctor.H> 37 # include <tpl_memArray.H> 41 using namespace Aleph;
68 public StlAlephIterator<ArrayStack<T>>
120 return array.
put(data);
131 return array.
put(std::forward<T>(data));
135 T &
append(
const T & data) {
return push(data); }
138 T &
append(T && data) {
return push(std::forward<T>(data)); }
141 T &
insert(
const T & data) {
return push(data); }
144 T &
insert(T && data) {
return push(std::forward<T>(data)); }
174 return array.get_ne(1);
199 return array.
first();
213 const size_t sz = array.
size();
215 throw std::out_of_range(
"top index out of range");
216 return array.
access(sz - i - 1);
219 T & get_last()
const {
return top(); }
228 size_t size() const noexcept {
return array.
size(); }
240 template <
class Operation>
241 bool traverse(Operation & operation) noexcept(noexcept(operation))
247 template <
class Operation>
248 bool traverse(Operation & operation)
const noexcept(noexcept(operation))
254 template <
class Operation>
255 bool traverse(Operation && operation = Operation()) const
256 noexcept(noexcept(operation))
262 template <
class Operation>
263 bool traverse(Operation && operation = Operation())
264 noexcept(noexcept(operation))
301 template <
typename T>
306 public StlAlephIterator<FixedStack<T>>
320 : array(new T[d]), head(0), dim(d)
333 : array(new T [s.dim]), head(s.head), dim(s.dim)
335 for (
int i = 0; i < head; ++i)
336 array[i] = s.array[i];
344 std::swap(array, s.array);
345 std::swap(head, s.head);
346 std::swap(dim, s.dim);
351 : array(
nullptr), head(0), dim(0)
362 T * ptr =
new T [s.dim];
366 for (
size_t i = 0; i < s.head; ++i)
367 array[i] = s.array[i];
385 T &
push(
const T & data) noexcept
388 array[head++] = data;
389 return array[head - 1];
400 std::swap(array[head++], data);
401 return array[head - 1];
405 T &
append(
const T & data) noexcept {
return push(data); }
408 T &
append(T && data) noexcept {
return push(std::forward<T>(data)); }
411 T &
insert(
const T & data) noexcept {
return push(data); }
414 T &
insert(T && data) noexcept {
return push(std::forward<T>(data)); }
421 T &
pushn(
const size_t & n = 1) noexcept
423 assert(head + n <= dim);
426 return array[head - 1];
434 return std::move(array[--head]);
444 assert((
int (head - n)) >= 0);
447 return std::move(array[head]);
455 return array[head - 1];
458 T & get_last()
const noexcept {
return top(); }
461 T &
base() const noexcept {
return array[0]; }
470 T &
top(
size_t i)
const noexcept
473 return array[head - i - 1];
477 bool is_empty() const noexcept {
return head == 0; }
483 size_t size() const noexcept {
return head; }
492 template <
class Operation>
493 bool traverse(Operation & operation) noexcept(noexcept(operation))
495 for (
int i = 0; i < head; i++)
496 if (not operation(array[i]))
503 template <
class Operation>
504 bool traverse(Operation & operation)
const noexcept(noexcept(operation))
506 return const_cast<FixedStack*
>(
this)->traverse(operation);
510 template <
class Operation>
511 bool traverse(Operation && operation = Operation())
512 const noexcept(noexcept(operation))
514 return traverse<Operation>(operation);
518 template <
class Operation>
519 bool traverse(Operation && operation = Operation())
520 noexcept(noexcept(operation))
522 return traverse<Operation>(operation);
540 :
Base(no_exception_ctor, s.array, s.dim, s.head) {}
void swap(FixedStack &s) noexcept
Swap in constant time s with this
Definition: tpl_arrayStack.H:342
Definition: tpl_memArray.H:73
bool is_empty() const noexcept
Retrun true if stack is empty.
Definition: tpl_arrayStack.H:225
T & append(T &&data) noexcept
Definition: tpl_arrayStack.H:408
T & access(const size_t i) const noexcept
Definition: tpl_memArray.H:565
bool traverse(Operation &&operation=Operation()) const noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:255
Definition: htlist.H:1290
T & pushn(const size_t &n=1) noexcept
Definition: tpl_arrayStack.H:421
ArrayStack(ArrayStack &&s)
Move constructor.
Definition: tpl_arrayStack.H:83
size_t capacity() const noexcept
The type of element of array.
Definition: tpl_memArray.H:200
T pop() noexcept
Pop by moving the top of stack.
Definition: tpl_arrayStack.H:430
T & first() const
Return a modifiable reference to the first element.
Definition: tpl_memArray.H:542
Definition: tpl_arrayStack.H:64
T & insert(T &&data)
Definition: tpl_arrayStack.H:144
T & top(size_t i) const noexcept
Definition: tpl_arrayStack.H:470
void swap(MemArray &a) noexcept
Swap in constant time this with a
Definition: tpl_memArray.H:238
size_t size() const noexcept
Return the number of elements stored in the stack.
Definition: tpl_arrayStack.H:228
T & insert(const T &data)
Definition: tpl_arrayStack.H:141
T & last() const
Return a modifiable reference to the last element.
Definition: tpl_memArray.H:534
Definition: array_it.H:45
bool traverse(Operation &operation)
Definition: tpl_memArray.H:598
T & insert(T &&data) noexcept
Definition: tpl_arrayStack.H:414
size_t size() const noexcept
Return the number of elements stored in the stack.
Definition: tpl_arrayStack.H:483
size_t size() const noexcept
Return the number of elements.
Definition: tpl_memArray.H:203
T & push(const T &data)
Definition: tpl_arrayStack.H:118
T popn(const int &n) noexcept
Definition: tpl_arrayStack.H:442
ArrayStack(const ArrayStack &s)
Copy constructor.
Definition: tpl_arrayStack.H:80
T & push(T &&data)
Definition: tpl_arrayStack.H:129
T & top() const
Definition: tpl_arrayStack.H:191
T & top() const noexcept
Return a modifiable referemce to stack's top.
Definition: tpl_arrayStack.H:451
T & insert(const T &data) noexcept
Definition: tpl_arrayStack.H:411
Definition: tpl_arrayStack.H:275
FixedStack(size_t d=1024)
The type of element.
Definition: tpl_arrayStack.H:317
bool traverse(Operation &operation) noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:493
T & base() const noexcept
Return the internal array base.
Definition: tpl_arrayStack.H:461
Definition: tpl_arrayStack.H:302
Definition: tpl_memArray.H:635
void putn(const size_t more)
Definition: tpl_memArray.H:431
T & append(const T &data)
Definition: tpl_arrayStack.H:135
bool is_empty() const noexcept
Return true if stack is empty.
Definition: tpl_arrayStack.H:477
void empty() noexcept
Empty the stack.
Definition: tpl_arrayStack.H:222
FixedStack(FixedStack &&s) noexcept
Move constructor.
Definition: tpl_arrayStack.H:350
T & base() noexcept
Return a modifiable reference to first element of array.
Definition: tpl_arrayStack.H:197
bool traverse(Operation &&operation=Operation()) const noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:511
T popn(size_t n)
Definition: tpl_arrayStack.H:184
size_t capacity() const noexcept
Return the internal capacity.
Definition: tpl_arrayStack.H:231
bool traverse(Operation &operation) const noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:504
T & top(size_t i) const
Definition: tpl_arrayStack.H:211
T & append(T &&data)
Definition: tpl_arrayStack.H:138
void empty() noexcept
Empty the stack.
Definition: tpl_arrayStack.H:480
bool traverse(Operation &&operation=Operation()) noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:263
T pop()
Definition: tpl_arrayStack.H:167
void empty()
Empty the container. The array is not contracted.
Definition: tpl_memArray.H:292
T & push(const T &data) noexcept
Definition: tpl_arrayStack.H:385
bool traverse(Operation &&operation=Operation()) noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:519
T & put(const T &item)
Definition: tpl_memArray.H:310
FixedStack(const FixedStack &s)
Copy constructor.
Definition: tpl_arrayStack.H:332
T & pushn(const size_t &n=1)
Definition: tpl_arrayStack.H:156
T get(size_t i=1)
Definition: tpl_memArray.H:502
bool traverse(Operation &operation) noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:241
Definition: tpl_arrayStack.H:531
Iterator(const ArrayStack< T > &s)
Initialize an iterator on stack s
Definition: tpl_arrayStack.H:285
bool traverse(Operation &operation) const noexcept(noexcept(operation))
Definition: tpl_arrayStack.H:248
T & push(T &&data) noexcept
Definition: tpl_arrayStack.H:397
T & append(const T &data) noexcept
Definition: tpl_arrayStack.H:405
Definition: htlist.H:1323
ArrayStack(size_t dim=4)
The type of element.
Definition: tpl_arrayStack.H:77
void swap(ArrayStack &s) noexcept
Swap this with s
Definition: tpl_arrayStack.H:100