vector.h
| 1 | #ifndef VECTOR_H |
| 2 | #define VECTOR_H |
| 3 | #define VECTOR_DEFAULT_SIZE 4 |
| 4 | #include <stdint.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | #include <stdbool.h> |
| 8 | |
| 9 | typedef struct Vector |
| 10 | { |
| 11 | void** items; |
| 12 | size_t capacity; |
| 13 | size_t length; |
| 14 | } Vector; |
| 15 | |
| 16 | typedef struct FindReturn |
| 17 | { |
| 18 | bool found; |
| 19 | size_t index; //if found is false, this contains rubbish |
| 20 | } FindReturn; |
| 21 | |
| 22 | Vector* new_vector(void); |
| 23 | void* vector_at(const Vector* vector, size_t index); |
| 24 | void* vector_pop(Vector* vector, size_t index); |
| 25 | bool vector_push(Vector* vector, void* item); |
| 26 | void vector_remove(Vector* vector, size_t index); |
| 27 | bool vector_adjust_size(Vector* vector, size_t size); |
| 28 | FindReturn vector_find(const Vector* haystack, const void* needle, bool (*cmp)(const void*, const void*)); |
| 29 | bool vector_insert(Vector* vector, size_t index, void* item); |
| 30 | |
| 31 | |
| 32 | #endif //VECTOR_H |
| 33 |