Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_memArray.H
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
91#ifndef TPL_MEMARRAY_H
92#define TPL_MEMARRAY_H
93
94#include <utility>
95#include <cstdlib>
96#include <cstring>
97#include <cmath>
98#include <limits>
99#include <stdexcept>
100#include <type_traits>
101
102#include <ah-errors.H>
103#include <ahUtils.H>
104#include <ahDry.H>
105#include <ahIterator.H>
106#include <ah-iterator.H>
107#include <array_it.H>
108#include <array_utils.H>
109
110// Opt-in AddressSanitizer container annotations for MemArray. Define
111// ALEPH_ANNOTATE_CONTAINERS for the whole program, Aleph included, when it is
112// built with -fsanitize=address: the macro changes the layout of MemArray, so
113// every translation unit must agree on it. Without AddressSanitizer, or
114// without the macro, the annotations compile to nothing.
115#if defined(ALEPH_ANNOTATE_CONTAINERS)
116# if defined(__SANITIZE_ADDRESS__)
117# define ALEPH_MEMARRAY_ANNOTATIONS 1
118# elif defined(__has_feature)
119# if __has_feature(address_sanitizer)
120# define ALEPH_MEMARRAY_ANNOTATIONS 1
121# endif
122# endif
123#endif
124#ifdef ALEPH_MEMARRAY_ANNOTATIONS
125# include <sanitizer/common_interface_defs.h>
126#endif
127
128namespace Aleph {
155template <typename T>
157{
158public:
159 static constexpr size_t Min_Dim = 4;
160
161protected:
162 T *ptr = nullptr;
163 size_t dim = Min_Dim;
164 size_t n = 0;
165#ifdef ALEPH_MEMARRAY_ANNOTATIONS
166 bool annotated = true; // false while the live items are not the prefix [0, n)
167#endif
168
172 static constexpr bool copied_as_bytes =
173 std::is_trivially_copyable_v<T> and std::is_trivially_copy_assignable_v<T>
174 and std::is_trivially_move_assignable_v<T> and not std::is_volatile_v<T>;
175
176public:
184 mutable size_t contract_threshold;
185
187 T *get_ptr() noexcept
188 {
189 return ptr;
190 }
191
193 const T *get_ptr() const noexcept
194 {
195 return ptr;
196 }
197
199 const size_t &get_dim() const noexcept
200 {
201 return dim;
202 }
203
204protected:
214 void annotate(const size_t old_n, const size_t new_n) const noexcept
215 {
216#ifdef ALEPH_MEMARRAY_ANNOTATIONS
217 if (annotated and ptr != nullptr and old_n != new_n)
218 __sanitizer_annotate_contiguous_container(ptr, ptr + dim, ptr + old_n, ptr + new_n);
219#else
220 (void) old_n;
221 (void) new_n;
222#endif
223 }
224
229 void disable_annotations() noexcept
230 {
231 annotate(n, dim);
232#ifdef ALEPH_MEMARRAY_ANNOTATIONS
233 annotated = false;
234#endif
235 }
236
237 static size_t next_power_of_two(const size_t requested)
238 {
239 size_t ret = 1;
240 while (ret < requested)
241 {
242 ah_overflow_error_if(ret > (std::numeric_limits<size_t>::max() >> 1))
243 << "MemArray capacity overflow";
244 ret <<= 1;
245 }
246 return ret;
247 }
248
250 void allocate()
251 {
252 static_assert(std::is_default_constructible_v<T>,
253 "MemArray<T> requires a default-constructible T (storage is new T[dim])");
254 assert(is_power_of_2(dim));
255 // Before new[]: for dim items whose bytes do not fit in a size_t, what
256 // new[] asks of the allocator depends on the compiler
257 ah_overflow_error_if(dim > std::numeric_limits<size_t>::max() / sizeof(T))
258 << "MemArray capacity overflow";
259 ptr = new T[dim];
261 annotate(dim, n);
262 }
263
271 void reallocate(const size_t cap, const size_t first = 0)
272 {
273 assert(cap >= n);
274 MemArray replacement(cap);
275#ifdef ALEPH_MEMARRAY_ANNOTATIONS
276 if (not annotated)
277 replacement.disable_annotations();
278#endif
279 replacement.putn(n);
280 for (size_t i = 0; i < n; ++i)
281 replacement.ptr[i] = std::move(ptr[(first + i) & (dim - 1)]);
282 swap(replacement);
283 }
284
291 bool expand(const size_t first = 0)
292 {
293 assert((ptr != nullptr and is_power_of_2(dim)) or (dim == 0 and n == 0));
294 if (n < dim)
295 return false;
296
297 ah_overflow_error_if(dim > (std::numeric_limits<size_t>::max() >> 1))
298 << "MemArray::expand(): capacity overflow";
299 reallocate(dim == 0 ? Min_Dim : dim << 1, first);
300
301 return true;
302 }
303
324 template <class U>
325 [[gnu::noinline]]
326 T &relocate_and_insert(const size_t pos, U &&item, const size_t first)
327 {
328 assert(n == dim and pos <= n);
329 ah_overflow_error_if(dim > (std::numeric_limits<size_t>::max() >> 1))
330 << "MemArray::grow_and_insert(): capacity overflow";
331
332 MemArray replacement(dim == 0 ? Min_Dim : dim << 1);
333#ifdef ALEPH_MEMARRAY_ANNOTATIONS
334 if (not annotated)
335 replacement.disable_annotations();
336#endif
337 replacement.putn(n + 1);
338 replacement.ptr[pos] = std::forward<U>(item); // the old buffer is still alive
339 if constexpr (copied_as_bytes)
340 if (first == 0 and n > 0) // in a row, from a buffer: an array moved from has none
341 {
342 std::memcpy(static_cast<void *>(replacement.ptr), ptr, pos * sizeof(T));
343 std::memcpy(static_cast<void *>(replacement.ptr + pos + 1), ptr + pos,
344 (n - pos) * sizeof(T));
345 swap(replacement);
346 return ptr[pos];
347 }
348 for (size_t i = 0; i < pos; ++i) // a loop for each side of the item:
349 replacement.ptr[i] = std::move(ptr[(first + i) & (dim - 1)]);
350 for (size_t i = pos; i < n; ++i) // one loop would choose at each step
351 replacement.ptr[i + 1] = std::move(ptr[(first + i) & (dim - 1)]);
352 swap(replacement);
353
354 return ptr[pos];
355 }
356
369 template <class U>
370 T &grow_and_insert(const size_t pos, U &&item, const size_t first = 0)
371 {
372 if constexpr (std::is_scalar_v<T>)
373 return relocate_and_insert(pos, T(item), first);
374 else
375 return relocate_and_insert(pos, std::forward<U>(item), first);
376 }
377
388 bool contract(const size_t first = 0)
389 {
390 assert(ptr);
391 if (n > contract_threshold)
392 return false;
393
394 const size_t newsz = dim >> 1; // dim/2
395
396 if (newsz <= Min_Dim or n > newsz)
397 return false;
398
399 reallocate(newsz, first);
400
401 return true;
402 }
403
409 void init_dim(size_t d)
410 {
411 if (d == 0)
412 d = Min_Dim;
413
414 dim = is_power_of_2(d) ? d : next_power_of_two(d);
415
416 assert(dim >= d);
417 assert(is_power_of_2(dim));
418 }
419
420public:
421 using Item_Type = T;
422
424 [[nodiscard]] constexpr size_t capacity() const noexcept
425 {
426 return dim;
427 }
428
430 size_t size() const noexcept
431 {
432 return n;
433 }
434
436 bool is_empty() const noexcept
437 {
438 return n == 0;
439 }
440
449 MemArray(size_t _dim = Min_Dim) : ptr(nullptr), n(0)
450 {
451 static_assert(std::is_move_constructible_v<T>, "T must be move constructible");
452 static_assert(std::is_move_assignable_v<T>, "T must be move assignable");
453 init_dim(_dim);
454 allocate();
455 }
456
458 {
459 if (ptr != nullptr)
460 {
461 annotate(n, dim);
462 delete[] ptr;
463 ptr = nullptr;
464 }
465 }
466
468 void swap(MemArray &a) noexcept
469 {
470 std::swap(ptr, a.ptr);
471 std::swap(dim, a.dim);
472 std::swap(n, a.n);
473 std::swap(contract_threshold, a.contract_threshold);
474#ifdef ALEPH_MEMARRAY_ANNOTATIONS
475 std::swap(annotated, a.annotated); // the flag describes the buffer
476#endif
477 }
478
488 requires(std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T>)
489 : MemArray(a.dim)
490 {
491 putn(a.n);
492 if constexpr (copied_as_bytes)
493 if (n > 4)
494 {
495 std::memcpy(static_cast<void *>(ptr), a.ptr, n * sizeof(T));
496 return;
497 }
498 for (size_t i = 0; i < n; ++i)
499 ptr[i] = a.ptr[i];
500 }
501
507 MemArray(MemArray &&a) noexcept : ptr(nullptr), dim(0), n(0), contract_threshold(0)
508 {
509 swap(a);
510 }
511
514 requires(std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T>)
515 {
516 if (this == &a)
517 return *this;
518
519 MemArray copy(a);
520 swap(copy);
521
522 return *this;
523 }
524
527 {
528 swap(a);
529 return *this;
530 }
531
543 void empty() noexcept
544 {
545 annotate(n, 0);
546 n = 0;
547 }
548
554 void clear() noexcept
555 {
556 empty();
557 }
558
565 {
566 if (dim <= Min_Dim)
567 {
568 empty();
569 return;
570 }
571
572 MemArray replacement(Min_Dim);
573#ifdef ALEPH_MEMARRAY_ANNOTATIONS
574 if (not annotated)
575 replacement.disable_annotations();
576#endif
577 swap(replacement);
578 }
579
588 T &put(const T &item)
589 requires std::is_copy_assignable_v<T>
590 {
591 return put_item(item);
592 }
593
603 T &put(T &&item)
604 {
605 return put_item(std::move(item));
606 }
607
608private:
610 template <class U>
611 T &put_item(U &&item)
612 {
613 if (n == dim) // growing frees the buffer that item may live in
614 return grow_and_insert(n, std::forward<U>(item));
615
616 annotate(n, n + 1);
617 try
618 {
619 ptr[n] = std::forward<U>(item);
620 }
621 catch (...)
622 {
623 annotate(n + 1, n);
624 throw;
625 }
626 T &ret = ptr[n++];
627 return ret;
628 }
629
631 template <class U>
632 T &push_item(U &&item)
633 {
634 if (n == dim) // growing frees the buffer that item may live in
635 return grow_and_insert(0, std::forward<U>(item));
636
637 T tmp(std::forward<U>(item)); // open_gap() shifts the element item may be
638 open_gap();
639 ptr[0] = std::move(tmp);
640 T &ret = ptr[0];
641 return ret;
642 }
643
644 void open_gap(size_t pos = 0, size_t num_entries = 1)
645 {
646 putn(num_entries);
647 Aleph::open_gap(ptr, n, pos, num_entries);
648 }
649
650 void close_gap(size_t pos, size_t num_entries = 1)
651 {
652 ah_underflow_error_if(num_entries == 0) << "MemArray::close_gap(): no entries to remove";
653 Aleph::close_gap(ptr, n, pos, num_entries);
654 // The last num_entries items are now moved-from: drop them without
655 // moving them out again, as get() would do.
656 const size_t old_n = n;
657 n -= num_entries;
658 annotate(old_n, n);
659 contract();
660 }
661
662public:
671 T &push(const T &item)
672 requires std::is_copy_assignable_v<T>
673 {
674 return push_item(item);
675 }
676
685 T &push(T &&item)
686 {
687 return push_item(std::move(item));
688 }
689
691 {
692 ah_underflow_error_if(n == 0) << "top(): MemArray is empty";
693
694 return ptr[0];
695 }
696
699 const T &top() const
700 {
701 ah_underflow_error_if(n == 0) << "top(): MemArray is empty";
702
703 return ptr[0];
704 }
705
708 {
709 ah_underflow_error_if(n == 0) << "remove_first(): MemArray is empty";
710 assert(ptr);
711 T ret = std::move(ptr[0]);
712 this->close_gap(0, 1);
713 return ret;
714 }
715
718 {
719 return remove_first();
720 }
721
723 T &append(const T &item)
724 requires std::is_copy_assignable_v<T>
725 {
726 return put(item);
727 }
728
730 T &append(T &&item)
731 {
732 return put(std::forward<T>(item));
733 }
734
736 T &insert(const T &item)
737 requires std::is_copy_assignable_v<T>
738 {
739 return push(item);
740 }
741
743 T &insert(T &&item)
744 {
745 return push(std::forward<T>(item));
746 }
747
758 void putn(const size_t more)
759 {
760 ah_overflow_error_if(more > std::numeric_limits<size_t>::max() - n)
761 << "MemArray::putn(): size overflow";
762 const size_t new_n = n + more;
763 if (new_n <= dim)
764 {
765 annotate(n, new_n);
766 n = new_n;
767 return;
768 }
769
770 size_t new_dim = dim == 0 ? Min_Dim : dim;
771 while (new_dim < new_n)
772 {
773 ah_overflow_error_if(new_dim > (std::numeric_limits<size_t>::max() >> 1))
774 << "MemArray::putn(): capacity overflow";
775 new_dim <<= 1; // dim = 2*dim
776 }
777
778 reallocate(new_dim);
779 annotate(n, new_n);
780 n = new_n;
781 }
782
784 requires std::is_copy_assignable_v<T>
785 {
786 const size_t old_n = n;
787 const size_t num_entries = a.size();
788 putn(num_entries);
789 for (size_t i = 0; i < num_entries; ++i)
790 ptr[old_n + i] = a.ptr[i];
791
792 return *this;
793 }
794
800 void reserve(const size_t cap)
801 {
802 if (cap <= dim)
803 return;
804
805 const size_t new_dim = is_power_of_2(cap) ? cap : next_power_of_two(cap);
806 reallocate(new_dim);
807 }
808
811 T get(const size_t i = 1)
812 {
813 ah_underflow_error_if(i == 0 or i > n)
814 << "MemArray::get(): invalid number of entries";
815
816 const size_t old_n = n;
817 T ret = std::move(ptr[n - i]);
818 n -= i;
819 annotate(old_n, n);
820
821 contract();
822
823 return ret;
824 }
825
826 T get_ne(const size_t i = 1) noexcept
827 {
828 assert(ptr);
829 assert(i > 0);
830 assert(i <= n);
831 const size_t old_n = n;
832 T ret = std::move(ptr[n - i]);
833 n -= i;
834 annotate(old_n, n);
835
836 contract();
837
838 return ret;
839 }
840
843 {
844 return get();
845 }
846
849 {
850 ah_underflow_error_if(n == 0) << "MemArray::last(): empty array";
851 return ptr[n - 1];
852 }
853
856 const T &last() const
857 {
858 ah_underflow_error_if(n == 0) << "MemArray::last(): empty array";
859 return ptr[n - 1];
860 }
861
864 {
865 ah_underflow_error_if(n == 0) << "MemArray::first(): empty array";
866 return ptr[0];
867 }
868
871 const T &first() const
872 {
873 ah_underflow_error_if(n == 0) << "MemArray::first(): empty array";
874 return ptr[0];
875 }
876
879 {
880 return first();
881 }
882
885 const T &get_first() const
886 {
887 return first();
888 }
889
892 {
893 return last();
894 }
895
898 const T &get_last() const
899 {
900 return last();
901 }
902
905 {
906 if (n < 2)
907 return *this;
908
909 for (size_t i = 0, j = n - 1; i < j; ++i, --j)
910 std::swap(ptr[i], ptr[j]);
911 return *this;
912 }
913
916 T &access(const size_t i) noexcept
917 {
918 assert(ptr);
919 return ptr[i];
920 }
921
924 const T &access(const size_t i) const noexcept
925 {
926 assert(ptr);
927 return ptr[i];
928 }
929
932 T &operator[](const size_t i)
933 {
934 ah_out_of_range_error_if(i >= n) << "access out of range";
935
936 return ptr[i];
937 }
938
941 const T &operator[](const size_t i) const
942 {
943 ah_out_of_range_error_if(i >= n) << "access out of range";
944
945 return ptr[i];
946 }
947
954 T &operator()(const size_t i) noexcept
955 {
956 assert(ptr);
957 assert(i < n);
958 return ptr[i];
959 }
960
963 const T &operator()(const size_t i) const noexcept
964 {
965 assert(ptr);
966 assert(i < n);
967 return ptr[i];
968 }
969
979 template <class Operation>
981 bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith<Operation &, T &>)
982 {
983 assert(ptr or n == 0);
984 for (size_t i = 0; i < n; i++)
985 if (not static_cast<bool>(operation(ptr[i])))
986 return false;
987
988 return true;
989 }
990
1000 template <class Operation>
1002 bool traverse(Operation &operation) const
1004 {
1005 assert(ptr or n == 0);
1006 for (size_t i = 0; i < n; i++)
1007 if (not static_cast<bool>(operation(static_cast<const T &>(ptr[i]))))
1008 return false;
1009
1010 return true;
1011 }
1012
1014 template <class Operation>
1016 bool traverse(Operation &&operation) const
1018 {
1019 return traverse<Operation>(operation);
1020 }
1021
1023 template <class Operation>
1025 bool traverse(Operation &&operation) noexcept(Aleph::NothrowPredicateWith<Operation &, T &>)
1026 {
1027 return traverse<Operation>(operation);
1028 }
1029
1030 bool is_valid() const noexcept
1031 {
1032 return ptr;
1033 }
1034
1039 struct Iterator : public Array_Iterator<T>
1040 {
1042 using Base::Base;
1043
1046 : Array_Iterator<T>(a.ptr, a.dim, a.n)
1047 {}
1048
1050 Iterator(const MemArray<T> &) = delete;
1051 };
1052
1055};
1056} // end namespace Aleph
1057
1058#endif // TPL_MEMARRAY_H
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Definition ah-errors.H:727
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
Definition ah-errors.H:517
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:611
STL-compatible iterator adapters for Aleph containers.
DRY (Don't Repeat Yourself) utilities and macros.
Iterator traits and STL-compatible iterator wrappers.
General utility functions and helpers.
Iterator wrapper for C++ raw arrays and circular buffers.
Utility functions for array manipulation.
Iterator wrapper for C++ raw arrays.
Definition array_it.H:85
Read-only view of an Aleph iterator: the iterator of a constant container.
Simple, scalable and fast dynamic array.
T & put(const T &item)
Put a copy of item at the end of the sequence.
T & put(T &&item)
Move item to the end of the sequence.
void reserve(const size_t cap)
Reserves cap cells into the array.
bool traverse(Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
Traverse all the elements from index 0 to n - 1 and execute operation on each on them.
const T & top() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const T & get_first() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void open_gap(size_t pos=0, size_t num_entries=1)
bool contract(const size_t first=0)
Test if n is lesser than contract_threshold and eventually contract the array half long and copies it...
size_t size() const noexcept
Return the number of elements.
void putn(const size_t more)
Reserve more additional logical slots in the array.
T get_ne(const size_t i=1) noexcept
T & get_first()
See first.
bool traverse(Operation &&operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >)
See traverse(Operation & operation).
void clear() noexcept
Alias for empty().
const T & operator()(const size_t i) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
const T * get_ptr() const noexcept
See get_ptr().
T & last()
Return a modifiable reference to the last element.
T & grow_and_insert(const size_t pos, U &&item, const size_t first=0)
Grow a full array and insert one item: relocate_and_insert().
T & append(const T &item)
See put(const T & item).
size_t contract_threshold
Number of items at or below which contract() halves the capacity.
T & push_item(U &&item)
Shared body of both push() overloads.
static constexpr bool copied_as_bytes
Whether memcpy() copies an item as its assignments do: T is trivially copyable, its copy and move ass...
void empty_and_release()
Clear the array and reduce allocated storage to Min_Dim.
static constexpr size_t Min_Dim
MemArray(MemArray &&a) noexcept
Transfer storage without allocation.
T & get_last()
See last.
void allocate()
Allocate memory for the current dimension.
bool expand(const size_t first=0)
Grow a full array, including an empty moved-from array.
T get(const size_t i=1)
Remove i elements from the end.
const T & access(const size_t i) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
MemArray(const MemArray &a)
Construct a copy of a, with its capacity.
void disable_annotations() noexcept
Make the whole buffer accessible and stop annotating it.
T & operator[](const size_t i)
Return a reference to the ith element.
T & push(T &&item)
Move item to the beginning of the sequence.
T & append(T &&item)
See put(T && item).
T & push(const T &item)
Push a copy of item at the beginning of the sequence.
MemArray & append(const MemArray &a)
MemArray(size_t _dim=Min_Dim)
Construct an array con capacity equal or greater than _dim.
T & insert(T &&item)
See push(T && item).
constexpr size_t capacity() const noexcept
The type of element of array.
MemArray & operator=(const MemArray &a)
Assign by copy a to this
T & relocate_and_insert(const size_t pos, U &&item, const size_t first)
Grow a full array and insert one item into the new buffer.
T & insert(const T &item)
See push(const T & item).
const T & last() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static size_t next_power_of_two(const size_t requested)
void init_dim(size_t d)
Initialize the dimension of the array to d or to the next two power if d is not a two power.
bool is_valid() const noexcept
T & operator()(const size_t i) noexcept
Unlike access(), which also reaches the reserved slots beyond the logical size (a build with AddressS...
void close_gap(size_t pos, size_t num_entries=1)
bool is_empty() const noexcept
Return true is the array is empty.
void reallocate(const size_t cap, const size_t first=0)
Relocate the logical sequence into a new buffer.
T pop()
pop() the most recently pushed item
void empty() noexcept
Empties the container.
const T & operator[](const size_t i) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T & access(const size_t i) noexcept
Return a modifiable reference to the ith element.
T remove_last()
See get().
MemArray & reverse()
Reverse the order of items in array.
void annotate(const size_t old_n, const size_t new_n) const noexcept
Tell AddressSanitizer that the live items, previously the prefix [0, old_n), are now [0,...
const size_t & get_dim() const noexcept
Return the current dimension of array.
T * get_ptr() noexcept
Return the current base of array.
const T & first() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool traverse(Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
Traverse a constant array; each element is handed out as a constant reference.
void swap(MemArray &a) noexcept
Swap in constant time this with a
bool traverse(Operation &&operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >)
See traverse(Operation & operation) const.
T & put_item(U &&item)
Shared body of both put() overloads.
const T & get_last() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
T & first()
Return a modifiable reference to the first element.
T remove_first()
Remove the first item. Gap is closed.
MemArray & operator=(MemArray &&a) noexcept
Assign by moving a to this
PredicateWith<F, Args...>, and neither the call nor the conversion of its result to bool can throw.
f(args...) is a valid call whose result is usable as a condition.
Main namespace for Aleph-w library functions.
bool is_power_of_2(size_t x)
Taken from http://stackoverflow.com/questions/3638431/determine-if-an-int-is-a-power-of-2-or-not-in-a...
Definition ahUtils.H:229
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
and
Check uniqueness with explicit hash + equality functors.
void open_gap(Tarray &ptr, size_t n, size_t pos=0, size_t num_entries=1)
Open a gap in an array by shifting elements right.
Definition array_utils.H:96
void close_gap(T *ptr, size_t n, size_t pos, size_t num_entries=1)
Close a gap in an array by shifting elements left.
Simple iterator on elements of array.
Iterator(MemArray< T > &a) noexcept
Iterator on the modifiable array a.
Iterator(const MemArray< T > &)=delete
A constant array is iterated through Const_Iterator.