aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-09 12:31:50 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-09 12:31:50 +0200
commit02abc030a68cb2fdd2f21c96db830ec8cb9176ad (patch)
tree0c2d67c94a3618639fc2cd29d8bc78820e41c254 /include
parentb5124347359833fcde33452978c62133879c6c9e (diff)
parent3a2d19df9e509d0b015c786eb02f8315ff0ad91c (diff)
downloadlibft-02abc030a68cb2fdd2f21c96db830ec8cb9176ad.tar.gz
libft-02abc030a68cb2fdd2f21c96db830ec8cb9176ad.tar.bz2
libft-02abc030a68cb2fdd2f21c96db830ec8cb9176ad.zip
Merge remote-tracking branch 'origin/minishell'
Diffstat (limited to 'include')
-rw-r--r--include/libft.h14
-rw-r--r--include/libft_algo.h34
-rw-r--r--include/libft_def.h (renamed from include/libft_types.h)35
-rw-r--r--include/libft_dlst.h30
-rw-r--r--include/libft_dstr.h44
-rw-r--r--include/libft_ht.h51
-rw-r--r--include/libft_lst.h2
-rw-r--r--include/libft_mem.h5
-rw-r--r--include/libft_str.h20
-rw-r--r--include/libft_vec.h9
10 files changed, 193 insertions, 51 deletions
diff --git a/include/libft.h b/include/libft.h
index 74f074b..e982608 100644
--- a/include/libft.h
+++ b/include/libft.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/07 09:45:02 by cacharle #+# #+# */
-/* Updated: 2020/02/10 02:19:47 by cacharle ### ########.fr */
+/* Updated: 2020/04/03 06:32:37 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,18 +17,18 @@
# include <stdarg.h>
# include <stdlib.h>
# include <stddef.h>
+# include <stdbool.h>
# include <limits.h>
# include <errno.h>
-# include "libft_types.h"
-# include "libft_ctype.h"
-# include "libft_io.h"
-# include "libft_mem.h"
-# include "libft_str.h"
-
# ifdef __linux__
# include <stdio.h>
# define OPEN_MAX FOPEN_MAX
# endif
+# include "libft_io.h"
+# include "libft_mem.h"
+# include "libft_str.h"
+# include "libft_ctype.h"
+
#endif
diff --git a/include/libft_algo.h b/include/libft_algo.h
index 7223e7b..e859de5 100644
--- a/include/libft_algo.h
+++ b/include/libft_algo.h
@@ -1,24 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_algo.h :+: :+: :+: */
+/* libft_algo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/19 07:22:57 by cacharle #+# #+# */
-/* Updated: 2020/02/10 05:58:26 by cacharle ### ########.fr */
+/* Updated: 2020/04/04 23:33:51 by charles ### ########.fr */
/* */
/* ************************************************************************** */
+/*
+** \file libft_algo.h
+** \brief Algorithms
+*/
+
#ifndef LIBFT_ALGO_H
# define LIBFT_ALGO_H
# include <stdlib.h>
-# include <stddef.h>
# include "libft_mem.h"
-# include "libft_types.h"
+# include "libft_def.h"
+# include "libft_str.h"
-typedef int (*t_ftcompar_func)(const void*, const void*);
+/*
+** \brief Range struct
+** \param lo Lower bound
+** \param hi Upper bound
+*/
typedef struct
{
@@ -26,6 +35,14 @@ typedef struct
int hi;
} t_ftrange;
+/*
+** \brief Merge sort consts struct
+** \param base Array to sort
+** \param left Left subarray
+** \param right Right subarray
+** \note Only used internaly by ft_mergesort
+*/
+
struct s_merge_sorted_arrays
{
void *base;
@@ -33,15 +50,20 @@ struct s_merge_sorted_arrays
void *right;
};
+/*
+** remove this horror
+*/
+
typedef struct s_ft_search_const
{
const void *key;
t_ftcompar_func compar;
} t_ftsearch_const;
-t_ftbool ft_is_set(void *base, size_t nel, size_t width,
+bool ft_is_set(void *base, size_t nel, size_t width,
t_ftcompar_func compar);
int ft_compar_int(const void *a, const void *b);
+int ft_compar_str(const void *s1_p, const void *s2_p);
void ft_qsort(void *base, size_t nel, size_t width,
t_ftcompar_func compar);
int ft_mergesort(void *base, size_t nel, size_t width,
diff --git a/include/libft_types.h b/include/libft_def.h
index 3987a80..fa8d550 100644
--- a/include/libft_types.h
+++ b/include/libft_def.h
@@ -1,17 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* libft_types.h :+: :+: :+: */
+/* libft_def.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:36:56 by cacharle #+# #+# */
-/* Updated: 2020/02/28 12:10:02 by cacharle ### ########.fr */
+/* Updated: 2020/05/09 12:31:09 by charles ### ########.fr */
/* */
/* ************************************************************************** */
-#ifndef LIBFT_TYPES_H
-# define LIBFT_TYPES_H
+/*
+** \file libft_def.h
+** \brief Type and constant definition
+*/
+
+#ifndef LIBFT_DEF_H
+# define LIBFT_DEF_H
+
+# include <stddef.h>
+# include <stdint.h>
+# include <stdbool.h>
# define TRUE 1
# define FALSE 0
@@ -27,4 +36,22 @@ typedef unsigned int t_ftuint;
typedef long int t_ftlong;
typedef unsigned long int t_ftulong;
+/*
+** \brief Standard delete function
+** \param x Resource to delete
+*/
+
+typedef void (*t_ftdel_func)(void *x);
+
+/*
+** \brief Standard comparison function
+** \param x1 Resource 1
+** \param x2 Resource 2
+** \return negative number if x1 < x2,
+** 0 if x1 == x2,
+** positive number if x1 > x2
+*/
+
+typedef int (*t_ftcompar_func)(const void *x1, const void *x2);
+
#endif
diff --git a/include/libft_dlst.h b/include/libft_dlst.h
new file mode 100644
index 0000000..9870ea7
--- /dev/null
+++ b/include/libft_dlst.h
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_dlst.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/03 15:15:04 by charles #+# #+# */
+/* Updated: 2020/04/03 15:44:32 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_DLST_H
+# define LIBFT_DLST_H
+
+# include <stdlib.h>
+# include "libft_def.h"
+
+typedef struct s_ftdlst
+{
+ struct s_ftdlst *prev;
+ struct s_ftdlst *next;
+ void *data;
+} t_ftdlst;
+
+t_ftdlst *ft_dlstnew(void *data);
+void ft_dlstdestroy(t_ftdlst *dlst, t_ftdel_func del);
+void ft_dlstdelone(t_ftdlst *dlst, t_ftdel_func del);
+
+#endif
diff --git a/include/libft_dstr.h b/include/libft_dstr.h
new file mode 100644
index 0000000..732e475
--- /dev/null
+++ b/include/libft_dstr.h
@@ -0,0 +1,44 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_dstr.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/03 10:39:51 by charles #+# #+# */
+/* Updated: 2020/04/05 00:37:05 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_DSTR_H
+# define LIBFT_DSTR_H
+
+# include <stdlib.h>
+# include "libft_def.h"
+# include "libft_str.h"
+# include "libft_mem.h"
+
+/*
+** \brief Dynamic string struct
+** \param str Underlying null-terminated character array
+** \param length Number of character (not including the '\0')
+** \param capacity Maximum length - 1 of the current string
+*/
+
+typedef struct s_ftdstr
+{
+ char *str;
+ size_t length;
+ size_t capacity;
+} t_ftdstr;
+
+t_ftdstr *ft_dstrnew(char *from);
+void ft_dstrdestroy(t_ftdstr *dstr);
+t_ftdstr *ft_dstrgrow(t_ftdstr *dstr, size_t at_least);
+char *ft_dstrunwrap(t_ftdstr *dstr);
+t_ftdstr *ft_dstrinsert(t_ftdstr *dstr, char *inserted, size_t i);
+void ft_dstrerase(t_ftdstr *dstr, size_t start, size_t len);
+t_ftdstr *ft_dstrsubstitute(t_ftdstr *dstr, char *replacement,
+ size_t start, size_t end);
+
+#endif
diff --git a/include/libft_ht.h b/include/libft_ht.h
index 10c6fc7..c53ee4d 100644
--- a/include/libft_ht.h
+++ b/include/libft_ht.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:36:09 by cacharle #+# #+# */
-/* Updated: 2020/04/01 17:59:35 by charles ### ########.fr */
+/* Updated: 2020/04/04 22:34:53 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,9 @@
*/
# include "libft.h"
+# include "libft_def.h"
# include "libft_lst.h"
+# include "libft_mem.h"
/*
** \brief Hash table entry, key/value pair
@@ -27,45 +29,42 @@
** \param value Pointer to data
*/
-typedef struct s_ftht_entry
+typedef struct s_ftht_entry
{
- char *key;
- void *value;
-} t_ftht_entry;
-
-typedef t_ftlst* t_ftht_bucket;
+ char *key;
+ void *value;
+} t_ftht_entry;
/*
** \brief Hash table struct
** \param size Number of buckets
-** \param buckets Bucket array
+** \param buckets Bucket array, each bucket is a linked list
*/
-typedef struct s_ftht
+typedef struct s_ftht
{
- t_ftsize size;
- t_ftht_bucket *buckets;
-} t_ftht;
-
-typedef t_ftuint t_ftht_digest;
+ size_t size;
+ t_ftlst **buckets;
+} t_ftht;
-t_ftht_digest ft_hthash(t_ftht *ht, char *key);
+size_t ft_hthash(t_ftht *ht, char *key);
-t_ftht *ft_htnew(t_ftsize size);
-void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_entry*));
-void *ft_htget(t_ftht *ht, char *key);
-t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value,
- void (*del)(t_ftht_entry*));
-void ft_htdelone(t_ftht *ht, char *key,
- void (*del)(t_ftht_entry*));
-t_ftht_entry *ft_htentry_new(char *key, void *value);
-void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*));
+t_ftht *ft_htnew(size_t size);
+void ft_htdestroy(t_ftht *ht, t_ftdel_func del);
+void *ft_htget(t_ftht *ht, char *key);
+t_ftht_entry *ft_htset(t_ftht *ht, char *key, void *value,
+ t_ftdel_func del);
+void ft_htdelone(t_ftht *ht, char *key, t_ftdel_func del);
+t_ftht_entry *ft_htentry_new(char *key, void *value);
+void ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*));
/*
** internals
*/
-int ft_inter_htkey_cmp(const void *ref_key,
- const void *content);
+int ft_inter_htkey_cmp(const void *ref_key, const void *content);
+void ft_inter_htdel_first_order(t_ftht_entry *entry);
+void ft_inter_htdel_first_order_setup(t_ftdel_func del);
+void ft_inter_htdel_first_order_teardown(void);
#endif
diff --git a/include/libft_lst.h b/include/libft_lst.h
index d7157a9..2938bd2 100644
--- a/include/libft_lst.h
+++ b/include/libft_lst.h
@@ -19,7 +19,7 @@
*/
# include <stdlib.h>
-# include "libft_types.h"
+# include "libft_def.h"
# include "libft_algo.h"
/*
diff --git a/include/libft_mem.h b/include/libft_mem.h
index 7ec7122..f26180d 100644
--- a/include/libft_mem.h
+++ b/include/libft_mem.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:35:57 by cacharle #+# #+# */
-/* Updated: 2020/02/28 12:17:48 by cacharle ### ########.fr */
+/* Updated: 2020/05/09 12:28:55 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,8 +14,7 @@
# define LIBFT_MEM_H
# include <stddef.h>
-# include <stdint.h>
-# include "libft_types.h"
+# include "libft_def.h"
void ft_bzero(void *s, size_t n);
void *ft_memset(void *s, int c, size_t n);
diff --git a/include/libft_str.h b/include/libft_str.h
index a373e86..07a5fe0 100644
--- a/include/libft_str.h
+++ b/include/libft_str.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:39:22 by cacharle #+# #+# */
-/* Updated: 2020/05/08 13:39:12 by charles ### ########.fr */
+/* Updated: 2020/05/09 12:29:21 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,7 @@
# define LIBFT_STR_H
# include <stddef.h>
+# include <stdbool.h>
# include "libft_ctype.h"
# include "libft_mem.h"
# include "libft_util.h"
@@ -52,7 +53,8 @@ int ft_atoi(const char *nptr);
void ft_striter(char *s, void (*f)(char *));
void ft_striteri(char *s, void (*f)(unsigned int, char *));
-char *ft_substr(char const *s, unsigned int start, size_t len);
+char *ft_strsub(char const *s, size_t start, size_t len);
+char *ft_strsubf(char const *s, size_t start, size_t len);
char *ft_strjoin(char const *s1, char const *s2);
char *ft_strjoin3(char const *s1, char const *s2, char const *s3);
char *ft_strjoinf(char const *s1, char const *s2, t_ftstrjoinf_tag tag);
@@ -75,6 +77,20 @@ int ft_strequ(char const *s1, char const *s2);
int ft_strnequ(char const *s1, char const *s2, size_t n);
char *ft_strtolower(char *s);
char *ft_strtoupper(char *s);
+char *ft_strcat3(char *dest, const char *src1, const char *src2);
+
+/*
+** glob
+*/
+
+bool ft_fnmatch(const char *pattern, const char *string);
+
+/*
+** NULL terminated string array
+*/
+
+char *ft_strsjoin(char **strs, char *delim);
+char *ft_strsjoinf(char **strs, char *delim);
/*
** bloat ?
diff --git a/include/libft_vec.h b/include/libft_vec.h
index 62ec257..8424bd5 100644
--- a/include/libft_vec.h
+++ b/include/libft_vec.h
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 18:57:16 by charles #+# #+# */
-/* Updated: 2020/04/01 19:40:53 by charles ### ########.fr */
+/* Updated: 2020/04/04 15:55:29 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,8 +19,9 @@
*/
# include <stdlib.h>
-# include <stddef.h>
+# include "libft_def.h"
# include "libft_mem.h"
+# include "libft_algo.h"
/*
** \brief Vector struct
@@ -40,7 +41,11 @@ t_ftvec *ft_vecnew(size_t capacity);
void ft_vecdestroy(t_ftvec *vec, void (*del)(void *elem));
t_ftvec *ft_vecgrow(t_ftvec *vec);
t_ftvec *ft_vecpush(t_ftvec *vec, void *pushed);
+t_ftvec *ft_vecpush_safe(t_ftvec *vec, void *pushed);
void ft_vecpop(t_ftvec *vec, void (*del)(void *elem));
void ft_veciter(t_ftvec *vec, void (*f)(void *elem));
+void ft_vecremove(t_ftvec *vec, size_t i, void (*del)(void *elem));
+t_ftvec *ft_vecinsert(t_ftvec *vec, size_t i, void *elem);
+void ft_vecsort(t_ftvec *vec, t_ftcompar_func cmp);
#endif