aboutsummaryrefslogtreecommitdiff
path: root/ft_is_set.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-19 08:30:03 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-02 22:11:17 +0100
commitf4e1232957b1270da70f57fcad4cd6371947e442 (patch)
treeeb78d0ed1cf3ad3ee7797e8359b0802fc1159808 /ft_is_set.c
parentd22609e03717283e85a23587203af1b8b7d2fde2 (diff)
downloadlibft-f4e1232957b1270da70f57fcad4cd6371947e442.tar.gz
libft-f4e1232957b1270da70f57fcad4cd6371947e442.tar.bz2
libft-f4e1232957b1270da70f57fcad4cd6371947e442.zip
Added algo functions ft_qsort, ft_is_set, ft_memswap, ft_compar_int
Diffstat (limited to 'ft_is_set.c')
-rw-r--r--ft_is_set.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/ft_is_set.c b/ft_is_set.c
new file mode 100644
index 0000000..8e45b49
--- /dev/null
+++ b/ft_is_set.c
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_is_set.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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);
+}