|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Simple, scalable, contiguous dynamic array. More...
#include <utility>#include <cstdlib>#include <cmath>#include <stdexcept>#include <ah-errors.H>#include <ahUtils.H>#include <ahDry.H>#include <ahIterator.H>#include <array_it.H>#include <array_utils.H>Go to the source code of this file.
Classes | |
| class | Aleph::MemArray< T > |
| Simple, scalable and fast dynamic array. More... | |
| struct | Aleph::MemArray< T >::Iterator |
| Simple iterator on elements of array. More... | |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
Simple, scalable, contiguous dynamic array.
This file provides MemArray, a dynamic array that maintains all elements in a single contiguous memory block. Unlike DynArray (which uses a two-level directory), MemArray offers direct array-like access but requires reallocation when growing beyond capacity.
| Operation | Time | Notes |
|---|---|---|
| access [] | O(1) | Direct memory access |
| append | O(1) amortized | O(n) when reallocating |
| insert at i | O(n-i) | Shifts elements |
| remove at i | O(n-i) | Shifts elements |
| reserve | O(n) | May reallocate |
When capacity is exceeded, the array grows by a configurable factor (default: 2x). This gives amortized O(1) appends.
| Feature | MemArray | DynArray |
|---|---|---|
| Memory layout | Contiguous | Two-level directory |
| Reallocation | Full copy | Segment-based |
| Cache locality | Excellent | Good |
| Large arrays | May fail to allocate | Handles well |
Definition in file tpl_memArray.H.