-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashtable.h
74 lines (57 loc) · 1.62 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
74
#ifndef __HASHTABLE_H
#define __HASHTABLE_H
#include "linked_list.h"
typedef struct{
void *key;
void *value;
} info_t;
typedef struct hashtable_t hashtable_t;
struct hashtable_t {
linked_list_t **buckets; /* Array de liste simplu-inlantuite. */
/* Nr. total de noduri existente curent in toate bucket-urile. */
unsigned int size;
unsigned int hmax; /* Nr. de bucket-uri. */
/* (Pointer la) Functie pentru a calcula valoarea hash asociata cheilor. */
unsigned int (*hash_function)(void*);
/* (Pointer la) Functie pentru a compara doua chei. */
int (*compare_function)(void*, void*);
/* (Pointer la) Functie pentru a elibera memoria ocupata de cheie si valoare. */
void (*key_val_free_function)(void*);
};
hashtable_t *ht_create(unsigned int hmax, unsigned int (*hash_function)(void*),
int (*compare_function)(void*, void*),
void (*key_val_free_function)(void*));
void
ht_put(hashtable_t *ht, void *key, unsigned int key_size,
void *value, unsigned int value_size);
void
ht_put_modified(hashtable_t *ht, void *key, unsigned int key_size,
void *value, unsigned int value_size);
void *
ht_get(hashtable_t *ht, void *key);
int
ht_has_key(hashtable_t *ht, void *key);
void
ht_remove_entry(hashtable_t *ht, void *key);
unsigned int
ht_get_size(hashtable_t *ht);
unsigned int
ht_get_hmax(hashtable_t *ht);
void
ht_free(hashtable_t *ht);
void key_val_free_function(void *data);
/*
* Functii de comparare a cheilor:
*/
int
compare_function_ints(void *a, void *b);
int
compare_function_strings(void *a, void *b);
/*
* Functii de hashing:
*/
unsigned int
hash_function_int(void *a);
unsigned int
hash_function_string(void *a);
#endif