libstd v0.1.0
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1#ifndef VECTOR_H_
2#define VECTOR_H_
3
4#include <stdbool.h>
5#include <stddef.h>
6
10typedef struct VectorNode {
11 void* data;
12 struct VectorNode* next;
14
18typedef struct Vector {
20 size_t element_size;
21 size_t size;
23
30void vector_init(Vector* vector, size_t element_size);
31
38void vector_destroy(Vector* vector);
39
48bool vector_insert(Vector* vector, const void* data);
49
58bool vector_remove(Vector* vector, size_t index);
59
69bool vector_update(Vector* vector, size_t index, const void* new_data);
70
78void* vector_get(Vector* vector, size_t index);
79
90int vector_search(Vector* vector, int (*cmp_fn)(void*, void*), void* key);
91
98int vector_size(const Vector* vector);
99
108bool vector_sort(Vector* vector, int (*cmp_fn)(void*, void*));
109
110#endif // VECTOR_H_
Node structure representing an element in the vector.
Definition vector.h:10
void * data
Definition vector.h:11
struct VectorNode * next
Definition vector.h:12
Structure representing a generic linked-list-backed Vector.
Definition vector.h:18
size_t element_size
Definition vector.h:20
size_t size
Definition vector.h:21
VectorNode * head
Definition vector.h:19
void vector_destroy(Vector *vector)
Destroys the Vector and frees all allocated nodes and their associated data.
Definition vector.c:39
bool vector_update(Vector *vector, size_t index, const void *new_data)
Updates the element data at a specific index in the vector.
Definition vector.c:109
int vector_search(Vector *vector, int(*cmp_fn)(void *, void *), void *key)
Searches for an element in the vector using a custom comparison function.
Definition vector.c:142
bool vector_remove(Vector *vector, size_t index)
Removes an element at a specific index from the vector.
Definition vector.c:78
void * vector_get(Vector *vector, size_t index)
Retrieves a pointer to the element at a specific index.
Definition vector.c:128
int vector_size(const Vector *vector)
Retrieves the total number of elements currently stored in the vector.
Definition vector.c:162
bool vector_insert(Vector *vector, const void *data)
Appends (inserts) a new element to the end of the vector.
Definition vector.c:61
bool vector_sort(Vector *vector, int(*cmp_fn)(void *, void *))
Sorts the elements in the vector using a comparison function.
Definition vector.c:170
void vector_init(Vector *vector, size_t element_size)
Initializes an empty Vector.
Definition vector.c:29