Code cleanup, implement LL_ITER macro

This commit is contained in:
Evan Burkey 2022-03-28 10:52:16 -07:00
parent 91e2ac1994
commit 8b2a459252
14 changed files with 136 additions and 94 deletions

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
flint

View File

@ -11,18 +11,26 @@ typedef struct {
int size; int size;
int (*compare)(const void *a, const void *b); int (*compare)(const void *a, const void *b);
void (*destroy)(void *data); void (*destroy)(void *data);
struct BinTreeNode *root; struct BinTreeNode *root;
} BinTree; } BinTree;
void bintree_init(BinTree *tree, void (*destroy)(void *data)); void bintree_init(BinTree *tree, void (*destroy)(void *data));
void bintree_destroy(BinTree *tree); void bintree_destroy(BinTree *tree);
int bintree_ins_left(BinTree *tree, BinTreeNode *node, void *data); int bintree_ins_left(BinTree *tree, BinTreeNode *node, void *data);
int bintree_ins_right(BinTree *tree, BinTreeNode *node, void *data); int bintree_ins_right(BinTree *tree, BinTreeNode *node, void *data);
void bintree_rem_left(BinTree *tree, BinTreeNode *node); void bintree_rem_left(BinTree *tree, BinTreeNode *node);
void bintree_rem_right(BinTree *tree, BinTreeNode *node); void bintree_rem_right(BinTree *tree, BinTreeNode *node);
int bintree_merge(BinTree *merge, BinTree *left, BinTree *right, void *data); int bintree_merge(BinTree *merge, BinTree *left, BinTree *right, void *data);
void bintree_debug_print(BinTree *tree); void bintree_debug_print(BinTree *tree);
#define bintree_is_eob(node) ((node) == NULL) #define bintree_is_eob(node) ((node) == NULL)

View File

@ -4,10 +4,15 @@
#include <stdlib.h> #include <stdlib.h>
char *get_input(const char *); char *get_input(const char *);
char **split(char *, size_t *, const char *); char **split(char *, size_t *, const char *);
char **get_lines(const char *, size_t *); char **get_lines(const char *, size_t *);
int *get_ints(const char *, size_t *); int *get_ints(const char *, size_t *);
void del_split(char **); void del_split(char **);
void del_lines(char **); void del_lines(char **);
#endif // LIBFLINT_INPUT_H #endif // LIBFLINT_INPUT_H

View File

@ -13,6 +13,7 @@ typedef struct {
size_t size; size_t size;
void (*destroy)(void *data); void (*destroy)(void *data);
int (*match)(const void *a, const void *b); int (*match)(const void *a, const void *b);
struct ListNode *head; struct ListNode *head;
@ -20,11 +21,20 @@ typedef struct {
} List; } List;
void ll_init(List *list, void (*destroy)(void *data)); void ll_init(List *list, void (*destroy)(void *data));
void ll_destroy(List *list); void ll_destroy(List *list);
int ll_ins_next(List *list, ListNode *node, const void *data); int ll_ins_next(List *list, ListNode *node, const void *data);
int ll_ins_prev(List *list, ListNode *node, const void *data); int ll_ins_prev(List *list, ListNode *node, const void *data);
int ll_remove(List *list, ListNode *node, void **data); int ll_remove(List *list, ListNode *node, void **data);
int ll_remove_next(List *list, ListNode *node, void **data); int ll_remove_next(List *list, ListNode *node, void **data);
int ll_remove_prev(List *list, ListNode *node, void **data); int ll_remove_prev(List *list, ListNode *node, void **data);
/* Provides ListNode *node for the iteration loop */
#define LL_ITER(list) for(ListNode *node = (list)->head; node != NULL; node = node->next)
#endif #endif

View File

@ -2,8 +2,11 @@
#define LIBFLINT_H_MATH #define LIBFLINT_H_MATH
int max_int(int a, int b); int max_int(int a, int b);
int min_int(int a, int b); int min_int(int a, int b);
int clamp_int(int i, int low, int high); int clamp_int(int i, int low, int high);
int binstr_to_int(const char *s); int binstr_to_int(const char *s);
#endif // LIBFLINT_H_MATH #endif // LIBFLINT_H_MATH

View File

@ -7,14 +7,23 @@
void set_init(Set *set, int (*match)(const void *a, const void *b), void set_init(Set *set, int (*match)(const void *a, const void *b),
void (*destroy)(void *data)); void (*destroy)(void *data));
void set_destroy(Set *set); void set_destroy(Set *set);
int set_insert(Set *set, const void *data); int set_insert(Set *set, const void *data);
int set_remove(Set *set, void **data); int set_remove(Set *set, void **data);
int set_union(Set *setu, const Set *a, const Set *b); int set_union(Set *setu, const Set *a, const Set *b);
int set_intersection(Set *seti, const Set *a, const Set *b); int set_intersection(Set *seti, const Set *a, const Set *b);
int set_difference(Set *setd, const Set *a, const Set *b); int set_difference(Set *setd, const Set *a, const Set *b);
int set_is_member(const Set *set, const void *data); int set_is_member(const Set *set, const void *data);
int set_is_subset(const Set *a, const Set *b); int set_is_subset(const Set *a, const Set *b);
int set_is_equal(const Set *a, const Set *b); int set_is_equal(const Set *a, const Set *b);
#endif #endif

View File

@ -6,9 +6,13 @@
#define Stack List #define Stack List
void stack_init(Stack *stack, void (*destroy)(void *data)); void stack_init(Stack *stack, void (*destroy)(void *data));
void stack_destroy(Stack *stack); void stack_destroy(Stack *stack);
int stack_push(Stack *stack, void *data); int stack_push(Stack *stack, void *data);
void *stack_peek(Stack *stack); void *stack_peek(Stack *stack);
int stack_pop(Stack *stack, void **data); int stack_pop(Stack *stack, void **data);
#endif #endif

View File

@ -4,7 +4,9 @@
#include <limits.h> #include <limits.h>
#ifdef __linux__ #ifdef __linux__
#include <bsd/stdlib.h> #include <bsd/stdlib.h>
#endif #endif
#include "lfinput.h" #include "lfinput.h"

View File

@ -8,7 +8,7 @@
#include "lfmath.h" #include "lfmath.h"
void print_ll(List *list) { void print_ll(List *list) {
for (ListNode* node = list->head; node != NULL; node = node->next) { LL_ITER(list) {
printf(" %d", *((int *) node->data)); printf(" %d", *((int *) node->data));
} }
printf("\n"); printf("\n");