Loading src/bst.c +24 −0 Changes for src/bst.c: 24 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #define gauche left #define droite right struct node_t { unsigned long int key; void* val; Loading @@ -15,12 +21,30 @@ typedef struct bst_t { } bst_t; bst_t bst_empty(void){ bst_t t; t.size = 0; t.tree = NULL; return t; } int bst_is_empty(bst_t t){ return t.tree == NULL; } bst_t bst_add(bst_t t, void* x){ struct node_t* arbre = malloc(sizeof(struct node_t)); arbre->val = x; arbre->left = NULL; arbre->right = NULL; if(bst_is_empty(t)) { t.size = 1; t.tree = arbre; } while(t.tree->gauche != NULL || t.tree->droite ) { } } void bst_destroy(bst_t t, void (*free_void)(void*)){ Loading src/bst.h +3 −0 Changes for src/bst.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #ifndef __BST__ #define __BST__ Loading src/hash_tbl.h +1 −1 Changes for src/hash_tbl.h: 1 added line, 1 removed line. Original line number Diff line number Diff line #ifndef __HASH_TBL__ #define __HASH_TBL__ #include "linked_list.h" #include "list.h" struct hash_tbl { size_t (*h)(void*); Loading src/list.c +48 −1 Changes for src/list.c: 48 added lines, 1 removed line. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> struct cell_t { void* val; unsigned long int id; Loading @@ -6,31 +9,75 @@ struct cell_t { typedef struct cell_t* list_t; #define suivant next #define null NULL list_t list_empty(){ return NULL; } int list_is_empty(list_t l){ return l == NULL; } list_t list_push(list_t l, void* x){ list_t l2 = malloc(sizeof(list_t)); l2->val = x; l2->next = l; if(l == NULL) l2->id = 1; else l2->id = l->id+1; return l2; } list_t list_tail(list_t l){ if(list_is_empty(l)) return NULL; return l->next; } void* list_pop(list_t* l){ if(list_is_empty(*l)) return NULL; list_t tmp = *l; void* x = tmp->val; *l = tmp->next; free(tmp); return x; } void* list_top(list_t l){ if(l==NULL) return NULL; return l->val; } void list_destroy(list_t l, void (*free)(void*)){ void list_destroy(list_t l, void (*free_void)(void*)){ if(l != NULL) { list_t tmp = l->next; while(tmp != NULL) { free_void(l->val); free(l); l = tmp; tmp = l->next; } free_void(l->val); free(l); } } // return the found element or NULL void* list_in(list_t l, void* x, int (*eq)(void*, void*)){ if(l == NULL) return NULL; list_t tmp = l; while(!eq(tmp->val,x) && tmp->next != NULL) { tmp = tmp->next; } if(eq(tmp->val, x)) return x; return NULL; } unsigned long int list_len(list_t l){ if(l == NULL) return 0; return l->id; } src/list.h +4 −1 Changes for src/list.h: 4 added lines, 1 removed line. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #ifndef __LIST__ #define __LIST__ Loading @@ -15,7 +18,7 @@ list_t list_push(list_t, void*); list_t list_tail(list_t); void* list_pop(list_t*); void* list_top(list_t); void list_destroy(list_t, void (*free)(void*)); void list_destroy(list_t, void (*free_void)(void*)); void* list_in(list_t, void*, int (*eq)(void*, void*)); unsigned long int list_len(list_t); Loading Loading
src/bst.c +24 −0 Changes for src/bst.c: 24 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #define gauche left #define droite right struct node_t { unsigned long int key; void* val; Loading @@ -15,12 +21,30 @@ typedef struct bst_t { } bst_t; bst_t bst_empty(void){ bst_t t; t.size = 0; t.tree = NULL; return t; } int bst_is_empty(bst_t t){ return t.tree == NULL; } bst_t bst_add(bst_t t, void* x){ struct node_t* arbre = malloc(sizeof(struct node_t)); arbre->val = x; arbre->left = NULL; arbre->right = NULL; if(bst_is_empty(t)) { t.size = 1; t.tree = arbre; } while(t.tree->gauche != NULL || t.tree->droite ) { } } void bst_destroy(bst_t t, void (*free_void)(void*)){ Loading
src/bst.h +3 −0 Changes for src/bst.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #ifndef __BST__ #define __BST__ Loading
src/hash_tbl.h +1 −1 Changes for src/hash_tbl.h: 1 added line, 1 removed line. Original line number Diff line number Diff line #ifndef __HASH_TBL__ #define __HASH_TBL__ #include "linked_list.h" #include "list.h" struct hash_tbl { size_t (*h)(void*); Loading
src/list.c +48 −1 Changes for src/list.c: 48 added lines, 1 removed line. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> struct cell_t { void* val; unsigned long int id; Loading @@ -6,31 +9,75 @@ struct cell_t { typedef struct cell_t* list_t; #define suivant next #define null NULL list_t list_empty(){ return NULL; } int list_is_empty(list_t l){ return l == NULL; } list_t list_push(list_t l, void* x){ list_t l2 = malloc(sizeof(list_t)); l2->val = x; l2->next = l; if(l == NULL) l2->id = 1; else l2->id = l->id+1; return l2; } list_t list_tail(list_t l){ if(list_is_empty(l)) return NULL; return l->next; } void* list_pop(list_t* l){ if(list_is_empty(*l)) return NULL; list_t tmp = *l; void* x = tmp->val; *l = tmp->next; free(tmp); return x; } void* list_top(list_t l){ if(l==NULL) return NULL; return l->val; } void list_destroy(list_t l, void (*free)(void*)){ void list_destroy(list_t l, void (*free_void)(void*)){ if(l != NULL) { list_t tmp = l->next; while(tmp != NULL) { free_void(l->val); free(l); l = tmp; tmp = l->next; } free_void(l->val); free(l); } } // return the found element or NULL void* list_in(list_t l, void* x, int (*eq)(void*, void*)){ if(l == NULL) return NULL; list_t tmp = l; while(!eq(tmp->val,x) && tmp->next != NULL) { tmp = tmp->next; } if(eq(tmp->val, x)) return x; return NULL; } unsigned long int list_len(list_t l){ if(l == NULL) return 0; return l->id; }
src/list.h +4 −1 Changes for src/list.h: 4 added lines, 1 removed line. Original line number Diff line number Diff line #include <stdio.h> #include <stdlib.h> #ifndef __LIST__ #define __LIST__ Loading @@ -15,7 +18,7 @@ list_t list_push(list_t, void*); list_t list_tail(list_t); void* list_pop(list_t*); void* list_top(list_t); void list_destroy(list_t, void (*free)(void*)); void list_destroy(list_t, void (*free_void)(void*)); void* list_in(list_t, void*, int (*eq)(void*, void*)); unsigned long int list_len(list_t); Loading