From 19d83149feebaeb99430715242aac352890122cc Mon Sep 17 00:00:00 2001 From: nass1pro Date: Tue, 9 Jun 2020 19:48:34 +0200 Subject: lexer_test single_ok --- test_mini/libft/src/algo/ft_bsearch.c | 32 +++++ test_mini/libft/src/algo/ft_compar_int.c | 18 +++ test_mini/libft/src/algo/ft_heapsort.c | 54 +++++++ test_mini/libft/src/algo/ft_is_set.c | 32 +++++ test_mini/libft/src/algo/ft_lfind.c | 28 ++++ test_mini/libft/src/algo/ft_lsearch.c | 23 +++ test_mini/libft/src/algo/ft_mergesort.c | 76 ++++++++++ test_mini/libft/src/algo/ft_qsort.c | 64 +++++++++ test_mini/libft/src/algo/ft_reverse.c | 27 ++++ test_mini/libft/src/bt/ft_btdestroy.c | 23 +++ test_mini/libft/src/bt/ft_btnew.c | 25 ++++ test_mini/libft/src/ctype/ft_isalnum.c | 18 +++ test_mini/libft/src/ctype/ft_isalpha.c | 16 +++ test_mini/libft/src/ctype/ft_isascii.c | 16 +++ test_mini/libft/src/ctype/ft_isblank.c | 16 +++ test_mini/libft/src/ctype/ft_isdigit.c | 16 +++ test_mini/libft/src/ctype/ft_isprint.c | 16 +++ test_mini/libft/src/ctype/ft_isspace.c | 19 +++ test_mini/libft/src/ctype/ft_todigit.c | 20 +++ test_mini/libft/src/ctype/ft_tolower.c | 24 ++++ test_mini/libft/src/ctype/ft_toupper.c | 20 +++ test_mini/libft/src/ht/ft_htdelone.c | 29 ++++ test_mini/libft/src/ht/ft_htdestroy.c | 30 ++++ test_mini/libft/src/ht/ft_htentry_new.c | 37 +++++ test_mini/libft/src/ht/ft_htget.c | 35 +++++ test_mini/libft/src/ht/ft_hthash.c | 36 +++++ test_mini/libft/src/ht/ft_htiter.c | 31 +++++ test_mini/libft/src/ht/ft_htnew.c | 38 +++++ test_mini/libft/src/ht/ft_htset.c | 56 ++++++++ test_mini/libft/src/ht/ft_inter_htkey_cmp.c | 25 ++++ test_mini/libft/src/io/ft_getchar.c | 22 +++ test_mini/libft/src/io/ft_next_line.c | 113 +++++++++++++++ test_mini/libft/src/io/ft_printf/ft_asprintf.c | 24 ++++ test_mini/libft/src/io/ft_printf/ft_dprintf.c | 24 ++++ test_mini/libft/src/io/ft_printf/ft_printf.c | 24 ++++ test_mini/libft/src/io/ft_printf/ft_snprintf.c | 24 ++++ test_mini/libft/src/io/ft_printf/ft_sprintf.c | 24 ++++ test_mini/libft/src/io/ft_printf/ft_vasprintf.c | 21 +++ test_mini/libft/src/io/ft_printf/ft_vasprintf.h | 155 +++++++++++++++++++++ test_mini/libft/src/io/ft_printf/ft_vdprintf.c | 24 ++++ test_mini/libft/src/io/ft_printf/ft_vprintf.c | 18 +++ test_mini/libft/src/io/ft_printf/ft_vsnprintf.c | 26 ++++ test_mini/libft/src/io/ft_printf/ft_vsprintf.c | 18 +++ .../libft/src/io/ft_printf/internals/convert.c | 122 ++++++++++++++++ .../src/io/ft_printf/internals/convert_char.c | 53 +++++++ .../libft/src/io/ft_printf/internals/convert_hex.c | 34 +++++ .../libft/src/io/ft_printf/internals/convert_int.c | 40 ++++++ .../src/io/ft_printf/internals/convert_none.c | 25 ++++ .../src/io/ft_printf/internals/convert_percent.c | 23 +++ .../libft/src/io/ft_printf/internals/convert_ptr.c | 29 ++++ .../libft/src/io/ft_printf/internals/convert_str.c | 25 ++++ .../src/io/ft_printf/internals/convert_uint.c | 34 +++++ .../src/io/ft_printf/internals/convert_written.c | 28 ++++ .../libft/src/io/ft_printf/internals/extract.c | 98 +++++++++++++ .../src/io/ft_printf/internals/length_modifier.c | 39 ++++++ test_mini/libft/src/io/ft_printf/internals/list.c | 67 +++++++++ test_mini/libft/src/io/ft_printf/internals/parse.c | 61 ++++++++ test_mini/libft/src/io/ft_printf/internals/utils.c | 115 +++++++++++++++ test_mini/libft/src/io/ft_putchar.c | 18 +++ test_mini/libft/src/io/ft_putchar_fd.c | 20 +++ test_mini/libft/src/io/ft_putendl.c | 18 +++ test_mini/libft/src/io/ft_putendl_fd.c | 21 +++ test_mini/libft/src/io/ft_putnbr.c | 18 +++ test_mini/libft/src/io/ft_putnbr_fd.c | 30 ++++ test_mini/libft/src/io/ft_putstr.c | 18 +++ test_mini/libft/src/io/ft_putstr_fd.c | 20 +++ test_mini/libft/src/lst/ft_lstbsearch.c | 65 +++++++++ test_mini/libft/src/lst/ft_lstdelone.c | 27 ++++ test_mini/libft/src/lst/ft_lstdestroy.c | 29 ++++ test_mini/libft/src/lst/ft_lstiter.c | 29 ++++ test_mini/libft/src/lst/ft_lstlast.c | 27 ++++ test_mini/libft/src/lst/ft_lstlfind.c | 22 +++ test_mini/libft/src/lst/ft_lstlsearch.c | 27 ++++ test_mini/libft/src/lst/ft_lstmap.c | 56 ++++++++ test_mini/libft/src/lst/ft_lstnew.c | 29 ++++ test_mini/libft/src/lst/ft_lstpop_front.c | 29 ++++ test_mini/libft/src/lst/ft_lstpush_back.c | 30 ++++ test_mini/libft/src/lst/ft_lstpush_front.c | 26 ++++ test_mini/libft/src/lst/ft_lstremove_if.c | 38 +++++ test_mini/libft/src/lst/ft_lstreverse.c | 22 +++ test_mini/libft/src/lst/ft_lstreverse_ret.c | 32 +++++ test_mini/libft/src/lst/ft_lstsize.c | 31 +++++ test_mini/libft/src/lst/ft_lstsort.c | 46 ++++++ test_mini/libft/src/lst/ft_lstsorted_merge.c | 43 ++++++ test_mini/libft/src/mem/ft_bzero.c | 18 +++ test_mini/libft/src/mem/ft_calloc.c | 23 +++ test_mini/libft/src/mem/ft_memalloc.c | 18 +++ test_mini/libft/src/mem/ft_memccpy.c | 31 +++++ test_mini/libft/src/mem/ft_memchr.c | 26 ++++ test_mini/libft/src/mem/ft_memcmp.c | 30 ++++ test_mini/libft/src/mem/ft_memcpy.c | 33 +++++ test_mini/libft/src/mem/ft_memdel.c | 21 +++ test_mini/libft/src/mem/ft_memmem.c | 58 ++++++++ test_mini/libft/src/mem/ft_memmove.c | 35 +++++ test_mini/libft/src/mem/ft_memset.c | 31 +++++ test_mini/libft/src/mem/ft_memset_pattern4.c | 26 ++++ test_mini/libft/src/mem/ft_memswap.c | 29 ++++ test_mini/libft/src/str/ft_atoi.c | 22 +++ test_mini/libft/src/str/ft_atoi_strict.c | 38 +++++ test_mini/libft/src/str/ft_itoa.c | 40 ++++++ test_mini/libft/src/str/ft_split.c | 73 ++++++++++ test_mini/libft/src/str/ft_strcasecmp.c | 24 ++++ test_mini/libft/src/str/ft_strcat.c | 19 +++ test_mini/libft/src/str/ft_strchr.c | 18 +++ test_mini/libft/src/str/ft_strclr.c | 20 +++ test_mini/libft/src/str/ft_strcmp.c | 23 +++ test_mini/libft/src/str/ft_strcount.c | 24 ++++ test_mini/libft/src/str/ft_strcpy.c | 18 +++ test_mini/libft/src/str/ft_strcspn.c | 23 +++ test_mini/libft/src/str/ft_strdel.c | 18 +++ test_mini/libft/src/str/ft_strdup.c | 22 +++ test_mini/libft/src/str/ft_strequ.c | 20 +++ test_mini/libft/src/str/ft_striter.c | 21 +++ test_mini/libft/src/str/ft_striteri.c | 27 ++++ test_mini/libft/src/str/ft_strjoin.c | 25 ++++ test_mini/libft/src/str/ft_strjoin3.c | 36 +++++ test_mini/libft/src/str/ft_strjoinf.c | 35 +++++ test_mini/libft/src/str/ft_strlcat.c | 32 +++++ test_mini/libft/src/str/ft_strlcpy.c | 28 ++++ test_mini/libft/src/str/ft_strlen.c | 41 ++++++ test_mini/libft/src/str/ft_strmap.c | 34 +++++ test_mini/libft/src/str/ft_strmapi.c | 34 +++++ test_mini/libft/src/str/ft_strncasecmp.c | 26 ++++ test_mini/libft/src/str/ft_strncat.c | 29 ++++ test_mini/libft/src/str/ft_strncmp.c | 26 ++++ test_mini/libft/src/str/ft_strncpy.c | 24 ++++ test_mini/libft/src/str/ft_strndup.c | 23 +++ test_mini/libft/src/str/ft_strnequ.c | 20 +++ test_mini/libft/src/str/ft_strnew.c | 18 +++ test_mini/libft/src/str/ft_strnlen.c | 25 ++++ test_mini/libft/src/str/ft_strnstr.c | 29 ++++ test_mini/libft/src/str/ft_strpbrk.c | 24 ++++ test_mini/libft/src/str/ft_strrchr.c | 24 ++++ test_mini/libft/src/str/ft_strsep.c | 27 ++++ test_mini/libft/src/str/ft_strspn.c | 23 +++ test_mini/libft/src/str/ft_strstr.c | 29 ++++ test_mini/libft/src/str/ft_strtol.c | 80 +++++++++++ test_mini/libft/src/str/ft_strtolower.c | 26 ++++ test_mini/libft/src/str/ft_strtoupper.c | 26 ++++ test_mini/libft/src/str/ft_strtrim.c | 31 +++++ test_mini/libft/src/str/ft_substr.c | 26 ++++ test_mini/libft/src/util/ft_split_destroy.c | 24 ++++ test_mini/libft/src/vec/ft_vecdestroy.c | 29 ++++ test_mini/libft/src/vec/ft_vecgrow.c | 43 ++++++ test_mini/libft/src/vec/ft_veciter.c | 31 +++++ test_mini/libft/src/vec/ft_vecnew.c | 38 +++++ test_mini/libft/src/vec/ft_vecpop.c | 28 ++++ test_mini/libft/src/vec/ft_vecpush.c | 30 ++++ test_mini/libft/src/vec/ft_vecremove.c | 31 +++++ 149 files changed, 4865 insertions(+) create mode 100644 test_mini/libft/src/algo/ft_bsearch.c create mode 100644 test_mini/libft/src/algo/ft_compar_int.c create mode 100644 test_mini/libft/src/algo/ft_heapsort.c create mode 100644 test_mini/libft/src/algo/ft_is_set.c create mode 100644 test_mini/libft/src/algo/ft_lfind.c create mode 100644 test_mini/libft/src/algo/ft_lsearch.c create mode 100644 test_mini/libft/src/algo/ft_mergesort.c create mode 100644 test_mini/libft/src/algo/ft_qsort.c create mode 100644 test_mini/libft/src/algo/ft_reverse.c create mode 100644 test_mini/libft/src/bt/ft_btdestroy.c create mode 100644 test_mini/libft/src/bt/ft_btnew.c create mode 100644 test_mini/libft/src/ctype/ft_isalnum.c create mode 100644 test_mini/libft/src/ctype/ft_isalpha.c create mode 100644 test_mini/libft/src/ctype/ft_isascii.c create mode 100644 test_mini/libft/src/ctype/ft_isblank.c create mode 100644 test_mini/libft/src/ctype/ft_isdigit.c create mode 100644 test_mini/libft/src/ctype/ft_isprint.c create mode 100644 test_mini/libft/src/ctype/ft_isspace.c create mode 100644 test_mini/libft/src/ctype/ft_todigit.c create mode 100644 test_mini/libft/src/ctype/ft_tolower.c create mode 100644 test_mini/libft/src/ctype/ft_toupper.c create mode 100644 test_mini/libft/src/ht/ft_htdelone.c create mode 100644 test_mini/libft/src/ht/ft_htdestroy.c create mode 100644 test_mini/libft/src/ht/ft_htentry_new.c create mode 100644 test_mini/libft/src/ht/ft_htget.c create mode 100644 test_mini/libft/src/ht/ft_hthash.c create mode 100644 test_mini/libft/src/ht/ft_htiter.c create mode 100644 test_mini/libft/src/ht/ft_htnew.c create mode 100644 test_mini/libft/src/ht/ft_htset.c create mode 100644 test_mini/libft/src/ht/ft_inter_htkey_cmp.c create mode 100644 test_mini/libft/src/io/ft_getchar.c create mode 100644 test_mini/libft/src/io/ft_next_line.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_asprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_dprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_printf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_snprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_sprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_vasprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_vasprintf.h create mode 100644 test_mini/libft/src/io/ft_printf/ft_vdprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_vprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_vsnprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/ft_vsprintf.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_char.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_hex.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_int.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_none.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_percent.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_ptr.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_str.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_uint.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/convert_written.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/extract.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/length_modifier.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/list.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/parse.c create mode 100644 test_mini/libft/src/io/ft_printf/internals/utils.c create mode 100644 test_mini/libft/src/io/ft_putchar.c create mode 100644 test_mini/libft/src/io/ft_putchar_fd.c create mode 100644 test_mini/libft/src/io/ft_putendl.c create mode 100644 test_mini/libft/src/io/ft_putendl_fd.c create mode 100644 test_mini/libft/src/io/ft_putnbr.c create mode 100644 test_mini/libft/src/io/ft_putnbr_fd.c create mode 100644 test_mini/libft/src/io/ft_putstr.c create mode 100644 test_mini/libft/src/io/ft_putstr_fd.c create mode 100644 test_mini/libft/src/lst/ft_lstbsearch.c create mode 100644 test_mini/libft/src/lst/ft_lstdelone.c create mode 100644 test_mini/libft/src/lst/ft_lstdestroy.c create mode 100644 test_mini/libft/src/lst/ft_lstiter.c create mode 100644 test_mini/libft/src/lst/ft_lstlast.c create mode 100644 test_mini/libft/src/lst/ft_lstlfind.c create mode 100644 test_mini/libft/src/lst/ft_lstlsearch.c create mode 100644 test_mini/libft/src/lst/ft_lstmap.c create mode 100644 test_mini/libft/src/lst/ft_lstnew.c create mode 100644 test_mini/libft/src/lst/ft_lstpop_front.c create mode 100644 test_mini/libft/src/lst/ft_lstpush_back.c create mode 100644 test_mini/libft/src/lst/ft_lstpush_front.c create mode 100644 test_mini/libft/src/lst/ft_lstremove_if.c create mode 100644 test_mini/libft/src/lst/ft_lstreverse.c create mode 100644 test_mini/libft/src/lst/ft_lstreverse_ret.c create mode 100644 test_mini/libft/src/lst/ft_lstsize.c create mode 100644 test_mini/libft/src/lst/ft_lstsort.c create mode 100644 test_mini/libft/src/lst/ft_lstsorted_merge.c create mode 100644 test_mini/libft/src/mem/ft_bzero.c create mode 100644 test_mini/libft/src/mem/ft_calloc.c create mode 100644 test_mini/libft/src/mem/ft_memalloc.c create mode 100644 test_mini/libft/src/mem/ft_memccpy.c create mode 100644 test_mini/libft/src/mem/ft_memchr.c create mode 100644 test_mini/libft/src/mem/ft_memcmp.c create mode 100644 test_mini/libft/src/mem/ft_memcpy.c create mode 100644 test_mini/libft/src/mem/ft_memdel.c create mode 100644 test_mini/libft/src/mem/ft_memmem.c create mode 100644 test_mini/libft/src/mem/ft_memmove.c create mode 100644 test_mini/libft/src/mem/ft_memset.c create mode 100644 test_mini/libft/src/mem/ft_memset_pattern4.c create mode 100644 test_mini/libft/src/mem/ft_memswap.c create mode 100644 test_mini/libft/src/str/ft_atoi.c create mode 100644 test_mini/libft/src/str/ft_atoi_strict.c create mode 100644 test_mini/libft/src/str/ft_itoa.c create mode 100644 test_mini/libft/src/str/ft_split.c create mode 100644 test_mini/libft/src/str/ft_strcasecmp.c create mode 100644 test_mini/libft/src/str/ft_strcat.c create mode 100644 test_mini/libft/src/str/ft_strchr.c create mode 100644 test_mini/libft/src/str/ft_strclr.c create mode 100644 test_mini/libft/src/str/ft_strcmp.c create mode 100644 test_mini/libft/src/str/ft_strcount.c create mode 100644 test_mini/libft/src/str/ft_strcpy.c create mode 100644 test_mini/libft/src/str/ft_strcspn.c create mode 100644 test_mini/libft/src/str/ft_strdel.c create mode 100644 test_mini/libft/src/str/ft_strdup.c create mode 100644 test_mini/libft/src/str/ft_strequ.c create mode 100644 test_mini/libft/src/str/ft_striter.c create mode 100644 test_mini/libft/src/str/ft_striteri.c create mode 100644 test_mini/libft/src/str/ft_strjoin.c create mode 100644 test_mini/libft/src/str/ft_strjoin3.c create mode 100644 test_mini/libft/src/str/ft_strjoinf.c create mode 100644 test_mini/libft/src/str/ft_strlcat.c create mode 100644 test_mini/libft/src/str/ft_strlcpy.c create mode 100644 test_mini/libft/src/str/ft_strlen.c create mode 100644 test_mini/libft/src/str/ft_strmap.c create mode 100644 test_mini/libft/src/str/ft_strmapi.c create mode 100644 test_mini/libft/src/str/ft_strncasecmp.c create mode 100644 test_mini/libft/src/str/ft_strncat.c create mode 100644 test_mini/libft/src/str/ft_strncmp.c create mode 100644 test_mini/libft/src/str/ft_strncpy.c create mode 100644 test_mini/libft/src/str/ft_strndup.c create mode 100644 test_mini/libft/src/str/ft_strnequ.c create mode 100644 test_mini/libft/src/str/ft_strnew.c create mode 100644 test_mini/libft/src/str/ft_strnlen.c create mode 100644 test_mini/libft/src/str/ft_strnstr.c create mode 100644 test_mini/libft/src/str/ft_strpbrk.c create mode 100644 test_mini/libft/src/str/ft_strrchr.c create mode 100644 test_mini/libft/src/str/ft_strsep.c create mode 100644 test_mini/libft/src/str/ft_strspn.c create mode 100644 test_mini/libft/src/str/ft_strstr.c create mode 100644 test_mini/libft/src/str/ft_strtol.c create mode 100644 test_mini/libft/src/str/ft_strtolower.c create mode 100644 test_mini/libft/src/str/ft_strtoupper.c create mode 100644 test_mini/libft/src/str/ft_strtrim.c create mode 100644 test_mini/libft/src/str/ft_substr.c create mode 100644 test_mini/libft/src/util/ft_split_destroy.c create mode 100644 test_mini/libft/src/vec/ft_vecdestroy.c create mode 100644 test_mini/libft/src/vec/ft_vecgrow.c create mode 100644 test_mini/libft/src/vec/ft_veciter.c create mode 100644 test_mini/libft/src/vec/ft_vecnew.c create mode 100644 test_mini/libft/src/vec/ft_vecpop.c create mode 100644 test_mini/libft/src/vec/ft_vecpush.c create mode 100644 test_mini/libft/src/vec/ft_vecremove.c (limited to 'test_mini/libft/src') diff --git a/test_mini/libft/src/algo/ft_bsearch.c b/test_mini/libft/src/algo/ft_bsearch.c new file mode 100644 index 0000000..5132fa2 --- /dev/null +++ b/test_mini/libft/src/algo/ft_bsearch.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bsearch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:29:05 by cacharle #+# #+# */ +/* Updated: 2020/02/13 23:14:48 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +void *ft_bsearch(const void *base, size_t nel, size_t width, + t_ftsearch_const *consts) +{ + int res; + size_t mid; + + if (nel < 1) + return (NULL); + mid = nel / 2; + res = (consts->compar)(consts->key, base + mid * width); + if (res == 0) + return ((void*)base + mid * width); + if (res < 0) + return (ft_bsearch(base, mid, width, consts)); + else + return (ft_bsearch(base + (mid + 1) * width, nel - mid - 1, + width, consts)); +} diff --git a/test_mini/libft/src/algo/ft_compar_int.c b/test_mini/libft/src/algo/ft_compar_int.c new file mode 100644 index 0000000..848dc71 --- /dev/null +++ b/test_mini/libft/src/algo/ft_compar_int.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_compar_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 08:24:43 by cacharle #+# #+# */ +/* Updated: 2020/01/19 08:27:38 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_compar_int(const void *a, const void *b) +{ + return (*(int*)a - *(int*)b); +} diff --git a/test_mini/libft/src/algo/ft_heapsort.c b/test_mini/libft/src/algo/ft_heapsort.c new file mode 100644 index 0000000..d309624 --- /dev/null +++ b/test_mini/libft/src/algo/ft_heapsort.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_heapsort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 02:59:22 by cacharle #+# #+# */ +/* Updated: 2020/02/10 04:22:19 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +/* static void st_build_max_heap(void *base, size_t nel, size_t width, */ +/* int (*compar)(const void *, const void *)) */ +/* { */ +/* int i; */ +/* */ +/* i = 1; */ +/* while (i < nel) */ +/* { */ +/* compar(base + i * width, base + 2 * i * width) */ +/* */ +/* i++; */ +/* } */ +/* } */ +/* */ +/* static void st_heapify(void *base, size_t nel, size_t width, */ +/* int (*compar)(const void *, const void *)) */ +/* { */ +/* */ +/* } */ + +int ft_heapsort(void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *)) +{ + (void)base; + (void)nel; + (void)width; + (void)compar; + /* size_t i; */ + /* */ + /* if (nel < 2) */ + /* return (0); */ + /* st_build_max_heap(base, nel, width, compar); */ + /* i = -1; */ + /* while (++i < nel) */ + /* { */ + /* ft_memswap(base, base + (nel - i - 1) * width); */ + /* st_heapify(base, nel - i - 1, width, compar); */ + /* } */ + return (0); +} diff --git a/test_mini/libft/src/algo/ft_is_set.c b/test_mini/libft/src/algo/ft_is_set.c new file mode 100644 index 0000000..3e7ae31 --- /dev/null +++ b/test_mini/libft/src/algo/ft_is_set.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_set.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 07:17:15 by cacharle #+# #+# */ +/* Updated: 2020/02/10 02:51:41 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_algo.h" + +t_ftbool ft_is_set(void *base, size_t nel, size_t width, + t_ftcompar_func compar) +{ + size_t i; + + if (nel < 2) + return (TRUE); + ft_qsort(base, nel, width, compar); + i = 0; + while (i < nel - 1) + { + if (compar(base + (i * width), base + ((i + 1) * width)) == 0) + return (FALSE); + i++; + } + return (TRUE); +} diff --git a/test_mini/libft/src/algo/ft_lfind.c b/test_mini/libft/src/algo/ft_lfind.c new file mode 100644 index 0000000..8538f50 --- /dev/null +++ b/test_mini/libft/src/algo/ft_lfind.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lfind.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:49:19 by cacharle #+# #+# */ +/* Updated: 2020/02/10 05:58:19 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +void *ft_lfind(const void *base, size_t *nelp, size_t width, + t_ftsearch_const *consts) +{ + size_t i; + + i = 0; + while (i < *nelp) + { + if ((consts->compar)(consts->key, base + i * width) == 0) + return ((void*)base + i * width); + i++; + } + return (NULL); +} diff --git a/test_mini/libft/src/algo/ft_lsearch.c b/test_mini/libft/src/algo/ft_lsearch.c new file mode 100644 index 0000000..4c77bca --- /dev/null +++ b/test_mini/libft/src/algo/ft_lsearch.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lsearch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:53:57 by cacharle #+# #+# */ +/* Updated: 2020/02/10 05:59:33 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +void *ft_lsearch(const void *base, size_t *nelp, size_t width, + t_ftsearch_const *consts) +{ + void *found; + + if ((found = ft_lfind(base, nelp, width, consts)) != NULL) + return (found); + return (ft_memcpy((void*)base + (*nelp)++ * width, consts->key, width)); +} diff --git a/test_mini/libft/src/algo/ft_mergesort.c b/test_mini/libft/src/algo/ft_mergesort.c new file mode 100644 index 0000000..25b4255 --- /dev/null +++ b/test_mini/libft/src/algo/ft_mergesort.c @@ -0,0 +1,76 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_mergesort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 02:26:41 by cacharle #+# #+# */ +/* Updated: 2020/02/13 23:14:21 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +static int st_mergesort_error(void *left, void *right) +{ + free(left); + free(right); + return (-1); +} + +static void st_merge_sorted(struct s_merge_sorted_arrays *arrays, size_t nel, + size_t width, int (*compar)(const void *, const void *)) +{ + size_t bi; + size_t li; + size_t ri; + size_t mid; + + mid = nel / 2; + bi = 0; + li = 0; + ri = 0; + while (li < mid && ri < nel - mid) + { + if (compar(arrays->left + li * width, arrays->right + ri * width) < 0) + ft_memcpy(arrays->base + bi * width, + arrays->left + li++ * width, width); + else + ft_memcpy(arrays->base + bi * width, + arrays->right + ri++ * width, width); + bi++; + } + while (li < mid) + ft_memcpy(arrays->base + bi++ * width, + arrays->left + li++ * width, width); + while (ri < nel - mid) + ft_memcpy(arrays->base + bi++ * width, + arrays->right + ri++ * width, width); +} + +int ft_mergesort(void *base, size_t nel, size_t width, + int (*compar)(const void *, const void *)) +{ + size_t mid; + struct s_merge_sorted_arrays arrays; + + if (nel < 2) + return (0); + mid = nel / 2; + if ((arrays.left = malloc(mid * width)) == NULL) + return (-1); + if ((arrays.right = malloc((nel - mid) * width)) == NULL) + return (st_mergesort_error(arrays.left, NULL)); + ft_memcpy(arrays.left, base, mid * width); + ft_memcpy(arrays.right, base + mid * width, (nel - mid) * width); + if (ft_mergesort(arrays.left, mid, width, compar) == -1) + return (st_mergesort_error(arrays.left, arrays.right)); + if (ft_mergesort(arrays.right, nel - mid, width, compar) == -1) + return (st_mergesort_error(arrays.left, arrays.right)); + arrays.base = base; + st_merge_sorted(&arrays, nel, width, compar); + free(arrays.left); + free(arrays.right); + return (0); +} diff --git a/test_mini/libft/src/algo/ft_qsort.c b/test_mini/libft/src/algo/ft_qsort.c new file mode 100644 index 0000000..9bcfcdf --- /dev/null +++ b/test_mini/libft/src/algo/ft_qsort.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_qsort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 07:25:51 by cacharle #+# #+# */ +/* Updated: 2020/02/10 02:55:14 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +static t_ftrange ft_range_new(int lo, int hi) +{ + t_ftrange range; + + range.lo = lo; + range.hi = hi; + return (range); +} + +static int ft_qsort_partition(void *base, t_ftrange range, + size_t width, t_ftcompar_func compar) +{ + void *pivot; + int p; + int i; + + pivot = base + (range.hi * width); + p = range.lo; + i = range.lo - 1; + while (++i < range.hi) + { + if (compar(base + (i * width), pivot) < 0) + { + ft_memswap(base + (i * width), base + (p * width), width); + p++; + } + } + ft_memswap(pivot, base + (p * width), width); + return (p); +} + +static void ft_qsort_rec(void *base, t_ftrange range, + size_t width, t_ftcompar_func compar) +{ + int pivot; + + if (range.lo >= range.hi) + return ; + pivot = ft_qsort_partition(base, range, width, compar); + ft_qsort_rec(base, ft_range_new(range.lo, pivot - 1), width, compar); + ft_qsort_rec(base, ft_range_new(pivot + 1, range.hi), width, compar); +} + +void ft_qsort(void *base, size_t nel, size_t width, + t_ftcompar_func compar) +{ + if (width == 0 || nel < 2) + return ; + ft_qsort_rec(base, ft_range_new(0, nel - 1), width, compar); +} diff --git a/test_mini/libft/src/algo/ft_reverse.c b/test_mini/libft/src/algo/ft_reverse.c new file mode 100644 index 0000000..0bc447f --- /dev/null +++ b/test_mini/libft/src/algo/ft_reverse.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_reverse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:07:13 by cacharle #+# #+# */ +/* Updated: 2020/02/10 05:19:22 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +void ft_reverse(void *base, size_t nel, size_t width) +{ + size_t i; + + i = 0; + nel--; + while (i < nel) + { + ft_memswap(base + i * width, base + nel * width, width); + i++; + nel--; + } +} diff --git a/test_mini/libft/src/bt/ft_btdestroy.c b/test_mini/libft/src/bt/ft_btdestroy.c new file mode 100644 index 0000000..c802db0 --- /dev/null +++ b/test_mini/libft/src/bt/ft_btdestroy.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btdestroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/07 21:30:53 by cacharle #+# #+# */ +/* Updated: 2020/02/07 21:35:19 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_bt.h" + +void ft_btdestroy(t_ftbtree *tree, void (*del)(void *data)) +{ + if (tree == NULL) + return ; + ft_btdestroy(tree->left, del); + ft_btdestroy(tree->right, del); + (*del)(tree->data); + free(tree); +} diff --git a/test_mini/libft/src/bt/ft_btnew.c b/test_mini/libft/src/bt/ft_btnew.c new file mode 100644 index 0000000..973e1a4 --- /dev/null +++ b/test_mini/libft/src/bt/ft_btnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/07 21:33:16 by cacharle #+# #+# */ +/* Updated: 2020/02/07 21:34:35 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_bt.h" + +t_ftbtree *ft_btnew(void *data) +{ + t_ftbtree *tree; + + if ((tree = (t_ftbtree*)malloc(sizeof(t_ftbtree))) == NULL) + return (NULL); + tree->data = data; + tree->left = NULL; + tree->right = NULL; + return (tree); +} diff --git a/test_mini/libft/src/ctype/ft_isalnum.c b/test_mini/libft/src/ctype/ft_isalnum.c new file mode 100644 index 0000000..1ee1e0f --- /dev/null +++ b/test_mini/libft/src/ctype/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:41:40 by cacharle #+# #+# */ +/* Updated: 2019/10/07 09:41:56 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isalpha(c) || ft_isdigit(c)); +} diff --git a/test_mini/libft/src/ctype/ft_isalpha.c b/test_mini/libft/src/ctype/ft_isalpha.c new file mode 100644 index 0000000..6f155b4 --- /dev/null +++ b/test_mini/libft/src/ctype/ft_isalpha.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:54:52 by cacharle #+# #+# */ +/* Updated: 2019/10/20 13:01:13 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} diff --git a/test_mini/libft/src/ctype/ft_isascii.c b/test_mini/libft/src/ctype/ft_isascii.c new file mode 100644 index 0000000..12b6849 --- /dev/null +++ b/test_mini/libft/src/ctype/ft_isascii.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:54:30 by cacharle #+# #+# */ +/* Updated: 2020/02/12 23:01:02 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + return (c >= 00 && c <= 0177); +} diff --git a/test_mini/libft/src/ctype/ft_isblank.c b/test_mini/libft/src/ctype/ft_isblank.c new file mode 100644 index 0000000..def106b --- /dev/null +++ b/test_mini/libft/src/ctype/ft_isblank.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isblank.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/10 05:17:45 by cacharle #+# #+# */ +/* Updated: 2020/02/10 05:18:34 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isblank(int c) +{ + return (c == ' ' || c == '\t'); +} diff --git a/test_mini/libft/src/ctype/ft_isdigit.c b/test_mini/libft/src/ctype/ft_isdigit.c new file mode 100644 index 0000000..f8a5850 --- /dev/null +++ b/test_mini/libft/src/ctype/ft_isdigit.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:41:20 by cacharle #+# #+# */ +/* Updated: 2019/10/07 10:41:25 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/test_mini/libft/src/ctype/ft_isprint.c b/test_mini/libft/src/ctype/ft_isprint.c new file mode 100644 index 0000000..c311709 --- /dev/null +++ b/test_mini/libft/src/ctype/ft_isprint.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:52:09 by cacharle #+# #+# */ +/* Updated: 2019/10/20 13:03:36 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int c) +{ + return (c >= ' ' && c <= '~'); +} diff --git a/test_mini/libft/src/ctype/ft_isspace.c b/test_mini/libft/src/ctype/ft_isspace.c new file mode 100644 index 0000000..18b6dba --- /dev/null +++ b/test_mini/libft/src/ctype/ft_isspace.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isspace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/15 11:33:36 by cacharle #+# #+# */ +/* Updated: 2020/01/15 11:35:07 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isspace(int c) +{ + return (c == ' ' || c == '\t' || c == '\n' + || c == '\v' || c == '\f' || c == '\r'); +} diff --git a/test_mini/libft/src/ctype/ft_todigit.c b/test_mini/libft/src/ctype/ft_todigit.c new file mode 100644 index 0000000..f201470 --- /dev/null +++ b/test_mini/libft/src/ctype/ft_todigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_todigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/15 10:37:57 by cacharle #+# #+# */ +/* Updated: 2020/02/12 23:11:55 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_todigit(int c) +{ + if (!ft_isdigit(c)) + return (-1); + return (c & 0x0F); +} diff --git a/test_mini/libft/src/ctype/ft_tolower.c b/test_mini/libft/src/ctype/ft_tolower.c new file mode 100644 index 0000000..919469f --- /dev/null +++ b/test_mini/libft/src/ctype/ft_tolower.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:14:26 by cacharle #+# #+# */ +/* Updated: 2019/11/20 01:04:02 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +/* +** E: 0100 0101 +** e: 0110 0101 +** ^ +*/ + +int ft_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return (c | 0b00100000); + return (c); +} diff --git a/test_mini/libft/src/ctype/ft_toupper.c b/test_mini/libft/src/ctype/ft_toupper.c new file mode 100644 index 0000000..8579b91 --- /dev/null +++ b/test_mini/libft/src/ctype/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:14:10 by cacharle #+# #+# */ +/* Updated: 2019/11/20 01:04:51 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return (c ^ 0b00100000); + return (c); +} diff --git a/test_mini/libft/src/ht/ft_htdelone.c b/test_mini/libft/src/ht/ft_htdelone.c new file mode 100644 index 0000000..7374a44 --- /dev/null +++ b/test_mini/libft/src/ht/ft_htdelone.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 09:27:18 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:10:16 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/* +** \brief Delete one hash table entry +** \param key Key of entry to delete +** \param del Function to destroy the entry +** \warning The del function HAS to free the key +** \note Do nothing if their is to entry which correspond to key +*/ + +void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_entry*)) +{ + ft_lstremove_if(ht->buckets + ft_hthash(ht, key), + ft_inter_htkey_cmp, key, + (void (*)(void*))del); +} diff --git a/test_mini/libft/src/ht/ft_htdestroy.c b/test_mini/libft/src/ht/ft_htdestroy.c new file mode 100644 index 0000000..ff362d2 --- /dev/null +++ b/test_mini/libft/src/ht/ft_htdestroy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htdestroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:31:02 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:10:31 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/* +** \brief Destroy an hash table. +** \param del Function to delete each entry +** \warning The del function HAS to free the key +*/ + +void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_entry*)) +{ + if (ht == NULL) + return ; + while (ht->size-- > 0) + ft_lstdestroy(ht->buckets + ht->size, (void (*)(void*))del); + free(ht->buckets); + free(ht); +} diff --git a/test_mini/libft/src/ht/ft_htentry_new.c b/test_mini/libft/src/ht/ft_htentry_new.c new file mode 100644 index 0000000..12a1159 --- /dev/null +++ b/test_mini/libft/src/ht/ft_htentry_new.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htentry_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:45:36 by cacharle #+# #+# */ +/* Updated: 2020/02/17 04:09:50 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/* +** \brief Create a new hash table key/value pair. +** \param key Hash entry string key (always duplicated) +** \return Content or NULL if an allocation failed. +*/ + +t_ftht_entry *ft_htentry_new(char *key, void *value) +{ + t_ftht_entry *content; + + if (key == NULL) + return (NULL); + if ((content = (t_ftht_entry*)malloc(sizeof(t_ftht_entry))) == NULL) + return (NULL); + if ((content->key = ft_strdup(key)) == NULL) + { + free(content); + return (NULL); + } + content->value = value; + return (content); +} diff --git a/test_mini/libft/src/ht/ft_htget.c b/test_mini/libft/src/ht/ft_htget.c new file mode 100644 index 0000000..a6383fe --- /dev/null +++ b/test_mini/libft/src/ht/ft_htget.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htget.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:33:21 by cacharle #+# #+# */ +/* Updated: 2020/04/01 18:02:57 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/* +** \brief Retrieve a value with a key +** \param ht Hash table where key is searched +** \param key Searched key +** \return Value void pointer at key or NULL if not found +*/ + +void *ft_htget(t_ftht *ht, char *key) +{ + t_ftht_digest digest; + t_ftlst *found; + + if (ht == NULL || key == NULL) + return (NULL); + digest = ft_hthash(ht, key); + found = ft_lstlfind(ht->buckets[digest], ft_inter_htkey_cmp, key); + if (found == NULL) + return (NULL); + return (((t_ftht_entry*)found->data)->value); +} diff --git a/test_mini/libft/src/ht/ft_hthash.c b/test_mini/libft/src/ht/ft_hthash.c new file mode 100644 index 0000000..3369d24 --- /dev/null +++ b/test_mini/libft/src/ht/ft_hthash.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_hthash.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 09:56:01 by cacharle #+# #+# */ +/* Updated: 2020/01/30 10:34:27 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_ht.h" + +/* +** \brief Hash a string +** \param ht So that the index is in the hash table bound +** \param key String to hash +** \return Hash +*/ + +// maybe use a less efficient but understandable function +t_ftht_digest ft_hthash(t_ftht *ht, char *key) +{ + t_ftht_digest digest; + + if (*key == '\0') + return (0); + digest = *key++ << 7; + while (*key != '\0') + { + digest = ((1000003 * digest) ^ *key) & (1 << 16); + key++; + } + return (digest % ht->size); +} diff --git a/test_mini/libft/src/ht/ft_htiter.c b/test_mini/libft/src/ht/ft_htiter.c new file mode 100644 index 0000000..b854993 --- /dev/null +++ b/test_mini/libft/src/ht/ft_htiter.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/01 18:02:24 by charles #+# #+# */ +/* Updated: 2020/04/01 18:02:32 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_ht.h" + +/* +** \brief Iterate over entry of hash table +** \param ht Iterated hash table +** \param f Function applied to each entry +*/ + +void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*)) +{ + size_t i; + + i = 0; + while (i < ht->size) + { + ft_lstiter(ht->buckets[i], (void (*)(void*))f); + i++; + } +} diff --git a/test_mini/libft/src/ht/ft_htnew.c b/test_mini/libft/src/ht/ft_htnew.c new file mode 100644 index 0000000..e5335d2 --- /dev/null +++ b/test_mini/libft/src/ht/ft_htnew.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:19:16 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:23:43 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/* +** \brief Create a new hash table. +** \param size Size of the underlying array of linked list (buckets) +** \return Created hash table or NULL is an allocation failed +*/ + +t_ftht *ft_htnew(t_ftsize size) +{ + t_ftht *ht; + + if (size == 0) + return (NULL); + if ((ht = (t_ftht*)malloc(sizeof(t_ftht))) == NULL) + return (NULL); + ht->buckets = (t_ftht_bucket*)ft_calloc(size, sizeof(t_ftht_entry)); + if (ht->buckets == NULL) + { + free(ht); + return (NULL); + } + ht->size = size; + return (ht); +} diff --git a/test_mini/libft/src/ht/ft_htset.c b/test_mini/libft/src/ht/ft_htset.c new file mode 100644 index 0000000..68d3752 --- /dev/null +++ b/test_mini/libft/src/ht/ft_htset.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:41:52 by cacharle #+# #+# */ +/* Updated: 2020/04/01 18:02:12 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/* +** \brief Create/Update a entry in hash table. +** \note If `key` already exist in `ht` +** only updates the list node content. +** Else create a new list node in addition the list content. +** \param ht Hash table where the entry is modified +** \param key Key of the new entry +** \param value Value of the new entry +** \param del Destroy function in case the entry is modified. +** \return Pointer to the created entry, NULL if an allocation failed. +*/ + +t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value, + void (*del)(t_ftht_entry*)) +{ + t_ftht_digest digest; + t_ftht_entry *content; + t_ftht_bucket bucket; + t_ftlst *tmp; + + if (ht == NULL || key == NULL) + return (NULL); + if ((content = ft_htentry_new(key, value)) == NULL) + return (NULL); + digest = ft_hthash(ht, key); + tmp = ft_lstlfind(ht->buckets[digest], ft_inter_htkey_cmp, key); + if (tmp != NULL) + { + if (del != NULL) + del(tmp->data); + tmp->data = content; + return ((t_ftht_entry*)tmp->data); + } + if ((bucket = ft_lstnew(content)) == NULL) + { + del(content); + return (NULL); + } + ft_lstpush_front(ht->buckets + digest, bucket); + return (content); +} diff --git a/test_mini/libft/src/ht/ft_inter_htkey_cmp.c b/test_mini/libft/src/ht/ft_inter_htkey_cmp.c new file mode 100644 index 0000000..e8a0375 --- /dev/null +++ b/test_mini/libft/src/ht/ft_inter_htkey_cmp.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_internal_htkey_equal.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 09:24:39 by cacharle #+# #+# */ +/* Updated: 2020/02/28 12:20:43 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +/* +** Hash table internal function to compare key string in linked list. +*/ + +int ft_inter_htkey_cmp(const void *ref_key, const void *content) +{ + if (ref_key == NULL || content == NULL) + return (-1); + return (ft_strcmp((char*)ref_key, ((t_ftht_entry*)content)->key)); +} diff --git a/test_mini/libft/src/io/ft_getchar.c b/test_mini/libft/src/io/ft_getchar.c new file mode 100644 index 0000000..9d233c0 --- /dev/null +++ b/test_mini/libft/src/io/ft_getchar.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_getchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/18 10:29:54 by cacharle #+# #+#