aboutsummaryrefslogtreecommitdiff
path: root/libft/src/algo/ft_is_set.c
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-11 15:52:52 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-11 15:52:52 +0200
commitc98de126d2252fe47dc2a9094a5f9a8fa6b4b60a (patch)
tree12f1c827ee063ed3e7038f6a704014e611e4f388 /libft/src/algo/ft_is_set.c
parenta4ceb5974d1b7dcdd12cc81b7eb07893ea16c8ad (diff)
downloadminishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.tar.gz
minishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.tar.bz2
minishell-c98de126d2252fe47dc2a9094a5f9a8fa6b4b60a.zip
Removing libft/minishell_test submodules, Removing subject/README/etc
Diffstat (limited to 'libft/src/algo/ft_is_set.c')
-rw-r--r--libft/src/algo/ft_is_set.c39
1 files changed, 39 insertions, 0 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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);
+}