Loading src/list.c +31 −3 Changes for src/list.c: 31 added lines, 3 removed lines. Original line number Diff line number Diff line #include <stdlib.h> struct cell_t { void* val; unsigned long int id;//taille de la liste Loading @@ -8,8 +10,7 @@ typedef struct cell_t* list_t; //renvoie une liste vide list_t list_empty(){ list_t * l = NULL; return l; return NULL; } //verifie si la liste est vide Loading @@ -19,31 +20,58 @@ int list_is_empty(list_t l){ // list_t list_push(list_t l, void* x){ list_t ret = malloc(sizeof(struct cell_t)); if(list_is_empty(l)) ret->id = 1; else ret->id = l->id + 1; ret->val = x; ret->next = l; return ret; } //l=(x:xs) //renvoie la queue xs de la liste list_t list_tail(list_t l){ return l->next; } //renvoie x et modifie l tel que l=xs void* list_pop(list_t* l){ void* ret = (*l)->val; list_t tmp = (*l)->next; free(*l); *l = tmp; return ret; } //renvoie x void* list_top(list_t l){ return l->val; } //detruire l void list_destroy(list_t l, void (*free)(void*)){ void list_destroy(list_t l, void (*free_void)(void*)){ if(!list_is_empty(l)) free_void(list_pop(&l)); } // return the found element or NULL //recherche l'element x void* list_in(list_t l, void* x, int (*eq)(void*, void*)){ while(!list_is_empty(l)){ if(l->val == x) return l; l=l->next; } return NULL; } // unsigned long int list_len(list_t l){ if(list_is_empty(l)) return 0; else return l->id; } tests/bignum_tests.c +2 −2 Changes for tests/bignum_tests.c: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ #define BG(n) bignum_from_int(n) /*void test_arithmetic(){ void test_arithmetic(){ assert(bignum_eq(bignum_add(BG(3), BG(4)), BG(7))); assert(bignum_eq(bignum_sub(BG(4), BG(3)), BG(1))); assert(bignum_eq(bignum_mul(BG(4), BG(3)), BG(12))); Loading Loading @@ -43,4 +43,4 @@ int main(){ return 0; } */ tests/exemple_collision.c +2 −2 Changes for tests/exemple_collision.c: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ #include <openssl/md5.h> #include "list.h" /*typedef struct pair_t { typedef struct pair_t { char x[8]; unsigned char h; }* pair_t; Loading Loading @@ -48,4 +48,4 @@ int main(){ } } } */ tests/list_tests.c +7 −6 Changes for tests/list_tests.c: 7 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ void test_emptyness() { printf("test_emptyness OK\n"); } /*void destroy(void* x){ void destroy(void* x){ bignum_destroy((bignum_t) x); } Loading Loading @@ -84,6 +84,7 @@ void test_pop(){ printf("test_pop OK\n"); } void test_in_list(){ bignum_t x,y,z; list_t l; Loading @@ -106,15 +107,15 @@ void test_in_list(){ list_destroy(l, &destroy); printf("test_in_list OK\n"); } */ int main() { printf("=== LIST tests ===\n"); test_emptyness(); //test_push(); //test_top(); //test_pop(); //test_in_list(); test_push(); test_top(); test_pop(); test_in_list(); return 0; } Loading
src/list.c +31 −3 Changes for src/list.c: 31 added lines, 3 removed lines. Original line number Diff line number Diff line #include <stdlib.h> struct cell_t { void* val; unsigned long int id;//taille de la liste Loading @@ -8,8 +10,7 @@ typedef struct cell_t* list_t; //renvoie une liste vide list_t list_empty(){ list_t * l = NULL; return l; return NULL; } //verifie si la liste est vide Loading @@ -19,31 +20,58 @@ int list_is_empty(list_t l){ // list_t list_push(list_t l, void* x){ list_t ret = malloc(sizeof(struct cell_t)); if(list_is_empty(l)) ret->id = 1; else ret->id = l->id + 1; ret->val = x; ret->next = l; return ret; } //l=(x:xs) //renvoie la queue xs de la liste list_t list_tail(list_t l){ return l->next; } //renvoie x et modifie l tel que l=xs void* list_pop(list_t* l){ void* ret = (*l)->val; list_t tmp = (*l)->next; free(*l); *l = tmp; return ret; } //renvoie x void* list_top(list_t l){ return l->val; } //detruire l void list_destroy(list_t l, void (*free)(void*)){ void list_destroy(list_t l, void (*free_void)(void*)){ if(!list_is_empty(l)) free_void(list_pop(&l)); } // return the found element or NULL //recherche l'element x void* list_in(list_t l, void* x, int (*eq)(void*, void*)){ while(!list_is_empty(l)){ if(l->val == x) return l; l=l->next; } return NULL; } // unsigned long int list_len(list_t l){ if(list_is_empty(l)) return 0; else return l->id; }
tests/bignum_tests.c +2 −2 Changes for tests/bignum_tests.c: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ #define BG(n) bignum_from_int(n) /*void test_arithmetic(){ void test_arithmetic(){ assert(bignum_eq(bignum_add(BG(3), BG(4)), BG(7))); assert(bignum_eq(bignum_sub(BG(4), BG(3)), BG(1))); assert(bignum_eq(bignum_mul(BG(4), BG(3)), BG(12))); Loading Loading @@ -43,4 +43,4 @@ int main(){ return 0; } */
tests/exemple_collision.c +2 −2 Changes for tests/exemple_collision.c: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ #include <openssl/md5.h> #include "list.h" /*typedef struct pair_t { typedef struct pair_t { char x[8]; unsigned char h; }* pair_t; Loading Loading @@ -48,4 +48,4 @@ int main(){ } } } */
tests/list_tests.c +7 −6 Changes for tests/list_tests.c: 7 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ void test_emptyness() { printf("test_emptyness OK\n"); } /*void destroy(void* x){ void destroy(void* x){ bignum_destroy((bignum_t) x); } Loading Loading @@ -84,6 +84,7 @@ void test_pop(){ printf("test_pop OK\n"); } void test_in_list(){ bignum_t x,y,z; list_t l; Loading @@ -106,15 +107,15 @@ void test_in_list(){ list_destroy(l, &destroy); printf("test_in_list OK\n"); } */ int main() { printf("=== LIST tests ===\n"); test_emptyness(); //test_push(); //test_top(); //test_pop(); //test_in_list(); test_push(); test_top(); test_pop(); test_in_list(); return 0; }