From 901d7a663766337d4aeecde8962776308ddb0cee Mon Sep 17 00:00:00 2001 From: veradec Date: Thu, 30 Jul 2026 10:36:46 +0530 Subject: [PATCH] fix: readme to update log's implementation --- README.md | 4 ++-- sonuva.c | 40 ++++++++++++++-------------------------- sonuva.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 0180cd7..d583227 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ sonuva is a c helper single header library feat: -[ ] Log -[ ] String Tokenizer +[X] Log (Has three levels of Log levels) +[ ] String Tokenizer [ ] File I/O diff --git a/sonuva.c b/sonuva.c index 288210f..12cf939 100644 --- a/sonuva.c +++ b/sonuva.c @@ -5,44 +5,32 @@ #define SONUVA_IMPLEMENTATION #include "sonuva.h" -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_swap(v, 0, 1); + LOG("Values in Vector"); + for (int i =0; i< v->size; i++) { + printf("%d : %d\n", i, v->arr[i]); } + printf("\n"); + + LOG("Vector Remove", "todo"); /* vec_rem(v, 10); */ + + LOG("Vector Delete", "todo"); /* vec_delete(v, 10); */ + + LOG("Vector purge", "todo"); /* vec_purge(v, 10); */ - /* vec_swap(v, 1, 2); */ + + printf("\n\n\033[31;1;4mTypes of Logs:"); + printf("\n"); LOG("This is a Log"); LOG("This is a Warning", "warn"); LOG("This is a TODO", "todo"); diff --git a/sonuva.h b/sonuva.h index 9ac23e7..d68b1ed 100644 --- a/sonuva.h +++ b/sonuva.h @@ -35,6 +35,60 @@ void LOG2(char *str, char *level) { } } +// Vector + + +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++; +} + + +void vec_swap(Vector *v, int pos1, int pos2) { + int temp = v->arr[pos1]; + v->arr[pos1] = v->arr[pos2]; + v->arr[pos2] = temp; +} + + +// Hashmap + +typedef struct HashMapElem { + char* key, + char* value; +} + +typedef struct HashMap { + size_t size; + size_t capacity; + HashMapElem *arr; +} HashMap; + +void hs_put() {} + +void hs_get() {} + +void