aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ctype/ft_isascii.c6
-rw-r--r--src/ht/ft_htnew.c6
-rw-r--r--src/lst/ft_lstsort.c40
-rw-r--r--src/lst/ft_lstsorted_merge.c36
4 files changed, 80 insertions, 8 deletions
diff --git a/src/ctype/ft_isascii.c b/src/ctype/ft_isascii.c
index 51dcd1c..376ee54 100644
--- a/src/ctype/ft_isascii.c
+++ b/src/ctype/ft_isascii.c
@@ -6,13 +6,11 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 09:54:30 by cacharle #+# #+# */
-/* Updated: 2019/10/20 13:03:23 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 02:14:40 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#define MAX_CHAR ((1 << 7) - 1)
-
int ft_isascii(int c)
{
- return (c >= 0 && c <= MAX_CHAR);
+ return (c >= 0 && c <= 255);
}
diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c
index 950a4fe..d98a724 100644
--- a/src/ht/ft_htnew.c
+++ b/src/ht/ft_htnew.c
@@ -6,20 +6,18 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:19:16 by cacharle #+# #+# */
-/* Updated: 2020/01/31 10:41:57 by cacharle ### ########.fr */
+/* Updated: 2020/02/10 02:16:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "libft_ht.h"
-#define FT_HT_MAX_SIZE (1 << 14)
-
t_ftht *ft_htnew(t_ftsize size)
{
t_ftht *ht;
- if (size == 0 || size > FT_HT_MAX_SIZE)
+ if (size == 0)
return (NULL);
if ((ht = (t_ftht*)malloc(sizeof(t_ftht))) == NULL)
return (NULL);
diff --git a/src/lst/ft_lstsort.c b/src/lst/ft_lstsort.c
new file mode 100644
index 0000000..883604f
--- /dev/null
+++ b/src/lst/ft_lstsort.c
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstsort.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 01:53:55 by cacharle #+# #+# */
+/* Updated: 2020/02/10 02:09:28 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_lst.h"
+
+void ft_lstsort(t_ftlst **begin_list, int (*cmp)(void *, void*))
+{
+ t_ftlst *fast;
+ t_ftlst *slow;
+ t_ftlst *middle;
+
+ if (begin_list == NULL || *begin_list == NULL
+ || (*begin_list)->next == NULL)
+ return ;
+ fast = (*begin_list)->next;
+ slow = *begin_list;
+ while (fast != NULL)
+ {
+ fast = fast->next;
+ if (fast != NULL)
+ {
+ fast = fast->next;
+ slow = slow->next;
+ }
+ }
+ middle = slow->next;
+ slow->next = NULL;
+ ft_lstsort(begin_list, cmp);
+ ft_lstsort(&middle, cmp);
+ *begin_list = ft_lstsorted_merge(*begin_list, middle, cmp);
+}
diff --git a/src/lst/ft_lstsorted_merge.c b/src/lst/ft_lstsorted_merge.c
new file mode 100644
index 0000000..c3d0391
--- /dev/null
+++ b/src/lst/ft_lstsorted_merge.c
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_lstsorted_merge.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/10 01:58:52 by cacharle #+# #+# */
+/* Updated: 2020/02/10 02:13:37 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_lst.h"
+
+t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2,
+ int (*cmp)(void *, void *))
+{
+ t_ftlst *merged;
+
+ merged = NULL;
+ if (l1 == NULL)
+ return (l2);
+ if (l2 == NULL)
+ return (l1);
+ if (cmp(l1->content, l2->content) < 0)
+ {
+ merged = l1;
+ merged->next = ft_lstsorted_merge(l1->next, l2, cmp);
+ }
+ else
+ {
+ merged = l2;
+ merged->next = ft_lstsorted_merge(l1, l2->next, cmp);
+ }
+ return (merged);
+}