Return void, not int.
[oweals/opkg-lede.git] / libopkg / hash_table.h
1 /* hash.h - hash tables for opkg
2
3    Steven M. Ayer, Jamey Hicks
4    
5    Copyright (C) 2002 Compaq Computer Corporation
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 */
17
18 #ifndef _HASH_TABLE_H_
19 #define _HASH_TABLE_H_
20
21 typedef struct hash_entry hash_entry_t;
22 typedef struct hash_table hash_table_t;
23
24 struct hash_entry {
25   char * key;
26   void * data;
27   struct hash_entry * next;
28 };
29
30 struct hash_table {
31   const char *name; 
32   hash_entry_t * entries;  
33   unsigned int n_buckets;
34   unsigned int n_elements;
35
36   /* useful stats */
37   unsigned int n_used_buckets;
38   unsigned int n_collisions;
39   unsigned int max_bucket_len;
40   unsigned int n_hits, n_misses;
41 };
42
43 void hash_table_init(const char *name, hash_table_t *hash, int len);
44 void hash_table_deinit(hash_table_t *hash);
45 void hash_print_stats(hash_table_t *hash);
46 void *hash_table_get(hash_table_t *hash, const char *key);
47 int hash_table_insert(hash_table_t *hash, const char *key, void *value);
48 int hash_table_remove(hash_table_t *has, const char *key);
49 void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
50
51 #endif /* _HASH_TABLE_H_ */