summaryrefslogtreecommitdiff
path: root/hash.h
blob: 9cb346050144280b7ca22a0ec8c85020d8653074 (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
/*
 * addr_hash.h:
 *
 */

#ifndef __HASH_H_ /* include guard */
#define __HASH_H_

/* implementation independent declarations */
typedef enum {
    HASH_STATUS_OK,
    HASH_STATUS_MEM_EXHAUSTED,
    HASH_STATUS_KEY_NOT_FOUND
} hash_status_enum;

typedef struct node_tag {
    struct node_tag *next;       /* next node */
    void* key;                /* key */
    void* rec;                /* user data */
} hash_node_type;

typedef struct {
    int (*compare) (void*, void*);
    int (*hash) (void*);
    void* (*copy_key) (void*);
    void (*delete_key) (void*);
    hash_node_type** table;
    int size;
} hash_type;


hash_status_enum hash_initialise(hash_type*);
hash_status_enum hash_destroy(hash_type*);
hash_status_enum hash_insert(hash_type*, void* key, void *rec);
hash_status_enum hash_delete(hash_type* hash_table, void* key);
hash_status_enum hash_find(hash_type* hash_table, void* key, void** rec);
hash_status_enum hash_next_item(hash_type* hash_table, hash_node_type** ppnode);
void hash_delete_all(hash_type* hash_table);

#endif /* __HASH_H_ */