Repository navigation
Expand file tree
/
Copy pathhashtable.h
More file actions
50 lines (41 loc) · 1.6 KB
/
Copy pathhashtable.h
File metadata and controls
50 lines (41 loc) · 1.6 KB
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
#ifndef HASH_H_
#define HASH_H_
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hashtable.h"
#include "set.h"
typedef struct hashtable_t{
int count;
set_t **ptr;
}hashtable_t;#endif
/* Create a new (empty) hashtable; return NULL if error. */
hashtable_t *hashtable_new(const int num_slots);
/* Insert item, identified by key (string), into the given hashtable.
* The key string is copied for use by the hashtable.
* Return false if key exists in ht, any parameter is NULL, or error;
* return true if new item was inserted.
*/
bool hashtable_insert(hashtable_t *ht, const char *key, void *item);
/* Return the item associated with the given key;
* return NULL if hashtable is NULL, key is NULL, key is not found.
*/
void *hashtable_find(hashtable_t *ht, const char *key);
/* Print the whole table; provide the output file and func to print each item.
* Ignore if NULL fp. Print (null) if NULL ht.
* Print a table with no items if NULL itemprint.
*/
void hashtable_print(hashtable_t *ht, FILE *fp,
void (*itemprint)(FILE *fp, const char *key, void *item));
/* Iterate over all items in the table; in undefined order.
* Call the given function on each item, with (arg, key, item).
* If ht==NULL or itemfunc==NULL, do nothing.
*/
void hashtable_iterate(hashtable_t *ht, void *arg,
void (*itemfunc)(void *arg, const char *key, void *item) );
/* Delete the whole hashtable; ignore NULL ht.
* Provide a function that will delete each item (may be NULL).
*/
void hashtable_delete(hashtable_t *ht, void (*itemdelete)(void *item) );
#endif //HASH_H_