-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashtable.h
executable file
·73 lines (56 loc) · 2.27 KB
/
hashtable.h
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
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtable.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/04 08:16:53 by akharrou #+# #+# */
/* Updated: 2019/05/24 18:21:27 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HASHTABLE_H
# define HASHTABLE_H
/*
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
*/
# define HASHCODE(key, buckets) (ft_hash(key) % buckets)
# define INIT_HASHTABLE_SIZE 256
# define MIN_LOAD_FACTOR 0.0
# define MAX_LOAD_FACTOR 0.7
# define HTAB_MULTIPLIER 2
# define HTAB_DIVISER 2
/*
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
*/
typedef struct s_entry
{
char *key;
void *item;
struct s_entry *next;
} t_entry;
typedef struct s_hashtable
{
unsigned int entries;
unsigned int num_buckets;
t_entry **buckets;
} t_hashtable;
/*
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
*/
t_hashtable *hashtab_init(void);
t_hashtable *hashtab_new(unsigned int num_entries);
int hashtab_insert(t_hashtable **table, char *key, void *item);
t_entry *hashtab_getentry(t_hashtable *table, char *key);
void *hashtab_getitem(t_hashtable *table, char *key);
void *hashtab_popitem(t_hashtable **table, char *key);
int hashtab_remove(t_hashtable **table, char *key);
int hashtab_clear(t_hashtable **table);
int hashtab_destroy(t_hashtable **table);
int hashtab_grow(t_hashtable **table);
int hashtab_shrink(t_hashtable **table);
int hashtab_count(t_hashtable *table);
/*
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
*/
#endif