blob: cddb20796003581777cc9a283088cb6f7cf39f8c [file] [log] [blame]
willy tarreau12350152005-12-18 01:03:27 +01001/*
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 Tarreau2dd0d472006-06-29 17:53:05 +020018#ifndef _COMMON_CHTBL_H
19#define _COMMON_CHTBL_H
willy tarreau12350152005-12-18 01:03:27 +010020
21#include <stdlib.h>
22
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020023#include <common/config.h>
24#include <common/list.h>
willy tarreau12350152005-12-18 01:03:27 +010025
26/*****************************************************************************
27* *
28* Define a structure for chained hash tables. *
29* *
30*****************************************************************************/
31
32typedef 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
50int 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
53void chtbl_destroy(CHTbl *htbl);
54
55int chtbl_insert(CHTbl *htbl, const void *data);
56
57int chtbl_remove(CHTbl *htbl, void **data);
58
59int chtbl_lookup(const CHTbl *htbl, void **data);
60
61#define chtbl_size(htbl) ((htbl)->size)
62
Willy Tarreau2dd0d472006-06-29 17:53:05 +020063#endif /* _COMMON_CHTBL_H */
Willy Tarreaubaaee002006-06-26 02:48:02 +020064