aboutsummaryrefslogtreecommitdiff
path: root/include/libft_ht.h
blob: 24abf95b4c9fe0a771634075f666ed0b6384628f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   libft_ht.h                                         :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/01/31 10:36:09 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/28 12:18:19 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef LIBFT_HT_H
# define LIBFT_HT_H

/**
** \file   libft_ht.h
** \brief  Hash table manipulation
*/

# include "libft.h"
# include "libft_lst.h"

/**
** \brief        Hash table entry, key/value pair
** \param key    String key
** \param value  Pointer to data
*/

typedef struct		s_ftht_entry
{
	char			*key;
	void			*value;
}					t_ftht_entry;

typedef t_ftlst*	t_ftht_bucket;

/**
** \brief          Hash table struct
** \param size     Number of buckets
** \param buckets  Bucket array
*/

typedef struct		s_ftht
{
	t_ftsize		size;
	t_ftht_bucket	*buckets;
}					t_ftht;

typedef t_ftuint	t_ftht_digest;

t_ftht_digest		ft_hthash(t_ftht *ht, char *key);

t_ftht				*ft_htnew(t_ftsize size);
void				ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_entry*));
void				*ft_htget(t_ftht *ht, char *key);
t_ftht_entry		*ft_htset(t_ftht *ht, char *key, void *value,
								void (*del)(t_ftht_entry*));
void				ft_htdelone(t_ftht *ht, char *key,
								void (*del)(t_ftht_entry*));
t_ftht_entry		*ft_htentry_new(char *key, void *value);
void                ft_htiter(t_ftht *ht, void (*f)(t_ftht_entry*));

/*
** internals
*/

int					ft_inter_htkey_cmp(const void *ref_key,
											const void *content);

#endif