aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/algo/ft_compar_int.c9
-rw-r--r--src/algo/ft_compar_str.c25
-rw-r--r--src/algo/ft_is_set.c13
-rw-r--r--src/algo/ft_mergesort.c24
-rw-r--r--src/algo/ft_qsort.c35
-rw-r--r--src/algo/ft_reverse.c9
-rw-r--r--src/bt/ft_btdestroy.c13
-rw-r--r--src/bt/ft_btnew.c16
-rw-r--r--src/bt/ft_btsorted_insert.c38
-rw-r--r--src/bt/ft_btsorted_search.c35
-rw-r--r--src/dlst/ft_dlstdelone.c26
-rw-r--r--src/dlst/ft_dlstdestroy.c32
-rw-r--r--src/dlst/ft_dlstnew.c25
-rw-r--r--src/dstr/ft_dstrdestroy.c26
-rw-r--r--src/dstr/ft_dstrerase.c35
-rw-r--r--src/dstr/ft_dstrgrow.c41
-rw-r--r--src/dstr/ft_dstrinsert.c38
-rw-r--r--src/dstr/ft_dstrnew.c36
-rw-r--r--src/dstr/ft_dstrsubstitute.c32
-rw-r--r--src/dstr/ft_dstrunwrap.c28
-rw-r--r--src/ht/ft_htdelone.c17
-rw-r--r--src/ht/ft_htdestroy.c20
-rw-r--r--src/ht/ft_htentry_new.c (renamed from src/ht/ft_htcontent_new.c)14
-rw-r--r--src/ht/ft_htget.c18
-rw-r--r--src/ht/ft_hthash.c12
-rw-r--r--src/ht/ft_htiter.c31
-rw-r--r--src/ht/ft_htnew.c15
-rw-r--r--src/ht/ft_htset.c50
-rw-r--r--src/ht/ft_inter_htdel_first_order.c33
-rw-r--r--src/ht/ft_inter_htkey_cmp.c8
-rw-r--r--src/io/ft_getfile.c (renamed from src/io/ft_read_file.c)24
-rw-r--r--src/io/ft_getfile_fd.c40
-rw-r--r--src/io/ft_getline.c82
-rw-r--r--src/io/ft_next_line.c113
-rw-r--r--src/io/ft_printf/internals/list.c4
-rw-r--r--src/io/ft_printf/internals/parse.c2
-rw-r--r--src/lst/ft_lstbsearch.c6
-rw-r--r--src/lst/ft_lstdelone.c10
-rw-r--r--src/lst/ft_lstdestroy.c (renamed from src/lst/ft_lstclear.c)12
-rw-r--r--src/lst/ft_lstiter.c10
-rw-r--r--src/lst/ft_lstlast.c8
-rw-r--r--src/lst/ft_lstlfind.c6
-rw-r--r--src/lst/ft_lstlsearch.c6
-rw-r--r--src/lst/ft_lstmap.c21
-rw-r--r--src/lst/ft_lstnew.c12
-rw-r--r--src/lst/ft_lstpop_front.c10
-rw-r--r--src/lst/ft_lstpush_back.c (renamed from src/lst/ft_lstadd_back.c)10
-rw-r--r--src/lst/ft_lstpush_front.c (renamed from src/lst/ft_lstadd_front.c)10
-rw-r--r--src/lst/ft_lstremove_if.c12
-rw-r--r--src/lst/ft_lstreverse.c5
-rw-r--r--src/lst/ft_lstreverse_ret.c6
-rw-r--r--src/lst/ft_lstsize.c8
-rw-r--r--src/lst/ft_lstsort.c6
-rw-r--r--src/lst/ft_lstsorted_merge.c10
-rw-r--r--src/mem/ft_memccpy.c58
-rw-r--r--src/mem/ft_memchr.c41
-rw-r--r--src/mem/ft_memcmp.c46
-rw-r--r--src/mem/ft_memcpy.c10
-rw-r--r--src/mem/ft_memjoin.c24
-rw-r--r--src/mem/ft_memjoinf1.c22
-rw-r--r--src/mem/ft_memmove.c13
-rw-r--r--src/mem/ft_memset.c34
-rw-r--r--src/rbt/ft_rbtinsert.c83
-rw-r--r--src/rbt/ft_rbtnew.c35
-rw-r--r--src/rbt/ft_rbtrotate_left.c38
-rw-r--r--src/rbt/ft_rbtrotate_right.c38
-rw-r--r--src/str/ft_atof.c18
-rw-r--r--src/str/ft_atoi.c9
-rw-r--r--src/str/ft_fnmatch.c37
-rw-r--r--src/str/ft_split.c14
-rw-r--r--src/str/ft_strcasecmp.c2
-rw-r--r--src/str/ft_strcat.c1
-rw-r--r--src/str/ft_strcat3.c26
-rw-r--r--src/str/ft_strcmp.c7
-rw-r--r--src/str/ft_strdup.c7
-rw-r--r--src/str/ft_strjoin3.c36
-rw-r--r--src/str/ft_strjoinf.c4
-rw-r--r--src/str/ft_strlen.c78
-rw-r--r--src/str/ft_strmove.c25
-rw-r--r--src/str/ft_strncasecmp.c2
-rw-r--r--src/str/ft_strncat.c18
-rw-r--r--src/str/ft_strncmp.c15
-rw-r--r--src/str/ft_strnew.c19
-rw-r--r--src/str/ft_strsdestroy.c30
-rw-r--r--src/str/ft_strsep.c15
-rw-r--r--src/str/ft_strsjoin.c50
-rw-r--r--src/str/ft_strsjoinf.c29
-rw-r--r--src/str/ft_strslen.c23
-rw-r--r--src/str/ft_strstr.c9
-rw-r--r--src/str/ft_strsub.c (renamed from src/str/ft_substr.c)25
-rw-r--r--src/str/ft_strsubf.c30
-rw-r--r--src/str/ft_strtof.c44
-rw-r--r--src/str/ft_strtrim.c4
-rw-r--r--src/vec/ft_vecdestroy.c29
-rw-r--r--src/vec/ft_vecgrow.c43
-rw-r--r--src/vec/ft_vecinsert.c36
-rw-r--r--src/vec/ft_veciter.c31
-rw-r--r--src/vec/ft_veciter_ret.c33
-rw-r--r--src/vec/ft_vecnew.c38
-rw-r--r--src/vec/ft_vecpop.c28
-rw-r--r--src/vec/ft_vecpush.c30
-rw-r--r--src/vec/ft_vecpush_safe.c (renamed from src/io/ft_read_fd.c)37
-rw-r--r--src/vec/ft_vecremove.c31
-rw-r--r--src/vec/ft_vecsort.c24
-rw-r--r--src/vec/ft_vectobuf32.c29
105 files changed, 2184 insertions, 411 deletions
diff --git a/src/algo/ft_compar_int.c b/src/algo/ft_compar_int.c
index 848dc71..ab057bf 100644
--- a/src/algo/ft_compar_int.c
+++ b/src/algo/ft_compar_int.c
@@ -6,12 +6,19 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/19 08:24:43 by cacharle #+# #+# */
-/* Updated: 2020/01/19 08:27:38 by cacharle ### ########.fr */
+/* Updated: 2020/04/04 22:30:09 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
+/*
+** \brief Comparison function for 2 ints
+** \param a Pointer to first int
+** \param b Pointer to first int
+** \return The difference between a and b
+*/
+
int ft_compar_int(const void *a, const void *b)
{
return (*(int*)a - *(int*)b);
diff --git a/src/algo/ft_compar_str.c b/src/algo/ft_compar_str.c
new file mode 100644
index 0000000..6749ab0
--- /dev/null
+++ b/src/algo/ft_compar_str.c
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_compar_str.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/04 15:44:24 by charles #+# #+# */
+/* Updated: 2020/04/04 22:31:15 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_algo.h"
+
+/*
+** \brief String comparison function
+** \param s1_p Pointer to first string
+** \param s2_p Pointer to second string
+** \return `strcmp` of both strings
+*/
+
+int ft_compar_str(const void *s1_p, const void *s2_p)
+{
+ return (ft_strcmp(*(const char**)s1_p, *(const char**)s2_p));
+}
diff --git a/src/algo/ft_is_set.c b/src/algo/ft_is_set.c
index 3e7ae31..fd26a88 100644
--- a/src/algo/ft_is_set.c
+++ b/src/algo/ft_is_set.c
@@ -6,14 +6,21 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/19 07:17:15 by cacharle #+# #+# */
-/* Updated: 2020/02/10 02:51:41 by cacharle ### ########.fr */
+/* Updated: 2020/04/04 22:33:03 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#include "libft.h"
#include "libft_algo.h"
-t_ftbool ft_is_set(void *base, size_t nel, size_t width,
+/*
+** \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;
diff --git a/src/algo/ft_mergesort.c b/src/algo/ft_mergesort.c
index 25b4255..8556145 100644
--- a/src/algo/ft_mergesort.c
+++ b/src/algo/ft_mergesort.c
@@ -6,12 +6,19 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/10 02:26:41 by cacharle #+# #+# */
-/* Updated: 2020/02/13 23:14:21 by cacharle ### ########.fr */
+/* Updated: 2020/04/04 22:40:55 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft_algo.h"
+/*
+** \brief Helper function to return in case of error
+** \param left Left subarray
+** \param right Right subarray
+** \return -1 to indicate error
+*/
+
static int st_mergesort_error(void *left, void *right)
{
free(left);
@@ -19,6 +26,13 @@ static int st_mergesort_error(void *left, void *right)
return (-1);
}
+/*
+** \brief Merge 2 sorted arrays
+** \param arrays Struct containing the arrays (base, left, right)
+** \param nel Number of element in base
+** \param compar Comparison function
+*/
+
static void st_merge_sorted(struct s_merge_sorted_arrays *arrays, size_t nel,
size_t width, int (*compar)(const void *, const void *))
{
@@ -49,6 +63,14 @@ static void st_merge_sorted(struct s_merge_sorted_arrays *arrays, size_t nel,
arrays->right + ri++ * width, width);
}
+/*
+** \brief Sort an array using the merge sort algorithm
+** \param base Array to sort
+** \param nel Number of element in the array
+** \param width Size of each element
+** \return 0 on success, -1 on error
+*/
+
int ft_mergesort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *))
{
diff --git a/src/algo/ft_qsort.c b/src/algo/ft_qsort.c
index 9bcfcdf..0c1c0f7 100644
--- a/src/algo/ft_qsort.c
+++ b/src/algo/ft_qsort.c
@@ -6,12 +6,19 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/19 07:25:51 by cacharle #+# #+# */
-/* Updated: 2020/02/10 02:55:14 by cacharle ### ########.fr */
+/* Updated: 2020/04/04 22:10:29 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft_algo.h"
+/*
+** \brief Helper to create a new range
+** \param lo Lower bound
+** \param hi Higher bound