willy tarreau | 1235015 | 2005-12-18 01:03:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | This File is copied from |
| 3 | |
| 4 | http://www.oreilly.com/catalog/masteralgoc/index.html |
| 5 | Mastering Algorithms with C |
| 6 | By Kyle Loudon |
| 7 | ISBN: 1-56592-453-3 |
| 8 | Publishd by O'Reilly |
| 9 | |
| 10 | */ |
| 11 | |
| 12 | /***************************************************************************** |
| 13 | * * |
| 14 | * ------------------------------- chtbl.h -------------------------------- * |
| 15 | * * |
| 16 | *****************************************************************************/ |
| 17 | |
| 18 | #ifndef CHTBL_H |
| 19 | #define CHTBL_H |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | |
| 23 | #include "list.h" |
| 24 | |
| 25 | /***************************************************************************** |
| 26 | * * |
| 27 | * Define a structure for chained hash tables. * |
| 28 | * * |
| 29 | *****************************************************************************/ |
| 30 | |
| 31 | typedef struct CHTbl_ { |
| 32 | |
| 33 | int buckets; |
| 34 | |
| 35 | int (*h)(const void *key); |
| 36 | int (*match)(const void *key1, const void *key2); |
| 37 | void (*destroy)(void *data); |
| 38 | |
| 39 | int size; |
| 40 | List *table; |
| 41 | } CHTbl; |
| 42 | |
| 43 | /***************************************************************************** |
| 44 | * * |
| 45 | * --------------------------- Public Interface --------------------------- * |
| 46 | * * |
| 47 | *****************************************************************************/ |
| 48 | |
| 49 | int chtbl_init(CHTbl *htbl, int buckets, int (*h)(const void *key), int |
| 50 | (*match)(const void *key1, const void *key2), void (*destroy)(void *data)); |
| 51 | |
| 52 | void chtbl_destroy(CHTbl *htbl); |
| 53 | |
| 54 | int chtbl_insert(CHTbl *htbl, const void *data); |
| 55 | |
| 56 | int chtbl_remove(CHTbl *htbl, void **data); |
| 57 | |
| 58 | int chtbl_lookup(const CHTbl *htbl, void **data); |
| 59 | |
| 60 | #define chtbl_size(htbl) ((htbl)->size) |
| 61 | |
| 62 | #endif |