reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1/*
2 * @file vector.h
3 * @brief A minimal vector (resizing array) data type.
4 * @ingroup Utilities
5 *
6 * This is intended to be the simplest way of storing a collection of
7 * pointers that is frequently filled and then completely emptied.
8 *
9 * The corresponding `.c` files are in reactor-c/core/utils/vector
10 *
11 * @author Peter Donovan
12 * @author Soroush Bateni
13 */
14
15#ifndef VECTOR_H
16#define VECTOR_H
17
18#include <stddef.h>
19#include <stdlib.h>
20
29typedef struct vector_t {
37 void** start;
38
46 void** next;
47
55 void** end;
56
66
74 int votes;
76
84vector_t vector_new(size_t initial_capacity);
85
92
100void vector_push(vector_t* v, void* element);
101
110void vector_pushall(vector_t* v, void** array, size_t size);
111
119
134void** vector_at(vector_t* v, size_t idx);
135
143
153
154#endif /* VECTOR_H */
void ** vector_at(vector_t *v, size_t idx)
Return a pointer to where the vector element at 'idx' is stored.
void vector_vote(vector_t *v)
Vote on whether this vector should be given less memory.
vector_t vector_new(size_t initial_capacity)
Allocate and initialize a new vector.
void vector_push(vector_t *v, void *element)
Add the given element to the vector.
void * vector_pop(vector_t *v)
Remove and return some pointer that is contained in the given vector, or return NULL if the given vec...
size_t vector_size(vector_t *v)
Return the size of the vector.
void vector_pushall(vector_t *v, void **array, size_t size)
Add all elements of the given array to the vector.
void vector_free(vector_t *v)
Free the memory held by the given vector, invalidating it.
A vector (resizing array) data type.
Definition vector.h:29
int votes
The number of votes to shrink this vector.
Definition vector.h:74
int votes_required
The number of votes required to shrink this vector.
Definition vector.h:65
void ** next
The element after the last element in the underlying array.
Definition vector.h:46
void ** start
The start of the underlying array.
Definition vector.h:37
void ** end
The end of the underlying array.
Definition vector.h:55