|
cu
|
#include <stdlib.h>#include <stdbool.h>Go to the source code of this file.
Data Structures | |
| struct | vector_t |
| vector dynamically growing array More... | |
Macros | |
| #define | VECTOR_INIT(N) |
| Initialize a vector_t on the stack. More... | |
| #define | VECTOR_DEL(V, FN) vector_clear(&V, FN); free(V.data); |
| Delete a on stack allocated vector_t. More... | |
Functions | |
| vector_t * | vector_new () |
| Creates a new empty vector of the size 8. More... | |
| vector_t * | vector_with_cap (size_t n) |
| Creates a empty vector of the size n. More... | |
| void | vector_insert (vector_t *v, size_t index, void *data) |
| Insert an element at given position, should the index be greater than the current vector size then the data is pushed to the end. The vector avoids any fragmentation. More... | |
| void | vector_push (vector_t *v, void *data) |
| Appends a element to the vector. More... | |
| size_t | vector_len (const vector_t *v) |
| bool | vector_is_empty (const vector_t *v) |
| void | vector_pop (vector_t *v, void(*df)(void *)) |
| Remove the last element from the vector. More... | |
| void | vector_remove (vector_t *v, size_t index, void(*df)(void *)) |
| Delete a element from the vector. More... | |
| void * | vector_get (const vector_t *v, size_t index) |
| Retrieve the data at given index. More... | |
| void | vector_foreach (const vector_t *v, void(*f)(void *)) |
| Apply the funtion f to every element in the vector. More... | |
| void | vector_del (vector_t *v) |
| Delete the vector and free allocated memory. The elements of the vector will not be freed. More... | |
| void | vector_clear (vector_t *v, void(*df)(void *)) |
| Remove all elements from the vector, in case that df is NULL every entry is set to 0. More... | |
| void | vector_clear_del (vector_t *v, void(*df)(void *)) |
| Remove all elements and free the vector_t. More... | |
| bool | vector_contains (const vector_t *v, const void *key, int(*pred)(const void *, const void *)) |
| Check whether a element is in the vector. for an int created on the stack: return memcmp(a, *(void **)b, sizeof(int32_t)) More... | |
| void * | vector_find (const vector_t *v, const void *key, bool(*pred)(const void *, const void *)) |
| Find an element in given vector. More... | |
| void | vector_sort (vector_t *v, int(*pred)(const void *, const void *)) |
| Sort the vector with quicksort. More... | |
| #define VECTOR_DEL | ( | V, | |
| FN | |||
| ) | vector_clear(&V, FN); free(V.data); |
Delete a on stack allocated vector_t.
| #define VECTOR_INIT | ( | N | ) |
Initialize a vector_t on the stack.
| N | size of the vector |
| void vector_clear | ( | vector_t * | v, |
| void(*)(void *) | df | ||
| ) |
Remove all elements from the vector, in case that df is NULL every entry is set to 0.
| v | vector to clear |
| df | deleting function for heap allocated data |
| void vector_clear_del | ( | vector_t * | v, |
| void(*)(void *) | df | ||
| ) |
| bool vector_contains | ( | const vector_t * | v, |
| const void * | key, | ||
| int(*)(const void *, const void *) | pred | ||
| ) |
Check whether a element is in the vector. for an int created on the stack: return memcmp(a, *(void **)b, sizeof(int32_t))
| v | vector to search |
| key | item to find |
| pred | predicate function |
| void vector_del | ( | vector_t * | v | ) |
Delete the vector and free allocated memory. The elements of the vector will not be freed.
| v | vector to delete |
| void* vector_find | ( | const vector_t * | v, |
| const void * | key, | ||
| bool(*)(const void *, const void *) | pred | ||
| ) |
Find an element in given vector.
| v | vector to search |
| key | key property |
| pred | predicate function |
| void vector_foreach | ( | const vector_t * | v, |
| void(*)(void *) | f | ||
| ) |
Apply the funtion f to every element in the vector.
| list | vector to operate on |
| f | function to apply |
| void* vector_get | ( | const vector_t * | v, |
| size_t | index | ||
| ) |
Retrieve the data at given index.
| list | fetch the data of this arrayList |
| i | index to fetch |
| void vector_insert | ( | vector_t * | v, |
| size_t | index, | ||
| void * | data | ||
| ) |
Insert an element at given position, should the index be greater than the current vector size then the data is pushed to the end. The vector avoids any fragmentation.
| v | vector |
| index | position to insert |
| data | data to insert |
| bool vector_is_empty | ( | const vector_t * | v | ) |
Check whether the vector is empty
| v | vector |
| size_t vector_len | ( | const vector_t * | v | ) |
| vector_t* vector_new | ( | ) |
| void vector_pop | ( | vector_t * | v, |
| void(*)(void *) | df | ||
| ) |
Remove the last element from the vector.
| v | vector to remove the element from |
| df | function to free the data, if NULL is passed it is ignored |
| void vector_push | ( | vector_t * | v, |
| void * | data | ||
| ) |
Appends a element to the vector.
| v | arrayList to which the data should be appended |
| Data | to add |
| void vector_remove | ( | vector_t * | v, |
| size_t | index, | ||
| void(*)(void *) | df | ||
| ) |
Delete a element from the vector.
| v | vector |
| index | of the element to remove |
| df | deleting function for the given element. df is ignored if NULL |
| void vector_sort | ( | vector_t * | v, |
| int(*)(const void *, const void *) | pred | ||
| ) |
Sort the vector with quicksort.
| v | vector to sort |
| pred | predicate function |
| vector_t* vector_with_cap | ( | size_t | n | ) |
Creates a empty vector of the size n.
| n | size of the empty array |
| returns | a new vector |