Code cleanup, implement LL_ITER macro
This commit is contained in:
@ -11,18 +11,26 @@ typedef struct {
|
||||
int size;
|
||||
|
||||
int (*compare)(const void *a, const void *b);
|
||||
|
||||
void (*destroy)(void *data);
|
||||
|
||||
struct BinTreeNode *root;
|
||||
} BinTree;
|
||||
|
||||
void bintree_init(BinTree *tree, void (*destroy)(void *data));
|
||||
|
||||
void bintree_destroy(BinTree *tree);
|
||||
|
||||
int bintree_ins_left(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_right(BinTree *tree, BinTreeNode *node);
|
||||
|
||||
int bintree_merge(BinTree *merge, BinTree *left, BinTree *right, void *data);
|
||||
|
||||
void bintree_debug_print(BinTree *tree);
|
||||
|
||||
#define bintree_is_eob(node) ((node) == NULL)
|
||||
|
@ -4,10 +4,15 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
char *get_input(const char *);
|
||||
|
||||
char **split(char *, size_t *, const char *);
|
||||
|
||||
char **get_lines(const char *, size_t *);
|
||||
|
||||
int *get_ints(const char *, size_t *);
|
||||
|
||||
void del_split(char **);
|
||||
|
||||
void del_lines(char **);
|
||||
|
||||
#endif // LIBFLINT_INPUT_H
|
||||
|
@ -4,27 +4,37 @@
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct ListNode {
|
||||
void* data;
|
||||
struct ListNode* next;
|
||||
struct ListNode* prev;
|
||||
void *data;
|
||||
struct ListNode *next;
|
||||
struct ListNode *prev;
|
||||
} ListNode;
|
||||
|
||||
typedef struct {
|
||||
size_t size;
|
||||
|
||||
void (*destroy)(void* data);
|
||||
int (*match)(const void* a, const void* b);
|
||||
void (*destroy)(void *data);
|
||||
|
||||
struct ListNode* head;
|
||||
struct ListNode* tail;
|
||||
int (*match)(const void *a, const void *b);
|
||||
|
||||
struct ListNode *head;
|
||||
struct ListNode *tail;
|
||||
} List;
|
||||
|
||||
void ll_init(List* list, void (*destroy)(void *data));
|
||||
void ll_destroy(List* list);
|
||||
int ll_ins_next(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_next(List* list, ListNode* node, void** data);
|
||||
int ll_remove_prev(List* list, ListNode* node, void** data);
|
||||
void ll_init(List *list, void (*destroy)(void *data));
|
||||
|
||||
void ll_destroy(List *list);
|
||||
|
||||
int ll_ins_next(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_next(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
|
||||
|
@ -2,8 +2,11 @@
|
||||
#define LIBFLINT_H_MATH
|
||||
|
||||
int max_int(int a, int b);
|
||||
|
||||
int min_int(int a, int b);
|
||||
|
||||
int clamp_int(int i, int low, int high);
|
||||
|
||||
int binstr_to_int(const char *s);
|
||||
|
||||
#endif // LIBFLINT_H_MATH
|
||||
|
@ -5,16 +5,25 @@
|
||||
|
||||
#define Set List
|
||||
|
||||
void set_init(Set* set, int (*match)(const void* a, const void* b),
|
||||
void (*destroy)(void* data));
|
||||
void set_destroy(Set* set);
|
||||
int set_insert(Set* set, const void* data);
|
||||
int set_remove(Set* set, void** data);
|
||||
int set_union(Set* setu, 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_is_member(const Set* set, const void* data);
|
||||
int set_is_subset(const Set* a, const Set* b);
|
||||
int set_is_equal(const Set* a, const Set* b);
|
||||
void set_init(Set *set, int (*match)(const void *a, const void *b),
|
||||
void (*destroy)(void *data));
|
||||
|
||||
void set_destroy(Set *set);
|
||||
|
||||
int set_insert(Set *set, const void *data);
|
||||
|
||||
int set_remove(Set *set, void **data);
|
||||
|
||||
int set_union(Set *setu, 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_is_member(const Set *set, const void *data);
|
||||
|
||||
int set_is_subset(const Set *a, const Set *b);
|
||||
|
||||
int set_is_equal(const Set *a, const Set *b);
|
||||
|
||||
#endif
|
||||
|
@ -5,10 +5,14 @@
|
||||
|
||||
#define Stack List
|
||||
|
||||
void stack_init(Stack* stack, void (*destroy)(void* data));
|
||||
void stack_destroy(Stack* stack);
|
||||
int stack_push(Stack* stack, void *data);
|
||||
void stack_init(Stack *stack, void (*destroy)(void *data));
|
||||
|
||||
void stack_destroy(Stack *stack);
|
||||
|
||||
int stack_push(Stack *stack, void *data);
|
||||
|
||||
void *stack_peek(Stack *stack);
|
||||
|
||||
int stack_pop(Stack *stack, void **data);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user