diff --git a/sonuva.c b/sonuva.c index 37e4326..288210f 100644 --- a/sonuva.c +++ b/sonuva.c @@ -1,11 +1,51 @@ +#include +#include +#include +#include #define SONUVA_IMPLEMENTATION #include "sonuva.h" -int main() -{ +typedef struct Vector { + size_t size; + size_t capacity; + int *arr; +} Vector; + +void vec_push(Vector *v, int value) { + if (v) { + if (v->size >= v->capacity) { + size_t new_capacity = v->capacity * 2; + if(new_capacity == 0) new_capacity = 8; + int *bigger_arr = realloc(v->arr, (sizeof(int) * new_capacity)); + v->arr = bigger_arr; + v->capacity = new_capacity; + } + } else { + v = malloc(sizeof(Vector) * 2); + v->capacity = sizeof(Vector) * 2; + v->size = 0; + } + v->arr[v->size] = value; + v->size++; +} + +int main() { + Vector *v = malloc(sizeof(Vector)); + vec_push(v, 10); + vec_push(v, 20); + for (int i =0; i< v->capacity; i++) { + printf("%d\n", v->arr[i]); + } + /* vec_rem(v, 10); */ + /* vec_delete(v, 10); */ + /* vec_purge(v, 10); */ + /* vec_swap(v, 1, 2); */ + + + LOG("This is a Log"); LOG("This is a Warning", "warn"); LOG("This is a TODO", "todo"); - LOG("HELLO", "fatal"); + LOG("This is a Fatal", "fatal"); return 0; } diff --git a/sonuva.h b/sonuva.h index 6a5a348..9ac23e7 100644 --- a/sonuva.h +++ b/sonuva.h @@ -5,7 +5,6 @@ #include #include - #define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0) #define NARGS_(_5, _4, _3, _2, _1, N, ...) N @@ -38,8 +37,5 @@ void LOG2(char *str, char *level) { + #endif // SONUVA_IMPLEMENTATION - - -/* I took it from stack overflow man stop asking me questions */ -