reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
vector.h File Reference
#include <stddef.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  vector_t
 

Typedefs

typedef struct vector_t vector_t
 

Functions

vector_t vector_new (size_t initial_capacity)
 
void vector_free (vector_t *v)
 
void vector_push (vector_t *v, void *element)
 
void vector_pushall (vector_t *v, void **array, size_t size)
 
void * vector_pop (vector_t *v)
 
void ** vector_at (vector_t *v, size_t idx)
 
size_t vector_size (vector_t *v)
 Return the size of the vector.
 
void vector_vote (vector_t *v)
 

Typedef Documentation

◆ vector_t

typedef struct vector_t vector_t

Function Documentation

◆ vector_at()

void ** vector_at ( vector_t * v,
size_t idx )

Return a pointer to where the vector element at 'idx' is stored. This can be used to set the value of the element or to read it. If the index is past the end of the vector, then the vector is automatically expanded and filled with NULL pointers as needed. If no element at idx has been previously set, then the value pointed to by the returned pointer will be NULL.

Parameters
vThe vector.
idxThe index into the vector.
Returns
A pointer to the element at 'idx', which is itself a pointer.

◆ vector_free()

void vector_free ( vector_t * v)

Free the memory held by the given vector, invalidating it.

Parameters
vAny vector.

◆ vector_new()

vector_t vector_new ( size_t initial_capacity)

Allocate and initialize a new vector.

Parameters
initial_capacityThe desired initial capacity to allocate. Must be more than 0

Allocate and initialize a new vector.

Parameters
initial_capacityThe desired initial capacity to allocate.

◆ vector_pop()

void * vector_pop ( vector_t * v)

Remove and return some pointer that is contained in the given vector, or return NULL if the given vector is empty.

Parameters
vAny vector.

◆ vector_push()

void vector_push ( vector_t * v,
void * element )

Add the given element to the vector. The given element should be non-null.

Parameters
vA vector that is to grow.
elementAn element that the vector should contain.

Add the given element to the vector.

Parameters
vA vector that is to grow.
elementAn element that the vector should contain.

◆ vector_pushall()

void vector_pushall ( vector_t * v,
void ** array,
size_t size )

Add all elements of the given array to the vector. Elements should be non-null.

Parameters
vA vector that is to grow.
arrayAn array of items to be added to the vector.
sizeThe size of the given array.

◆ vector_size()

size_t vector_size ( vector_t * v)

Return the size of the vector.

Parameters
vAny vector
Returns
size_t The size of the vector.

◆ vector_vote()

void vector_vote ( vector_t * v)

Vote on whether this vector should be given less memory. If v contains few elements, it becomes more likely to shrink.

It is suggested that this function be called when the number of elements in v reaches a local maximum.

Parameters
vAny vector.