DynArray

Dynamic array.

This is a simple dynamic array implementation. D dynamic arrays can't be used because they rely on the GC, and we are implementing the GC.

Members

Functions

Invariant
void Invariant()

Check the structure invariant.

append
T* append(T x)

Append a copy of the element x at the end of the array.

capacity
size_t capacity()

Get the array capacity.

elements_sizeof
size_t elements_sizeof()

Get the total ammount of bytes the elements consumes (capacity included).

free
void free()

Remove all the elements of the array and set the capacity to 0.

insert_sorted
T* insert_sorted(T x)

Insert an element preserving the array sorted.

length
size_t length()

Get the array size.

opIndex
T opIndex(size_t i)

Access an element by index.

ptr
T* ptr()

Get the pointer to the array's data.

remove
bool remove(T x)

Remove the first occurrence of the element x from the array.

remove_at
void remove_at(size_t pos)

Remove the element at position pos.

resize
bool resize(size_t new_capacity)

Change the current capacity of the array to new_capacity.

Meta