diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bt/ft_btdestroy.c | 23 | ||||
| -rw-r--r-- | src/bt/ft_btnew.c | 25 | ||||
| -rw-r--r-- | src/ctype/ft_isascii.c | 6 | ||||
| -rw-r--r-- | src/ht/ft_htcontent_new.c | 31 | ||||
| -rw-r--r-- | src/ht/ft_htdelone.c | 21 | ||||
| -rw-r--r-- | src/ht/ft_htdelone_key.c (renamed from src/io/ft_printf.c) | 17 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy.c | 24 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy_all.c | 26 | ||||
| -rw-r--r-- | src/ht/ft_htdestroy_key.c | 26 | ||||
| -rw-r--r-- | src/ht/ft_htget.c | 28 | ||||
| -rw-r--r-- | src/ht/ft_hthash.c | 28 | ||||
| -rw-r--r-- | src/ht/ft_htnew.c | 32 | ||||
| -rw-r--r-- | src/ht/ft_htset.c | 34 | ||||
| -rw-r--r-- | src/ht/ft_inter_htkey_equal.c | 21 | ||||
| -rw-r--r-- | src/io/ft_next_line.c (renamed from src/io/get_next_line/get_next_line.c) | 58 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_asprintf.c (renamed from src/io/ft_asprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_dprintf.c (renamed from src/io/ft_dprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_printf.c | 88 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_snprintf.c (renamed from src/io/ft_snprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_sprintf.c (renamed from src/io/ft_sprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_vasprintf.c (renamed from src/io/ft_vasprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_vdprintf.c (renamed from src/io/ft_vdprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_vprintf.c (renamed from src/io/ft_vprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_vsnprintf.c (renamed from src/io/ft_vsnprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/ft_vsprintf.c (renamed from src/io/ft_vsprintf.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert.c (renamed from src/io/ft_printf/convert.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_char.c (renamed from src/io/ft_printf/convert_char.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_hex.c (renamed from src/io/ft_printf/convert_hex.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_int.c (renamed from src/io/ft_printf/convert_int.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_none.c (renamed from src/io/ft_printf/convert_none.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_percent.c (renamed from src/io/ft_printf/convert_percent.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_ptr.c (renamed from src/io/ft_printf/convert_ptr.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_str.c (renamed from src/io/ft_printf/convert_str.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_uint.c (renamed from src/io/ft_printf/convert_uint.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/convert_written.c (renamed from src/io/ft_printf/convert_written.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/extract.c (renamed from src/io/ft_printf/extract.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/length_modifier.c (renamed from src/io/ft_printf/length_modifier.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/list.c (renamed from src/io/ft_printf/list.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/parse.c (renamed from src/io/ft_printf/parse.c) | 0 | ||||
| -rw-r--r-- | src/io/ft_printf/internals/utils.c (renamed from src/io/ft_printf/utils.c) | 0 | ||||
| -rw-r--r-- | src/lst/ft_lstadd_back.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstadd_front.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstbsearch.c | 57 | ||||
| -rw-r--r-- | src/lst/ft_lstclear.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstdelone.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstiter.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstlast.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstmap.c | 9 | ||||
| -rw-r--r-- | src/lst/ft_lstnew.c | 7 | ||||
| -rw-r--r-- | src/lst/ft_lstpop_front.c | 6 | ||||
| -rw-r--r-- | src/lst/ft_lstremove_if.c | 33 | ||||
| -rw-r--r-- | src/lst/ft_lstreverse.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstreverse_ret.c | 7 | ||||
| -rw-r--r-- | src/lst/ft_lstsize.c | 3 | ||||
| -rw-r--r-- | src/lst/ft_lstsort.c | 40 | ||||
| -rw-r--r-- | src/lst/ft_lstsorted_merge.c | 36 | ||||
| -rw-r--r-- | src/mem/ft_memccpy.c | 12 | ||||
| -rw-r--r-- | src/mem/ft_memchr.c | 8 | ||||
| -rw-r--r-- | src/mem/ft_memcmp.c | 12 | ||||
| -rw-r--r-- | src/mem/ft_memcpy.c | 15 | ||||
| -rw-r--r-- | src/mem/ft_memmove.c | 34 | ||||
| -rw-r--r-- | src/mem/ft_memset.c | 18 | ||||
| -rw-r--r-- | src/str/ft_atoi_strict.c | 2 | ||||
| -rw-r--r-- | src/str/ft_strcpy.c | 2 | ||||
| -rw-r--r-- | src/str/ft_strlen.c | 2 | ||||
| -rw-r--r-- | src/str/ft_strncpy.c | 4 | ||||
| -rw-r--r-- | src/str/ft_strrchr.c | 2 | ||||
| -rw-r--r-- | src/str/ft_strtol.c | 12 |
68 files changed, 631 insertions, 199 deletions
diff --git a/src/bt/ft_btdestroy.c b/src/bt/ft_btdestroy.c new file mode 100644 index 0000000..c802db0 --- /dev/null +++ b/src/bt/ft_btdestroy.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btdestroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/07 21:30:53 by cacharle #+# #+# */ +/* Updated: 2020/02/07 21:35:19 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_bt.h" + +void ft_btdestroy(t_ftbtree *tree, void (*del)(void *data)) +{ + if (tree == NULL) + return ; + ft_btdestroy(tree->left, del); + ft_btdestroy(tree->right, del); + (*del)(tree->data); + free(tree); +} diff --git a/src/bt/ft_btnew.c b/src/bt/ft_btnew.c new file mode 100644 index 0000000..973e1a4 --- /dev/null +++ b/src/bt/ft_btnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/07 21:33:16 by cacharle #+# #+# */ +/* Updated: 2020/02/07 21:34:35 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_bt.h" + +t_ftbtree *ft_btnew(void *data) +{ + t_ftbtree *tree; + + if ((tree = (t_ftbtree*)malloc(sizeof(t_ftbtree))) == NULL) + return (NULL); + tree->data = data; + tree->left = NULL; + tree->right = NULL; + return (tree); +} 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_htcontent_new.c b/src/ht/ft_htcontent_new.c new file mode 100644 index 0000000..4ffa9bf --- /dev/null +++ b/src/ht/ft_htcontent_new.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htcontent_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:45:36 by cacharle #+# #+# */ +/* Updated: 2020/01/30 09:52:28 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +t_ftht_content *ft_htcontent_new(char *key, void *value) +{ + t_ftht_content *content; + + if (key == NULL) + return (NULL); + if ((content = (t_ftht_content*)malloc(sizeof(t_ftht_content))) == NULL) + return (NULL); + if ((content->key = ft_strdup(key)) == NULL) + { + free(content); + return (NULL); + } + content->value = value; + return (content); +} diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c new file mode 100644 index 0000000..d502bf2 --- /dev/null +++ b/src/ht/ft_htdelone.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 09:27:18 by cacharle #+# #+# */ +/* Updated: 2020/01/31 10:40:40 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_content*)) +{ + ft_lstremove_if(ht->entries + ft_hthash(ht, key), + (t_ftbool (*)(void*, void*))ft_inter_htkey_equal, key, + (void (*)(void*))del); +} diff --git a/src/io/ft_printf.c b/src/ht/ft_htdelone_key.c index 1b92bb2..96d55ec 100644 --- a/src/io/ft_printf.c +++ b/src/ht/ft_htdelone_key.c @@ -1,24 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_printf.c :+: :+: :+: */ +/* ft_htdelone_key.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/21 02:31:32 by cacharle #+# #+# */ -/* Updated: 2019/11/21 03:41:54 by cacharle ### ########.fr */ +/* Created: 2020/01/30 09:45:11 by cacharle #+# #+# */ +/* Updated: 2020/01/30 09:46:42 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" +#include "libft_ht.h" -int ft_printf(const char *format, ...) +void ft_htdelone_key(t_ftht *ht, char *key) { - int ret; - va_list ap; - - va_start(ap, format); - ret = ft_vprintf(format, ap); - va_end(ap); - return (ret); + ft_htdelone(ht, key, ft_inter_htdelcontent_key); } diff --git a/src/ht/ft_htdestroy.c b/src/ht/ft_htdestroy.c new file mode 100644 index 0000000..e0442c6 --- /dev/null +++ b/src/ht/ft_htdestroy.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htdestroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:19:06 by cacharle #+# #+# */ +/* Updated: 2020/01/30 08:33:09 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*)) +{ + if (ht == NULL) + return ; + while (ht->size-- > 0) + ft_lstclear(ht->entries + ht->size, (void (*)(void*))del); + free(ht->entries); + free(ht); +} diff --git a/src/ht/ft_htdestroy_all.c b/src/ht/ft_htdestroy_all.c new file mode 100644 index 0000000..6f98a43 --- /dev/null +++ b/src/ht/ft_htdestroy_all.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htdestroy_all.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:29:58 by cacharle #+# #+# */ +/* Updated: 2020/01/31 10:43:13 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_ht.h" + +static void st_htdelcontent_all(t_ftht_content *content) +{ + if (content == NULL) + return ; + free(content->key); + free(content->value); +} + +void ft_htdestroy_all(t_ftht *ht) +{ + ft_htdestroy(ht, *st_htdelcontent_all); +} diff --git a/src/ht/ft_htdestroy_key.c b/src/ht/ft_htdestroy_key.c new file mode 100644 index 0000000..a704314 --- /dev/null +++ b/src/ht/ft_htdestroy_key.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htdestroy_key.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:31:02 by cacharle #+# #+# */ +/* Updated: 2020/01/31 10:43:45 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +void ft_inter_htdelcontent_key(t_ftht_content *content) +{ + if (content == NULL) + return ; + free(content->key); +} + +void ft_htdestroy_key(t_ftht *ht) +{ + ft_htdestroy(ht, *ft_inter_htdelcontent_key); +} diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c new file mode 100644 index 0000000..0002249 --- /dev/null +++ b/src/ht/ft_htget.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htget.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:33:21 by cacharle #+# #+# */ +/* Updated: 2020/01/31 10:40:57 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +t_ftht_content *ft_htget(t_ftht *ht, char *key) +{ + + t_ftht_digest digest; + + return (NULL); // lstbsearch breaking + if (ht == NULL || key == NULL) + return (NULL); + digest = ft_hthash(ht, key); + return (ft_lstbsearch(ht->entries[digest], + (t_ftbool (*)(void*, void*))ft_inter_htkey_equal, + key)->content); +} diff --git a/src/ht/ft_hthash.c b/src/ht/ft_hthash.c new file mode 100644 index 0000000..e7e696c --- /dev/null +++ b/src/ht/ft_hthash.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_hthash.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 09:56:01 by cacharle #+# #+# */ +/* Updated: 2020/01/30 10:34:27 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_ht.h" + +t_ftht_digest ft_hthash(t_ftht *ht, char *key) +{ + t_ftht_digest digest; + + if (*key == '\0') + return (0); + digest = *key++ << 7; + while (*key != '\0') + { + digest = ((1000003 * digest) ^ *key) & (1 << 16); + key++; + } + return (digest % ht->size); +} diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c new file mode 100644 index 0000000..d98a724 --- /dev/null +++ b/src/ht/ft_htnew.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:19:16 by cacharle #+# #+# */ +/* Updated: 2020/02/10 02:16:20 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "libft_ht.h" + +t_ftht *ft_htnew(t_ftsize size) +{ + t_ftht *ht; + + if (size == 0) + return (NULL); + if ((ht = (t_ftht*)malloc(sizeof(t_ftht))) == NULL) + return (NULL); + ht->entries = (t_ftht_entry*)ft_calloc(size, sizeof(t_ftht_entry)); + if (ht->entries == NULL) + { + free(ht); + return (NULL); + } + ht->size = size; + return (ht); +} diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c new file mode 100644 index 0000000..5ace788 --- /dev/null +++ b/src/ht/ft_htset.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_htset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/30 08:41:52 by cacharle #+# #+# */ +/* Updated: 2020/01/31 10:33:39 by cacharle ### ########.fr */ +/* |
