#include <stdbool.h>
#include <stddef.h>
Go to the source code of this file.
|
| void | vector_init (Vector *vector, size_t element_size) |
| | Initializes an empty Vector.
|
| |
| void | vector_destroy (Vector *vector) |
| | Destroys the Vector and frees all allocated nodes and their associated data.
|
| |
| bool | vector_insert (Vector *vector, const void *data) |
| | Appends (inserts) a new element to the end of the vector.
|
| |
| bool | vector_remove (Vector *vector, size_t index) |
| | Removes an element at a specific index from the vector.
|
| |
| bool | vector_update (Vector *vector, size_t index, const void *new_data) |
| | Updates the element data at a specific index in the vector.
|
| |
| void * | vector_get (Vector *vector, size_t index) |
| | Retrieves a pointer to the element at a specific index.
|
| |
| int | vector_search (Vector *vector, int(*cmp_fn)(void *, void *), void *key) |
| | Searches for an element in the vector using a custom comparison function.
|
| |
| int | vector_size (const Vector *vector) |
| | Retrieves the total number of elements currently stored in the vector.
|
| |
| bool | vector_sort (Vector *vector, int(*cmp_fn)(void *, void *)) |
| | Sorts the elements in the vector using a comparison function.
|
| |
◆ Vector
Structure representing a generic linked-list-backed Vector.
◆ VectorNode
Node structure representing an element in the vector.
◆ vector_destroy()
| void vector_destroy |
( |
Vector * |
vector | ) |
|
Destroys the Vector and frees all allocated nodes and their associated data.
- Parameters
-
| vector | Pointer to the Vector to destroy. |
◆ vector_get()
| void * vector_get |
( |
Vector * |
vector, |
|
|
size_t |
index |
|
) |
| |
Retrieves a pointer to the element at a specific index.
- Parameters
-
| vector | Pointer to the Vector. |
| index | Zero-based position of the element to retrieve. |
- Returns
- Pointer to the stored data, or NULL if index is out of bounds.
◆ vector_init()
| void vector_init |
( |
Vector * |
vector, |
|
|
size_t |
element_size |
|
) |
| |
Initializes an empty Vector.
- Parameters
-
| vector | Pointer to the Vector structure to initialize. |
| element_size | Size of each element in bytes. |
◆ vector_insert()
| bool vector_insert |
( |
Vector * |
vector, |
|
|
const void * |
data |
|
) |
| |
Appends (inserts) a new element to the end of the vector.
- Parameters
-
| vector | Pointer to the Vector. |
| data | Pointer to the element data to insert. |
- Returns
true if insertion was successful, or false on memory allocation failure.
◆ vector_remove()
| bool vector_remove |
( |
Vector * |
vector, |
|
|
size_t |
index |
|
) |
| |
Removes an element at a specific index from the vector.
- Parameters
-
| vector | Pointer to the Vector. |
| index | Zero-based position of the element to remove. |
- Returns
true if the element was successfully removed, or false if index is out of bounds.
◆ vector_search()
| int vector_search |
( |
Vector * |
vector, |
|
|
int(*)(void *, void *) |
cmp_fn, |
|
|
void * |
key |
|
) |
| |
Searches for an element in the vector using a custom comparison function.
- Parameters
-
| vector | Pointer to the Vector. |
| cmp_fn | Pointer to the comparison function (should return 0 when elements match). |
| key | Pointer to the value/key being searched for. |
- Returns
- Zero-based index of the element if found, or -1 if not found.
◆ vector_size()
| int vector_size |
( |
const Vector * |
vector | ) |
|
Retrieves the total number of elements currently stored in the vector.
- Parameters
-
- Returns
- Total number of elements.
◆ vector_sort()
| bool vector_sort |
( |
Vector * |
vector, |
|
|
int(*)(void *, void *) |
cmp_fn |
|
) |
| |
Sorts the elements in the vector using a comparison function.
- Parameters
-
| vector | Pointer to the Vector. |
| cmp_fn | Pointer to the comparison function defining the sort order (e.g., returns < 0 if a < b, 0 if a == b, > 0 if a > b). |
- Returns
true if sorting succeeded, or false if the operation failed.
◆ vector_update()
| bool vector_update |
( |
Vector * |
vector, |
|
|
size_t |
index, |
|
|
const void * |
new_data |
|
) |
| |
Updates the element data at a specific index in the vector.
- Parameters
-
| vector | Pointer to the Vector. |
| index | Zero-based position of the element to update. |
| new_data | Pointer to the new data to be copied into the vector. |
- Returns
true if the element was successfully updated, or false if index is out of bounds.