Examples and fixing stuff

This commit is contained in:
Leonardo Vencovsky committed 2023-01-25 13:35:16 +01:00
1 parent a8c1619be6
commit bd338f2fe3
10 files changed
+42 -47

No files matched your search

+15 -20
View File
@@ -2,36 +2,31 @@ CC=gcc
CFLAGS=-Wall -Wextra -Werror -O3
INCLUDE=-I ../src
dfs: dfs.c
$(CC) $< -o $@.exe $(CFLAGS) $(INCLUDE)
./$@.exe
example: example.c
$(CC) $< -o $@.exe $(CFLAGS) $(INCLUDE)
./$@.exe
hanoi: hanoi.c
$(CC) $< -o $@.exe $(CFLAGS) $(INCLUDE)
./$@.exe
heapsort: heapsort.c
$(CC) $< -o $@.exe $(CFLAGS) $(INCLUDE)
./$@.exe
sieve: sieve.c
ifndef FILE
main:
@echo Please define a FILE parameter to run. Examples:
@echo " dfs"
@echo " example"
@echo " hanoi"
@echo " heapsort"
@echo " ice_cream"
@echo " sieve"
else
$(FILE): $(FILE).c
$(CC) $< -o $@.exe $(CFLAGS) $(INCLUDE)
./$@.exe
endif
clean:
rm *.exe
rm *.txt
rm *.exe -f
rm *.txt -f
memcheck:
ifndef FILE
$(error FILE parameter must be set first to check for leaks)
else
$(CC) $(FILE) -o mem.exe $(CFLAGS) $(INCLUDE) -g
$(CC) $(FILE).c -o mem.exe $(CFLAGS) $(INCLUDE) -g
valgrind --leak-check=yes ./mem.exe
endif
+1 -1
View File
@@ -61,7 +61,7 @@ int main(void)
printf("Stack:\n");
fprintf(stdout, "[ ");
struct Stack *stack = stk_new(100, &(struct StackFVal){ NULL });
struct Stack *stack = stk_new(100, &(struct StackFVal){ 0 });
struct BinaryTreeNode *node = tree->root;
+4 -4
View File
@@ -11,7 +11,7 @@ struct
struct stack *from;
struct stack *aux;
struct stack *to;
} print_aux = { NULL };
} print_aux = { 0 };
void print_stacks()
{
@@ -50,9 +50,9 @@ void hanoi(int n, struct stack *from, struct stack *aux, struct stack *to)
int main()
{
struct stack from = stk_init(10, &(struct stack_fval){ NULL });
struct stack to = stk_init(10, &(struct stack_fval){ NULL });
struct stack aux = stk_init(10, &(struct stack_fval){ NULL });
struct stack from = stk_init(10, &(struct stack_fval){ 0 });
struct stack to = stk_init(10, &(struct stack_fval){ 0 });
struct stack aux = stk_init(10, &(struct stack_fval){ 0 });
for (int i = disks; i >= 1; i--)
stk_push(&from, i);
+6 -6
View File
@@ -48,7 +48,7 @@ struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DE
return NULL;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * load)
if (capacity >= (double)UINTMAX_MAX * load)
return NULL;
if (!f_key || !f_val)
@@ -488,7 +488,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
goto success;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * _map_->load)
if (capacity >= (double)UINTMAX_MAX * _map_->load)
{
_map_->flag = CMC_FLAG_ERROR;
return false;
@@ -526,8 +526,8 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
if (!e1 || !e2)
{
/* Prevent the map from freeing the data */
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ NULL };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ NULL };
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ 0 };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ 0 };
_map_->alloc->free(_new_map_->buffer);
_map_->alloc->free(_new_map_);
@@ -544,8 +544,8 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
if (_map_->count != _new_map_->count)
{
/* Prevent the map from freeing the data */
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ NULL };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ NULL };
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ 0 };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ 0 };
_map_->alloc->free(_new_map_->buffer);
_map_->alloc->free(_new_map_);
+1 -1
View File
@@ -48,7 +48,7 @@ struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DE
return _map_;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * load)
if (capacity >= (double)UINTMAX_MAX * load)
return _map_;
if (!f_key || !f_val)
+4 -4
View File
@@ -42,7 +42,7 @@ struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DE
return NULL;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * load)
if (capacity >= (double)UINTMAX_MAX * load)
return NULL;
if (!f_key || !f_val)
@@ -448,7 +448,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
goto success;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * _map_->load)
if (capacity >= (double)UINTMAX_MAX * _map_->load)
{
_map_->flag = CMC_FLAG_ERROR;
return false;
@@ -504,8 +504,8 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
_new_map_->capacity = tmp_c;
/* Prevent the map from freeing the data */
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ NULL };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ NULL };
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ 0 };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ 0 };
CMC_(PFX, _free)(_new_map_);
+1 -1
View File
@@ -48,7 +48,7 @@ struct SNAME CMC_(PFX, _init_custom)(size_t capacity, double load, struct CMC_DE
return _map_;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * load)
if (capacity >= (double)UINTMAX_MAX * load)
return _map_;
if (!f_key || !f_val)
+4 -4
View File
@@ -44,7 +44,7 @@ struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DE
return NULL;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * load)
if (capacity >= (double)UINTMAX_MAX * load)
return NULL;
if (!f_key || !f_val)
@@ -658,7 +658,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
goto success;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * _map_->load)
if (capacity >= (double)UINTMAX_MAX * _map_->load)
{
_map_->flag = CMC_FLAG_ERROR;
return false;
@@ -714,8 +714,8 @@ bool CMC_(PFX, _resize)(struct SNAME *_map_, size_t capacity)
_new_map_->capacity = tmp_c;
/* Prevent the map from freeing the data */
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ NULL };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ NULL };
_new_map_->f_key = &(struct CMC_DEF_FKEY(SNAME)){ 0 };
_new_map_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ 0 };
CMC_(PFX, _free)(_new_map_);
+3 -3
View File
@@ -41,7 +41,7 @@ struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DE
return NULL;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * load)
if (capacity >= (double)UINTMAX_MAX * load)
return NULL;
if (!f_val)
@@ -443,7 +443,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_set_, size_t capacity)
goto success;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * _set_->load)
if (capacity >= (double)UINTMAX_MAX * _set_->load)
{
_set_->flag = CMC_FLAG_ERROR;
return false;
@@ -500,7 +500,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_set_, size_t capacity)
_new_set_->capacity = tmp_c;
/* Prevent the set from freeing the data */
_new_set_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ NULL };
_new_set_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ 0 };
CMC_(PFX, _free)(_new_set_);
+3 -3
View File
@@ -40,7 +40,7 @@ struct SNAME *CMC_(PFX, _new_custom)(size_t capacity, double load, struct CMC_DE
return NULL;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * load)
if (capacity >= (double)UINTMAX_MAX * load)
return NULL;
if (!f_val)
@@ -346,7 +346,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_set_, size_t capacity)
goto success;
/* Prevent integer overflow */
if (capacity >= UINTMAX_MAX * _set_->load)
if (capacity >= (double)UINTMAX_MAX * _set_->load)
{
_set_->flag = CMC_FLAG_ERROR;
return false;
@@ -400,7 +400,7 @@ bool CMC_(PFX, _resize)(struct SNAME *_set_, size_t capacity)
_new_set_->capacity = tmp_c;
/* Prevent the set from freeing the data */
_new_set_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ NULL };
_new_set_->f_val = &(struct CMC_DEF_FVAL(SNAME)){ 0 };
CMC_(PFX, _free)(_new_set_);