aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-08-02 11:05:33 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-08-02 11:05:33 +0200
commit5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde (patch)
tree80911dc3c32e9f230750e7e1042d413dfb6efab2 /include
parentee32953ea79616e72f5428cdf40c834714a891c9 (diff)
parentb96b82194ccad2cddbb46b77aa1962a57c47ff44 (diff)
downloadlibft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.gz
libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.tar.bz2
libft-5d2f925b20ceaea4122c59d2d2c4e7d4ae991fde.zip
Merge branch 'master' into ft_ssl
Diffstat (limited to 'include')
-rw-r--r--include/libft.h14
-rw-r--r--include/libft_algo.h34
-rw-r--r--include/libft_bt.h37
-rw-r--r--include/libft_ctype.h2
-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.h71
-rw-r--r--include/libft_io.h64
-rw-r--r--include/libft_lst.h29
-rw-r--r--include/libft_mem.h41
-rw-r--r--include/libft_rbt.h95
-rw-r--r--include/libft_str.h27
-rw-r--r--include/libft_vec.h53
14 files changed, 464 insertions, 112 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_bt.h b/include/libft_bt.h
index 6e2cc91..7bd7eb4 100644
--- a/include/libft_bt.h
+++ b/include/libft_bt.h
@@ -6,23 +6,44 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/07 21:26:34 by cacharle #+# #+# */
-/* Updated: 2020/02/07 21:34:52 by cacharle ### ########.fr */
+/* Updated: 2020/04/26 19:45:56 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_BT_H
# define LIBFT_BT_H
+/*
+** \file libft_bt.h
+** \brief Binary tree
+*/
+
# include <stdlib.h>
-typedef struct s_ftbtree
+/*
+** \brief Binary tree struct
+** \param left Left node
+** \param right Right node
+** \param data Node data
+*/
+
+typedef struct s_ftbt
{
- void *data;
- struct s_ftbtree *left;
- struct s_ftbtree *right;
-} t_ftbtree;
+ struct s_ftbt *left;
+ struct s_ftbt *right;
+ void *data;
+} t_ftbt;
+
+t_ftbt *ft_btnew(void *data);
+void ft_btdestroy(t_ftbt *tree, void (*del)(void *data));
-t_ftbtree *ft_btnew(void *data);
-void ft_btdestroy(t_ftbtree *tree, void (*del)(void *data));
+t_ftbt *ft_btsorted_insert(
+ t_ftbt *tree,
+ void *data,
+ int (*cmp)(void*, void*));
+void *ft_btsorted_search(
+ t_ftbt *tree,
+ void *ref,
+ int (*cmp)(void*, void*));
#endif
diff --git a/include/libft_ctype.h b/include/libft_ctype.h
index ad42c64..61f4534 100644
--- a/include/libft_ctype.h
+++ b/include/libft_ctype.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:35:31 by cacharle #+# #+# */
-/* Updated: 2020/02/10 05:18:30 by cacharle ### ########.fr */
+/* Updated: 2020/02/28 12:08:52 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/include/libft_types.h b/include/libft_def.h
index 20fe0f7..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/13 03:07:56 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 62f2ee1..c53ee4d 100644
--- a/include/libft_ht.h
+++ b/include/libft_ht.h
@@ -6,52 +6,65 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:36:09 by cacharle #+# #+# */
-/* Updated: 2020/02/19 02:38:28 by cacharle ### ########.fr */
+/* Updated: 2020/04/04 22:34:53 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_HT_H
# define LIBFT_HT_H
+/*
+** \file libft_ht.h
+** \brief Hash table manipulation
+*/
+
# include "libft.h"
+# include "libft_def.h"
# include "libft_lst.h"
+# include "libft_mem.h"
+
+/*
+** \brief Hash table entry, key/value pair
+** \param key String key
+** \param value Pointer to data
+*/
-typedef struct s_ftht_content
+typedef struct s_ftht_entry
{
- char *key;
- void *value;
-} t_ftht_content;
+ char *key;
+ void *value;
+} t_ftht_entry;
-typedef t_ftlst* t_ftht_entry;
+/*
+** \brief Hash table struct
+** \param size Number of buckets
+** \param buckets Bucket array, each bucket is a linked list
+*/
-typedef struct s_ftht
+typedef struct s_ftht
{
- t_ftsize size;
- t_ftht_entry *entries;
-} t_ftht;
-
-typedef t_ftuint t_ftht_digest;
-
-t_ftht_digest ft_hthash(t_ftht *ht, char *key);
-
-t_ftht *ft_htnew(t_ftsize size);
-void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*));
-void ft_htdestroy_all(t_ftht *ht);
-void ft_htdestroy_key(t_ftht *ht);
-void *ft_htget(t_ftht *ht, char *key);
-t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value,
- void (*del)(t_ftht_content*));
-void ft_htdelone(t_ftht *ht, char *key,
- void (*del)(t_ftht_content*));
-void ft_htdelone_key(t_ftht *ht, char *key);
-t_ftht_content *ft_htcontent_new(char *key, void *value);
+ size_t size;
+ t_ftlst **buckets;
+} t_ftht;
+
+size_t ft_hthash(t_ftht *ht, char *key);
+
+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
*/
-void ft_inter_htdelcontent_key(t_ftht_content *content);
-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_io.h b/include/libft_io.h
index 869bb86..f0d6f49 100644
--- a/include/libft_io.h
+++ b/include/libft_io.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:35:43 by cacharle #+# #+# */
-/* Updated: 2020/02/22 10:36:44 by cacharle ### ########.fr */
+/* Updated: 2020/08/02 11:03:44 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,42 +18,52 @@
# include <fcntl.h>
# include <limits.h>
# include "libft.h"
+# include "libft_def.h"
-/*
-** output
-*/
+void ft_putendl(char *s);
+void ft_putchar(char c);
+void ft_putstr(char const *s);
+void ft_putnbr(int n);
+void ft_putnbr_base(int n, char *base);
+void ft_putchar_fd(char c, int fd);
+void ft_putstr_fd(char *s, int fd);
+void ft_putendl_fd(char *s, int fd);
+void ft_putnbr_fd(int n, int fd);
+void ft_putnbr_base_fd(int n, char *base, int fd);
-void ft_putendl(char *s);
-void ft_putchar(char c);
-void ft_putstr(char const *s);
-void ft_putnbr(int n);
-void ft_putchar_fd(char c, int fd);
-void ft_putstr_fd(char *s, int fd);
-void ft_putendl_fd(char *s, int fd);
-void ft_putnbr_fd(int n, int fd);
-void ft_putnbr_base(int n, char *base);
-void ft_putnbr_base_fd(int n, char *base, int fd);
+char ft_getchar(void);
-/*
-** input
-*/
+# ifndef FT_GETFILE_BUFFER_SIZE
+# define FT_GETFILE_BUFFER_SIZE 64
+# endif
+# if FT_GETFILE_BUFFER_SIZE <= 0
+# error "FT_GETFILE_BUFFER_SIZE must be > 0"
+# endif
-char ft_getchar(void);
-char *ft_read_fd(int fd);
-char *ft_read_file(char *filename);
+typedef struct s_ftmem
+{
+ void *data;
+ size_t size;
+} t_ftmem;
-# ifndef FTNL_BUFFER_SIZE
-# define FTNL_BUFFER_SIZE 32
+int ft_getfile_fd(int fd, t_ftmem *mem);
+int ft_getfile(char *filename, t_ftmem *mem);
+
+# ifndef FT_GETLINE_BUFFER_SIZE
+# define FT_GETLINE_BUFFER_SIZE 64
+# endif
+# if FT_GETLINE_BUFFER_SIZE <= 0
+# error "FT_GETLINE_BUFFER_SIZE must be > 0"
# endif
-# define FTNL_STATUS_LINE 1
-# define FTNL_STATUS_EOF 0
-# define FTNL_STATUS_ERROR -1
+# define FT_LINE 1
+# define FT_EOF 0
+# define FT_ERROR -1
/*
-** get_next_line.c
+** getline.c
*/
-int ft_next_line(int fd, char **line);
+int ft_getline(int fd, char **line);
#endif
diff --git a/include/libft_lst.h b/include/libft_lst.h
index a48c1aa..2938bd2 100644
--- a/include/libft_lst.h
+++ b/include/libft_lst.h
@@ -6,36 +6,47 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/31 10:36:39 by cacharle #+# #+# */
-/* Updated: 2020/02/17 03:05:36 by cacharle ### ########.fr */
+/* Updated: 2020/04/01 17:59:50 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_LST_H
# define LIBFT_LST_H
+/*
+** \file libft_lst.h
+** \brief Linked list Manipulation
+*/
+
# include <stdlib.h>
-# include "libft_types.h"
+# include "libft_def.h"
# include "libft_algo.h"
+/*
+** \brief List struct
+** \param data Pointer to node data
+** \param next Pointer to next node or NULL if last node
+*/
+
typedef struct s_ftlst
{
- void *content;
+ void *data;
struct s_ftlst *next;
} t_ftlst;
-typedef void (*t_ftdel_func)(void *);
+typedef void (*t_ftdel_func)(void *);
-t_ftlst *ft_lstnew(void const *content);
-void ft_lstadd_front(t_ftlst **alst, t_ftlst *new);
+t_ftlst *ft_lstnew(void const *data);
int ft_lstsize(t_ftlst *lst);
+void ft_lstpush_front(t_ftlst **alst, t_ftlst *new);
+void ft_lstpush_back(t_ftlst **alst, t_ftlst *new);
+void ft_lstpop_front(t_ftlst **lst, void (*del)(void *));
t_ftlst *ft_lstlast(t_ftlst *lst);
-void ft_lstadd_back(t_ftlst **alst, t_ftlst *new);
void ft_lstdelone(t_ftlst *lst, void (*del)(void *));
-void ft_lstclear(t_ftlst **lst, void (*del)(void *));
+void ft_lstdestroy(t_ftlst **lst, void (*del)(void *));
void ft_lstiter(t_ftlst *lst, void (*f)(void *));
t_ftlst *ft_lstmap(t_ftlst *lst, void *(*f)(void *),
t_ftdel_func del);
-void ft_lstpop_front(t_ftlst **lst, void (*del)(void *));
t_ftlst *ft_lstreverse_ret(t_ftlst *lst);
void ft_lstreverse(t_ftlst **lst);
void ft_lstremove_if(t_ftlst **lst,
diff --git a/include/libft_mem.h b/include/libft_mem.h
index e03b6fa..3d7ca26 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/08/01 15:28:15 by charles ### ########.fr */
+/* Updated: 2020/08/02 10:50:39 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,28 +15,31 @@
# include <stddef.h>
# include <stdlib.h>
-# include "libft_types.h"
-
-void ft_bzero(void *s, size_t n);
-void *ft_memset(void *s, int c, size_t n);
-void *ft_memcpy(void *dest, const void *src, size_t n);
-void *ft_memccpy(void *dest, const void *src, int c, size_t n);
-void *ft_memmove(void *dst, const void *src, size_t len);
-void *ft_memchr(const void *s, int c, size_t n);
-int ft_memcmp(const void *s1, const void *s2, size_t n);
-void *ft_calloc(size_t count, size_t size);
-void ft_memswap(void *a, void *b, size_t size);
-void *ft_memmem(const void *big, size_t big_len,
- const void *little, size_t little_len);
-void ft_memset_pattern4(void *b, const void *pattern4,
- size_t len);
-
-void *ft_realloc(void *ptr, size_t ptr_size, size_t size);
+# include "libft_def.h"
+
+void ft_bzero(void *s, size_t n);
+void *ft_memset(void *s, int c, size_t n);
+void *ft_memcpy(void *dest, const void *src, size_t n);
+void *ft_memccpy(void *dest, const void *src, int c, size_t n);
+void *ft_memmove(void *dst, const void *src, size_t len);
+void *ft_memchr(const void *s, int c, size_t n);
+int ft_memcmp(const void *s1, const void *s2, size_t n);
+void *ft_calloc(size_t count, size_t size);
+void ft_memswap(void *a, void *b, size_t size);
+void ft_memset_pattern4(void *b, const void *pattern4, size_t len);
+void *ft_memjoin(void *m1, size_t m1_size, void *m2, size_t m2_size);
+void *ft_memjoinf1(void *m1, size_t m1_size, void *m2, size_t m2_size);
+
+void *ft_realloc(void *ptr, size_t ptr_size, size_t size);
+
+void *ft_memmem(
+ const void *big, size_t big_len,
+ const void *little, size_t little_len);
/*
** bloat ?
*/
-void ft_memdel(void **ap);
+void ft_memdel(void **ap);
#endif
diff --git a/include/libft_rbt.h b/include/libft_rbt.h
new file mode 100644
index 0000000..6865cdf
--- /dev/null
+++ b/include/libft_rbt.h
@@ -0,0 +1,95 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_rbt.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/26 16:09:51 by charles #+# #+# */
+/* Updated: 2020/05/11 16:11:16 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_RBT_H
+# define LIBFT_RBT_H
+
+/*
+** \file libft_rbt.h
+** \brief Red-black tree
+**
+** Rules: (from wikipedia)
+** 1. Each node is either red or black.
+** 2. The root is black. This rule is sometimes omitted. Since the root can
+** always be changed from red to black, but not necessarily vice versa,
+** this rule has little effect on analysis.
+** 3. All leaves (NULL) are black.
+** 4. If a node is red, then both its children are black.
+** 5. Every path from a given node to any of its descendant NULL nodes goes
+** through the same number of black nodes.
+**
+**
+** Unbalance case:
+**
+** 1. Node and parent are both red
+**
+** B1
+** \ left rot color swap
+** > R2 --> R2 --> B2
+** \ / \ / \
+** > R3 B1 R3 R1 R3
+**
+** 2. Node and parent are both red and uncle node is red
+**
+** B2 R2
+** / \ color swap / \
+** uncle> R1 R3 --> B1 B3
+** \ \
+** R4 R4
+*/
+
+# include <stdlib.h>
+
+/*
+** \brief Red-black tree color enum
+** \param FTRBT_COLOR_RED color red
+** \param FTRBT_COLOR_BLACK color black
+*/
+
+enum e_ftrbt_color
+{
+ FTRBT_COLOR_RED = 0,
+ FTRBT_COLOR_BLACK,
+};
+
+/*
+** \brief Red-black tree struct
+** \param left Left node
+** \param right Right node
+** \param data Pointer to data
+** \param parent Parent node
+** \param color Color of the node
+** \note The first 3 attricutes are the same
+** as t_ftbt (binary tree) struct
+** which means that we can use all functions
+** of binary tree on red-black tree.
+*/
+
+typedef struct s_ftrbt
+{
+ struct s_ftrbt *left;
+ struct s_ftrbt *right;
+ void *data;
+ struct s_ftrbt *parent;
+ enum e_ftrbt_color color;
+} t_ftrbt;
+
+t_ftrbt *ft_rbtnew(void *data, enum e_ftrbt_color color);
+void ft_rbtrotate_right(t_ftrbt **tree);
+void ft_rbtrotate_left(t_ftrbt **tree);
+
+t_ftrbt *ft_rbtinsert(
+ t_ftrbt *tree,
+ void *data,
+ int (*cmp)(void*, void*));
+
+#endif
diff --git a/include/libft_str.h b/include/libft_str.h
index fca5fbc..571cda0 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/08/01 18:55:31 by charles ### ########.fr */
+/* Updated: 2020/08/02 10:52:36 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,9 @@
# define LIBFT_STR_H
# include <stddef.h>
+# include <stdbool.h>
# include "libft_ctype.h"
+# include "libft_mem.h"
typedef enum
{
@@ -50,8 +52,10 @@ 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);
char *ft_strtrim(char const *s1, char const *set);
char **ft_split(char const *s, char c);
@@ -59,6 +63,8 @@ int ft_strcount(char *str, char c);
char *ft_itoa(int n);
int ft_atoi_strict(const char *s);
long ft_strtol(const char *s, char **endptr, int base);
+float ft_strtof(const char *nptr, char **endptr);
+float ft_atof(const char *nptr);
int ft_strcasecmp(const char *s1, const char *s2);
int ft_strncasecmp(const char *s1, const char *s2, size_t n);
size_t ft_strspn(const char *s, const char *charset);
@@ -73,6 +79,23 @@ int ft_strnequ(char const *s1, char const *s2, size_t n);
char *ft_strtolower(char *s);
char *ft_strtoupper(char *s);
char *ft_strnew(size_t size);
+char *ft_strcat3(char *dest, const char *src1, const char *src2);
+char *ft_strmove(char *dest, const char *src);
+
+/*
+** 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);
+void *ft_strsdestroy(char **strs);
+size_t ft_strslen(char **strs);
/*
** bloat ?
diff --git a/include/libft_vec.h b/include/libft_vec.h
new file mode 100644
index 0000000..c31b36e
--- /dev/null
+++ b/include/libft_vec.h
@@ -0,0 +1,53 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_vec.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 18:57:16 by charles #+# #+# */
+/* Updated: 2020/05/12 18:36:00 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_VEC_H
+# define LIBFT_VEC_H
+
+/*
+** \file libft_vec.h
+** \brief Vector manipulation
+*/
+
+# include <stdlib.h>
+# include "libft_def.h"
+# include "libft_mem.h"
+# include "libft_algo.h"
+
+/*
+** \brief Vector struct
+** \param data Underlying array
+** \param capacity Size of the underlying array
+** \param size Number of element in the vector
+*/
+
+typedef struct s_ftvec
+{
+ void **data;
+ size_t capacity;
+ size_t size;
+} t_ftvec;
+
+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_veciter_ret(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);
+void *ft_vectobuf32(t_ftvec *vec);
+
+#endif