fix: readme to update log's implementation
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user