vector.h

This interface exports an array-like indexed collection type.
Type
Vector This type defines the abstract vector type.
Functions
newVector() Returns an empty Vector.
freeVector(vector) Frees the storage associated with vector.
arrayToVector(array, n) Creates a vector from an array of void * pointers.
vectorToArray(vector) Returns a NULL-terminated array with the same elements as vector.
isEmpty(vector) Returns true if the vector is empty.
size(vector) Returns the number of elements in the vector.
clear(vector) Removes all elements from the vector.
clone(vector) Creates a copy of the vector.
get(vector, index) Gets the element at the specified index position, raising an error if the index is out of range.
set(vector, index, value) Sets the element at the specified index position, raising an error if the index is out of range.
add(vector, value) Adds a new value to the end of the vector.
insert(vector, index, value) Inserts a new value before the specified index position.
remove(vector, index) Deletes the element at the specified index position.

Type detail


typedef struct VectorCDT *Vector;
This type defines the abstract vector type.

Function detail


Vector newVector(void);
Returns an empty Vector.

Usage:

vector = newVector();

void freeVector(Vector vector);
Frees the storage associated with vector.

Usage:

freeVector(vector);

Vector arrayToVector(void *array[], int n);
Creates a vector from an array of void * pointers. If the array argument is NULL, this function returns NULL.

Usage:

vector = arrayToVector(array, n);

void **vectorToArray(Vector vector);
Returns a NULL-terminated array with the same elements as vector. If vector is NULL, this function returns NULL.

Usage:

array = vectorToArray(vector);

bool isEmpty(Vector vector);
Returns true if the vector is empty.

Usage:

if (isEmpty(vector)) . . .

int size(Vector vector);
Returns the number of elements in the vector.

Usage:

n = size(vector);

void clear(Vector vector);
Removes all elements from the vector.

Usage:

clear(vector);

Vector clone(Vector vector);
Creates a copy of the vector. The clone function copies only the first level of the structure and does not copy the individual elements.

Usage:

newvec = clone(vector);

void *get(Vector vector, int index);
Gets the element at the specified index position, raising an error if the index is out of range.

Usage:

value = get(vector, index);

void set(Vector vector, int index, void *value);
Sets the element at the specified index position, raising an error if the index is out of range.

Usage:

set(vector, index, value);

void add(Vector vector, void *value);
Adds a new value to the end of the vector.

Usage:

add(vector, value);

void insert(Vector vector, int index, void *value);
Inserts a new value before the specified index position.

Usage:

insert(vector, index, value);

void remove(Vector vector, int index);
Deletes the element at the specified index position.

Usage:

remove(vector, index);