From deb4217161dbcce7e311a15663b6a46eef80b470 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Thu, 14 Aug 2025 14:34:53 +0200 Subject: [PATCH] Add dict traversal (without order choice) --- Makefile | 3 +-- ft_struct/ft_dict_traversal.c | 12 ++++++++++++ inc/ft_struct.h | 11 ++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 ft_struct/ft_dict_traversal.c diff --git a/Makefile b/Makefile index d54f3a2..d70aada 100644 --- a/Makefile +++ b/Makefile @@ -46,8 +46,7 @@ SRCstruct:= ft_stack_free.c \ ft_dict_free.c \ ft_dict_init.c \ ft_dict_insert.c \ - - + ft_dict_traversal.c \ SRCparse:= ft_parse.c \ ft_parsing_table_init.c \ diff --git a/ft_struct/ft_dict_traversal.c b/ft_struct/ft_dict_traversal.c new file mode 100644 index 0000000..20e2f98 --- /dev/null +++ b/ft_struct/ft_dict_traversal.c @@ -0,0 +1,12 @@ +#include "ft_struct.h" + +t_ft_stat ft_dict_traversal_init(t_dict_traversal *traversal, t_dict *dict) +{ + traversal->key_size = dict->key_size; + return (ft_rbtree_traversal_init(&traversal->traversal, &dict->tree, inorder)); +} + +void *ft_dict_traverse(t_dict_traversal *traversal) +{ + return ((char *)ft_rbtree_traverse(&traversal->traversal) + traversal->key_size); +} diff --git a/inc/ft_struct.h b/inc/ft_struct.h index 39305cb..27440dc 100644 --- a/inc/ft_struct.h +++ b/inc/ft_struct.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/20 16:59:43 by ljiriste #+# #+# */ -/* Updated: 2025/08/03 08:49:37 by ljiriste ### ########.fr */ +/* Updated: 2025/08/14 14:33:38 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -130,6 +130,15 @@ t_ft_stat ft_dict_insert(t_dict *dict, void *key, void *element); void *ft_dict_access(t_dict *dict, void *key); void ft_dict_delete(t_dict *dict, void *key, t_free_fun free_key, t_free_fun free_el); +typedef struct s_dict_traversal +{ + size_t key_size; + t_rbtree_traversal traversal; +} t_dict_traversal; + +t_ft_stat ft_dict_traversal_init(t_dict_traversal *traversal, t_dict *dict); +void *ft_dict_traverse(t_dict_traversal *traversal); + # ifdef __cplusplus } # endif // __cplusplus -- 2.30.2