From c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 11 Oct 2020 15:52:52 +0200 Subject: Removing libft/minishell_test submodules, Removing subject/README/etc --- libft/src/algo/ft_is_set.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 libft/src/algo/ft_is_set.c (limited to 'libft/src/algo/ft_is_set.c') diff --git a/libft/src/algo/ft_is_set.c b/libft/src/algo/ft_is_set.c new file mode 100644 index 0000000..fd26a88 --- /dev/null +++ b/libft/src/algo/ft_is_set.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_set.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 07:17:15 by cacharle #+# #+# */ +/* Updated: 2020/04/04 22:33:03 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_algo.h" + +/* +** \brief Test whether array only contains unique elements +** \param base Array to test +** \param nel Number of element in the array +** \param width Size of an element +** \param compar Comparison function to test if 2 elements are equal +*/ + +bool 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); +} -- cgit