static bool *uf_string_fill_bool(t_string *v_this, const char *charset) { size_t i; size_t size; bool *active; i = 0; if ((active = uf_malloc_s(v_this->v_size, sizeof(*active))) == NULL) return ((bool *)M_ERROR((size_t)NULL, "Bad alloc")); uf_memset(active, false, v_this->v_size * sizeof(*active)); size = uf_str_len(charset); if (size == 0) i = v_this->v_size; while (i < v_this->v_size) { if (uf_strncmp(v_this->v_str + i, charset, size) == 0) { uf_memset(active + i, true, size * sizeof(*active)); i = i + size; } else i = i + 1; } return (active); }
void f_stack_init(t_stack *v_this, void (*uf_funct_destroy)(void *data)) { uf_memset(v_this, 0, sizeof(*v_this)); v_this->f_destroy = uf_stack_funct_destroy; if (uf_funct_destroy != NULL) v_this->f_destroy = uf_funct_destroy; }
void f_string_erase(t_string *v_this, ui from, ui to) { ui size; if (from >= to || to >= v_this->v_size) return ; size = v_this->v_size - to; uf_memcpy(v_this->v_str + from, v_this->v_str + to, size); uf_memset(v_this->v_str + from + size, '\0', to - from); v_this->v_size = v_this->v_size - (to - from); }
bool f_string_init(t_string *v_this, size_t (*uf_realloc)(size_t size)) { size_t size; size = 2; v_this->v_size = 0; if ((v_this->v_str = uf_malloc_s(size, sizeof(*v_this->v_str))) == NULL) return (M_ERROR(false, "Bad alloc")); uf_memset(v_this->v_str, 0, size * sizeof(*v_this->v_str)); v_this->f_realloc = uf_string_realloc_value; if (uf_realloc != NULL) v_this->f_realloc = uf_realloc; v_this->v_capacity = size; v_this->v_hex = "0123456789ABCDEF"; return (true); }
bool f_array_init(t_array *v_this, size_t (*uf_realloc)(size_t size), void (*uf_delete)(void *ptr), size_t type_size) { v_this->v_size = 0; v_this->v_capacity = 0; v_this->f_realloc = uf_realloc; if (uf_realloc == NULL) v_this->f_realloc = uf_array_realloc; v_this->f_delete = uf_delete; if (uf_delete == NULL) v_this->f_delete = uf_array_delete; if ((v_this->v_data = uf_malloc_s(2, type_size)) == NULL) return (M_ERROR(false, "Bad alloc")); uf_memset(v_this->v_data, 0, 2 * type_size); v_this->v_capacity = 2; v_this->v_type_size = type_size; return (true); }
bool f_rbtree_init(t_rbtree *v_this, int (*f_cmp)(void *d1, void *d2), void (*f_del)(void *data)) { uf_memset(v_this, 0, sizeof(*v_this)); if (f_cmp == NULL) return (m_error(false, "f_cmp couldn't NULL")); v_this->f_delete = uf_rbtree_delete; if (f_del != NULL) v_this->f_delete = f_del; v_this->f_cmp = f_cmp; v_this->v_nil.v_left = &v_this->v_nil; v_this->v_nil.v_right = &v_this->v_nil; v_this->v_nil.v_parent = &v_this->v_nil; v_this->v_nil.v_color = e_black; v_this->v_root.v_left = &v_this->v_nil; v_this->v_root.v_right = &v_this->v_nil; v_this->v_root.v_parent = &v_this->v_nil; v_this->v_root.v_color = e_black; return (true); }
static bool uf_sort_make_counter(int *tab, size_t size, int minmax[2]) { size_t i; int *counter; size_t size_counter; i = 0; size_counter = minmax[1] - minmax[0] + 1; counter = malloc(sizeof(*counter) * (size_counter)); if (counter == NULL) return (M_ERROR(false, "Bad alloc")); uf_memset(counter, 0, sizeof(*counter) * size_counter); while (i < size) { counter[tab[i] - minmax[0]] = counter[tab[i] - minmax[0]] + 1; i = i + 1; } uf_sort_tab(tab, counter, minmax); free(counter); return (true); }
int main(int argc, char const** argv) { char data[256]; int i; i = 0; while (i < 256) { data[i] = i; i = i + 1; } uf_print_memory(data, sizeof(data)); uf_memset(data, 0, sizeof(data)); uf_memcpy(data, "AAAAAAAA", 8); uf_print_char('\n'); uf_memcpy(data + 50, "AAAAAAAA", 8); uf_print_memory(data, sizeof(data)); (void)argc; (void)argv; return (0); }
void f_array_delete_if(t_array *v_this, bool (*ft_cmp)(void *d1, void *d2), void *data) { size_t i; size_t size; char *ptr; i = 0; ptr = (char *)v_this->v_data; size = v_this->v_size * v_this->v_type_size; while (i < size) { if (ft_cmp((void *)(ptr + i), data) == true) { uf_memcpy(ptr + i, ptr + i + v_this->v_type_size, size - i - v_this->v_type_size); uf_memset(ptr + size - v_this->v_type_size, 0, v_this->v_type_size); v_this->v_size = v_this->v_size - 1; size = v_this->v_size * v_this->v_type_size; } else i = i + v_this->v_type_size; } }
void f_array_destroy(t_array *v_this) { D_ARRAY(clear)(v_this); free(v_this->v_data); uf_memset(v_this, 0, sizeof(*v_this)); }
void f_stack_destroy(t_stack *v_this) { D_STACK(clear)(v_this); uf_memset(v_this, 0, sizeof(*v_this)); }
void f_string_destroy(t_string *v_this) { uf_free_s((void **)&v_this->v_str); uf_memset(v_this, 0, sizeof(*v_this)); }