42-archive/libft/srcs/htb/hashtab_insert.c
Antoine Riard bdefb3c7a5 hashtab v0
2017-05-16 21:41:09 +02:00

26 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_insert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:30:39 by ariard #+# #+# */
/* Updated: 2017/05/16 21:05:19 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
int hashtab_insert(t_hashtab *htb, t_list *new, void *key,
int (*match)(const void *data_ref, const void *key))
{
int bucket;
if (hashtab_lookup(htb, key, match))
return (-1);
bucket = htb->hashfunc(key, htb->capacity);
ft_lsteadd(&htb->head[bucket], new);
htb->size++;
return (bucket);
}