42-archive/libft/srcs/htb/hashtab_insert.c
2017-06-24 01:30:37 +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/06/22 22:42:56 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);
}