void f_list_splice(t_list *v_this, t_list_cell *position, t_list *other_list, t_list_interval *other_interval) { size_t cell_count; cell_count = D_LIST(pick_cells)(other_list, D_LIST_INTERVAL(begin)(other_interval), D_LIST_INTERVAL(end)(other_interval)); if (cell_count == 0) return ; if (D_LIST(empty)(v_this) == true) { v_this->v_size = cell_count; v_this->v_begin = D_LIST_INTERVAL(begin)(other_interval); v_this->v_end = D_LIST_INTERVAL(end)(other_interval); return ; } if (position == NULL) { position = D_LIST(end)(v_this); position->v_next = D_LIST_INTERVAL(begin)(other_interval); D_LIST_INTERVAL(begin)(other_interval)->v_prev = position; } else D_LIST(splice_imp)(v_this, position, D_LIST_INTERVAL(begin)(other_interval), D_LIST_INTERVAL(end)(other_interval)); v_this->v_size = D_LIST(size)(v_this) + cell_count; }
bool mf_unit_add_test(t_unit *v_this, const char *context, const char *name, void (*test)(t_unit_test *)) { t_list_cell *cell; t_unit_test *t; cell = D_LIST(begin)(&v_this->v_context); while (cell != NULL) { if (uf_strcmp(context, ((t_unit_context*)cell->v_data)->v_name) == 0) break ; cell = cell->v_next; } if (cell == NULL) return (M_ERROR(false, "Could not find %s context", context)); t = uf_unit_alloc_test(name, test); if (t == NULL) return (false); if (D_LIST(push_back)(&((t_unit_context*)cell->v_data)->v_test, t) == false) { uf_free_s((void **)&t); return (false); } return (true); }
static void f_list_pick_cells_imp(t_list *const v_this, t_list_cell *const begin, t_list_cell *const end) { t_list_cell *cell_before; t_list_cell *cell_after; cell_before = D_LIST_CELL(prev)(begin); cell_after = D_LIST_CELL(next)(end); if (cell_before == NULL) { v_this->v_begin = cell_after; if (cell_after != NULL) cell_after->v_prev = NULL; } else cell_before->v_next = cell_after; if (cell_after == NULL) { if (D_LIST(begin)(v_this) != NULL) v_this->v_end = D_LIST_CELL(next)(v_this->v_begin); else v_this->v_end = D_LIST(begin)(v_this); } else cell_after->v_prev = cell_before; }
int main(int argc, char const** argv) { t_list list; /* * Initialize with delete pointer NULL because my data it's not allocated */ D_LIST(init)(&list, NULL); /* * Push at the end, the data 101 * Check return Value ? * No it's useless ! Ok Master */ D_LIST(push_back)(&list, (void *)101); D_LIST(push_back)(&list, (void *)11101); D_LIST(foreach)(&list, uf_print_data); /* * We free memory ? * Well ... let it and we'll see */ D_LIST(destroy)(&list); (void)argc; (void)argv; return (0); }
static void f_list_split_imp(t_list *v_this, t_list *new_list, t_list_cell *split_at) { new_list->v_begin = split_at; new_list->v_end = D_LIST(end)(v_this); new_list->v_size = D_LIST_CELL(count)(split_at, D_LIST(end)(v_this)); v_this->v_size = D_LIST(size)(v_this) - D_LIST(size)(new_list); v_this->v_end = D_LIST_CELL(prev)(split_at); v_this->v_end->v_next = NULL; new_list->v_begin->v_prev = NULL; new_list->v_end->v_next = NULL; }
static size_t f_list_pick_cells(t_list *const v_this, t_list_cell *const begin, t_list_cell *end) { size_t cell_count; if (D_LIST(empty)(v_this) == true) return (0); if (end == NULL) end = D_LIST(end)(v_this); cell_count = D_LIST_CELL(count)(begin, end); D_LIST(pick_cells_imp)(v_this, begin, end); v_this->v_size = D_LIST(size)(v_this) - cell_count; begin->v_prev = NULL; end->v_next = NULL; return (cell_count); }
static void uf_unit_destroy_test(void *data) { t_unit_test *test; test = (t_unit_test *)data; D_LIST(destroy)(&test->v_assert); uf_free_s((void **)&data); }
void uf_unit_console_treat_list(t_unit *v_this) { uf_unit_print_console(v_this, "Context", false, '-'); uf_print_str("Id\tName\t\t\t\t\t\t Init\tDestroy\tTest\n\n"); D_LIST(foreach)(&v_this->v_context, uf_unit_print_context); uf_unit_print_console(v_this, "-", false, '-'); uf_print_char('\n'); }
t_list_cell *f_list_delete(t_list *v_this, t_list_cell *mb_del) { void *del; t_list_cell *ret; ret = D_LIST(erase)(v_this, mb_del, &del); v_this->f_destroy(del); free(mb_del); return (ret); }
void f_htable_print(t_htable *v_this, bool (*uf_print)(t_htable_cell *data)) { ui i; t_list *list; i = 0; list = D_ARRAY(data)(&v_this->v_array, t_list *); while (i < v_this->v_prime) { if (D_LIST(size)(list + i) > 0) { uf_print_char('['); uf_print_nbr(i); uf_print_str("]-> "); D_LIST(foreach)(list + i, (bool (*)(void *))uf_print); uf_print_char('\n'); } i = i + 1; } }
void uf_unit_console_treat_run(t_unit *v_this) { t_list_cell *cell; t_unit_context *ctxt; cell = D_LIST(begin)(&v_this->v_context); uf_unit_print_console(v_this, "Running", false, '-'); while (cell != NULL) { ctxt = (t_unit_context*)cell->v_data; if (D_LIST(empty)(&ctxt->v_test) == false) { uf_print_variadic("\nrunning context: %e%s%e\n", 35, ctxt->v_name, 0); uf_unit_console_run(&ctxt->v_test); } cell = cell->v_next; } uf_unit_print_console(v_this, "-", false, '-'); }
bool f_unit_add_context(t_unit *v_this, const char *name, bool (*init)(void *), bool (*destroy)(void *)) { t_unit_context *context; if ((context = uf_malloc_s(1, sizeof(*context))) == NULL) return (M_ERROR(false, "Bad alloc")); context->v_name = name; context->f_init = init; context->f_destroy = destroy; context->v_id = D_LIST(size)(&v_this->v_context) + 1; D_LIST(init)(&context->v_test, uf_unit_destroy_test); if (D_LIST(push_back)(&v_this->v_context, context) == false) { uf_free_s((void **)&context); return (false); } return (true); }
void *f_htable_erase(t_htable *v_this, const char *key) { t_list *list; void *ret; t_list_cell *cell; ret = NULL; list = F_ARRAY_AT(&v_this->v_array, D_HTABLE(generate_key)(v_this->v_prime, key), t_list *); cell = D_LIST(begin)(list); while (cell != NULL && ret == NULL) { if (uf_strcmp(key, ((t_htable_cell*)cell->v_data)->v_key) == 0) { D_LIST(erase)(list, cell, &ret); ret = ((t_htable_cell*)ret)->v_data; } cell = cell->v_next; } return (ret); }
void uf_unit_console_treat_failure(t_unit *v_this) { t_list_cell *cell; t_unit_context *ctxt; cell = D_LIST(begin)(&v_this->v_context); uf_unit_print_console(v_this, "Failures", false, '-'); uf_print_str("\t\tName\t\t Statut\t\tFile\t\tLine\n\n"); while (cell != NULL) { ctxt = (t_unit_context*)cell->v_data; if (D_LIST(empty)(&ctxt->v_test) == false) { uf_print_variadic("\ncontext: %e%s%e\n", 35, ctxt->v_name, 0); uf_unit_console_failure(&ctxt->v_test); } cell = cell->v_next; } uf_unit_print_console(v_this, "-", false, '-'); }
bool f_htable_add(t_htable *v_this, const char *str, void *data) { ui key; t_list *element; t_htable_cell *cell; key = D_HTABLE(generate_key)(v_this, str); element = D_ARRAY(at)(&v_this->v_array, key, t_list *); cell = D_HTABLE(create_cell)(str, data, v_this->f_delete); if (cell == NULL) return (m_error(false, "Bad alloc")); return (D_LIST(push_back)(element, cell)); }
t_list_cell *f_list_find(t_list *v_this, bool (*cmp)(void *, void *), void *d) { t_list_cell *cell; cell = D_LIST(begin)(v_this); while (cell != NULL) { if (cmp(cell->v_data, d) == true) break ; cell = cell->v_next; } return (cell); }
void uf_unit_console_failure(t_list *list) { t_unit_test *t; t_list_cell *cell; cell = D_LIST(begin)(list); while (cell != NULL) { t = (t_unit_test*)cell->v_data; uf_unit_console_failure_print_info(t); cell = cell->v_next; } }
bool f_htable_add(t_htable *v_this, const char *str, void *data) { size_t key; t_list *element; t_htable_cell *cell; key = v_this->f_generate_key(v_this->v_prime, str); element = F_ARRAY_AT(&v_this->v_array, key, t_list *); cell = D_HTABLE(create_cell)(str, data, v_this->f_delete); if (cell == NULL) return (M_ERROR(false, "Bad alloc")); return (D_LIST(push_back)(element, cell)); }
t_list_cell *f_list_insert(t_list *v_this, t_list_cell *position, void *data) { t_list_cell *cell; if (position == NULL) { if (D_LIST(push_back)(v_this, data) == true) return (D_LIST(end)(v_this)); else return (NULL); } cell = D_LIST_CELL(create)(position->v_prev, position, data); if (cell != NULL) { if (D_LIST_CELL(prev)(position) != NULL) D_LIST_CELL(prev)(position)->v_next = cell; else v_this->v_begin = cell; position->v_prev = cell; v_this->v_size = D_LIST(size)(v_this) + 1; } return (cell); }
void f_list_clear(t_list *v_this) { t_list_cell *cur; t_list_cell *del; cur = v_this->v_begin; while (cur != NULL) { del = cur; cur = cur->v_next; v_this->f_destroy(del->v_data); uf_free_s((void **)&del); } D_LIST(init)(v_this, v_this->f_destroy); }
bool f_htable_init(t_htable *v_this, size_t prime, size_t (*f_generate_key)(size_t prime, const char *str), void (*f_delete)(void *ptr)) { size_t i; t_list list; i = 0; if (D_ARRAY(init)(&v_this->v_array, NULL, (void (*)(void *))D_LIST(destroy), sizeof(t_list)) == false) return (M_ERROR(false, "Could not initialize array")); D_LIST(init)(&list, D_HTABLE(delete_cell)); while (i < prime) { D_ARRAY(push_back)(&v_this->v_array, &list); i = i + 1; } v_this->v_prime = prime; v_this->f_delete = f_delete; v_this->f_generate_key = D_HTABLE(generate_key); if (f_generate_key != NULL) v_this->f_generate_key = f_generate_key; return (true); }
static t_unit_test *uf_unit_alloc_test(const char *name, void (*test)(t_unit_test *)) { t_unit_test *t; if ((t = uf_malloc_s(1, sizeof(*t))) == NULL) return ((t_unit_test*)M_ERROR((size_t)NULL, "Bad alloc")); t->v_name = name; t->f_func = test; t->v_failed = false; t->v_active = true; t->v_tested = false; D_LIST(init)(&t->v_assert, free); return (t); }
void f_htable_delete(t_htable *v_this, const char *key) { t_list *list; t_list_cell *cell; list = F_ARRAY_AT(&v_this->v_array, D_HTABLE(generate_key)(v_this->v_prime, key), t_list *); cell = D_LIST(begin)(list); while (cell != NULL) { if (uf_strcmp(key, ((t_htable_cell*)cell->v_data)->v_key) == 0) { D_LIST(delete)(list, cell); break ; } cell = cell->v_next; }
void uf_unit_console_run(t_list *list) { t_list_cell *cell; t_unit_test *test; cell = D_LIST(begin)(list); while (cell != NULL) { test = (t_unit_test*)cell->v_data; uf_print_variadic("\trunning test: %e%s%e\t...\t", 37, test->v_name, 0); test->f_func(test); if (test->v_failed == true) uf_print_variadic("%efailed%e\n", 31, 0); else uf_print_variadic("%epassed%e\n", 32, 0); cell = cell->v_next; } }
void *f_htable_get(t_htable *v_this, const char *str) { t_list *list; void *ret; t_list_cell *cell; ret = NULL; list = D_ARRAY(at)(&v_this->v_array, D_HTABLE(generate_key)(v_this, str), t_list *); cell = D_LIST(begin)(list); while (cell != NULL && ret == NULL) { if (uf_strcmp(str, ((t_htable_cell*)cell->v_data)->v_key) == 0) ret = ((t_htable_cell*)cell->v_data)->v_data; cell = cell->v_next; } return (ret); }
static void uf_unit_console_failure_print_info(t_unit_test *t) { t_list_cell *cell; t_unit_assert *ass; if (t->v_tested == true) { cell = D_LIST(begin)(&t->v_assert); if (cell == NULL) uf_print_variadic("\ttest: %e%s%e\t\t V%e\n", 37, t->v_name, 32, 0); while (cell != NULL) { ass = (t_unit_assert *)cell->v_data; uf_print_variadic("\ttest: %e%s\t\t %eX\033[0m\t %s\t\t %d\n", 37, t->v_name, 31, ass->v_file, ass->v_line); cell = cell->v_next; } } else uf_print_variadic("\ttest: %e%s%e\t\tUntested%e\n", 37, t->v_name, 31, 0); }
void f_list_split(t_list *v_this, t_list_cell *split_at, t_list *new_list) { if (new_list != NULL && split_at != NULL) { if (D_LIST(empty)(new_list) == false) D_LIST(clear)(new_list); if (D_LIST(begin)(v_this) == split_at) { new_list->v_begin = D_LIST(begin)(v_this); new_list->v_end = D_LIST(end)(v_this); new_list->v_size = D_LIST(size)(v_this); new_list->f_destroy = v_this->f_destroy; v_this->v_size = 0; v_this->v_begin = NULL; v_this->v_end = NULL; v_this->f_destroy = NULL; } else D_LIST(split_imp)(v_this, new_list, split_at); } }
void f_list_destroy(t_list *v_this) { D_LIST(clear)(v_this); v_this->f_destroy = NULL; }