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 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 18 | #ifndef _COMMON_CHTBL_H |
| 19 | #define _COMMON_CHTBL_H |
willy tarreau | 1235015 | 2005-12-18 01:03:27 +0100 | [diff] [blame] | 20 | |
| 21 | #include <stdlib.h> |
| 22 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 23 | #include <common/config.h> |
| 24 | #include <common/list.h> |
willy tarreau | 1235015 | 2005-12-18 01:03:27 +0100 | [diff] [blame] | 25 | |
| 26 | /***************************************************************************** |
| 27 | * * |
| 28 | * Define a structure for chained hash tables. * |
| 29 | * * |
| 30 | *****************************************************************************/ |
| 31 | |
| 32 | typedef struct CHTbl_ { |
| 33 | |
| 34 | int buckets; |
| 35 | |
| 36 | int (*h)(const void *key); |
| 37 | int (*match)(const void *key1, const void *key2); |
| 38 | void (*destroy)(void *data); |
| 39 | |
| 40 | int size; |
| 41 | List *table; |
| 42 | } CHTbl; |
| 43 | |
| 44 | /***************************************************************************** |
| 45 | * * |
| 46 | * --------------------------- Public Interface --------------------------- * |
| 47 | * * |
| 48 | *****************************************************************************/ |
| 49 | |
| 50 | int chtbl_init(CHTbl *htbl, int buckets, int (*h)(const void *key), int |
| 51 | (*match)(const void *key1, const void *key2), void (*destroy)(void *data)); |
| 52 | |
| 53 | void chtbl_destroy(CHTbl *htbl); |
| 54 | |
| 55 | int chtbl_insert(CHTbl *htbl, const void *data); |
| 56 | |
| 57 | int chtbl_remove(CHTbl *htbl, void **data); |
| 58 | |
| 59 | int chtbl_lookup(const CHTbl *htbl, void **data); |
| 60 | |
| 61 | #define chtbl_size(htbl) ((htbl)->size) |
| 62 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 63 | #endif /* _COMMON_CHTBL_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 64 | |