80# ifndef POINTER_TABLE_H
81# define POINTER_TABLE_H
547 <<
" does not match expected value";
600 std::cout <<
"Number of pointers = " <<
num_pointers <<
'\n'
606 std::cout <<
"pointer_table[" <<
heap_index - 1 <<
"]= "
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
void cut(const size_t new_dim=0)
Cut the array to a new dimension; that is, it reduces the dimension of array and frees the remaining ...
size_t size() const noexcept
Return the current dimension of array.
A dynamic table for managing void pointers with index recycling.
void * verify_pointer(long i, void *ptr) const
Verifies that a pointer matches the one stored at an index.
long frees() const noexcept
Returns the number of recyclable indices.
void remove_pointer(long i)
Removes the pointer at the given index.
long num_pointers
Count of currently stored pointers.
bool invariant() const
Validates the internal consistency of the data structure.
long get_threshold() const noexcept
Returns the threshold size.
long busies() const noexcept
Returns the number of pointers currently stored.
bool is_valid_index(long i) const noexcept
Checks if an index is within valid bounds.
long threshold_size
Minimum size to maintain (prevents excessive shrinking)
long allocate_above_heap()
Allocates an index from the free table.
bool is_empty() const noexcept
Checks if the table is empty.
long get_heap_index() const noexcept
Returns the current heap index (high water mark).
long size() const noexcept
Returns the current capacity of the pointer table.
static constexpr long Null_Index
Sentinel value indicating an invalid or null index.
DynArray< void * > pointer_table
Array mapping indices to pointers.
long insert_pointer(void *ptr)
Inserts a pointer and returns its assigned index.
DynArray< long > free_table
Stack of available indices for reuse.
bool pointer_matches_with_index(long i, const void *ptr) const noexcept
Checks if a pointer matches the one stored at an index.
void insert_in_free_table(long i)
Adds an index to the free table for future reuse.
Pointer_Table(size_t initial_size=0)
Constructs a Pointer_Table with optional initial capacity.
long heap_index
Next available index at the heap top.
void clear()
Clears all pointers from the table.
void * get_pointer(long i) const
Retrieves the pointer at the given index.
void cleanup_free_table(long new_heap_index)
Removes indices from free_table that are >= new_heap_index.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Lazy and scalable dynamic array implementation.