From a5b068767440327f910dfa815be12ff4c0d94309 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 19 Jan 2020 08:30:03 +0100 Subject: Added algo functions ft_qsort, ft_is_set, ft_memswap, ft_compar_int --- src/algo/ft_is_set.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/algo/ft_is_set.c (limited to 'src/algo/ft_is_set.c') diff --git a/src/algo/ft_is_set.c b/src/algo/ft_is_set.c new file mode 100644 index 0000000..8e45b49 --- /dev/null +++ b/src/algo/ft_is_set.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_set.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 07:17:15 by cacharle #+# #+# */ +/* Updated: 2020/01/19 08:21:12 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_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