diff --git a/libftasm/Makefile b/libftasm/Makefile index ab735ac7..63095c87 100644 --- a/libftasm/Makefile +++ b/libftasm/Makefile @@ -206,6 +206,7 @@ htb/hashtab_lookup.c\ htb/hashtab_remove.c\ htb/hashtab_destroy.c\ htb/hashtab_print.c\ +htb/hashtab_generator.c\ SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) diff --git a/libftasm/includes/hashtab.h b/libftasm/includes/hashtab.h index 0e84bf70..7d64f21a 100644 --- a/libftasm/includes/hashtab.h +++ b/libftasm/includes/hashtab.h @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/05/15 19:16:49 by ariard #+# #+# */ -/* Updated: 2017/05/16 21:03:50 by ariard ### ########.fr */ +/* Updated: 2017/06/21 18:39:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,4 +43,6 @@ void hashtab_print(t_hashtab *htb, int (*printer)()); int ft_hash_string(const void *key, int size); +struct s_list *hashtab_generator(t_hashtab *htb, char init); + #endif diff --git a/libftasm/srcs/htb/hashtab_generator.c b/libftasm/srcs/htb/hashtab_generator.c new file mode 100644 index 00000000..6fe7b055 --- /dev/null +++ b/libftasm/srcs/htb/hashtab_generator.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hashtab_generator.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/06/21 18:21:30 by ariard #+# #+# */ +/* Updated: 2017/06/21 19:54:30 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "hashtab.h" + +struct s_list *hashtab_generator(t_hashtab *htb, char init) +{ + static int bucket; + static t_list *tmp; + static t_list *prev; + + if (init) + { + bucket = 0; + tmp = htb->head[bucket]; + return (NULL); + } + while (!tmp && ++bucket < htb->capacity) + tmp = htb->head[bucket]; + prev = tmp; + if (tmp) + tmp = tmp->next; + return (prev); +}