with generator on hashtab

This commit is contained in:
Antoine Riard 2017-06-21 19:55:15 +02:00
parent 11dd6dbd12
commit d3ab1f0071
3 changed files with 37 additions and 1 deletions

View file

@ -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))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_generator.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}