Add "extern C {...} to header files for C++ builds.
[freeradius.git] / src / include / hash.h
1 #ifndef FR_HASH_H
2 #define FR_HASH_H
3
4 /*
5  * hash.h       Structures and prototypes
6  *              for fast hashing.
7  *
8  * Version:     $Id$
9  *
10  *   This program is free software; you can redistribute it and/or modify
11  *   it under the terms of the GNU General Public License as published by
12  *   the Free Software Foundation; either version 2 of the License, or
13  *   (at your option) any later version.
14  *
15  *   This program is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with this program; if not, write to the Free Software
22  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23  *
24  * Copyright 2005,2006  The FreeRADIUS server project
25  */
26
27 #include <freeradius-devel/ident.h>
28 RCSIDH(hash_h, "$Id$")
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /*
35  *      Fast hash, which isn't too bad.  Don't use for cryptography,
36  *      just for hashing internal data.
37  */
38 uint32_t fr_hash(const void *, size_t);
39 uint32_t fr_hash_update(const void *data, size_t size, uint32_t hash);
40 uint32_t fr_hash_string(const char *p);
41
42 /*
43  *      If you need fewer than 32-bits of hash, use this macro to get
44  *      the number of bits in the hash you need.  The upper bits of the
45  *      hash will be set to zero.
46  */
47 uint32_t fr_hash_fold(uint32_t hash, int bits);
48
49 typedef struct fr_hash_table_t fr_hash_table_t;
50 typedef void (*fr_hash_table_free_t)(void *);
51 typedef uint32_t (*fr_hash_table_hash_t)(const void *);
52 typedef int (*fr_hash_table_cmp_t)(const void *, const void *);
53 typedef int (*fr_hash_table_walk_t)(void * /* ctx */, void * /* data */);
54
55 fr_hash_table_t *fr_hash_table_create(fr_hash_table_hash_t hashNode,
56                                           fr_hash_table_cmp_t cmpNode,
57                                           fr_hash_table_free_t freeNode);
58 void            fr_hash_table_free(fr_hash_table_t *ht);
59 int             fr_hash_table_insert(fr_hash_table_t *ht, void *data);
60 int             fr_hash_table_delete(fr_hash_table_t *ht, const void *data);
61 void            *fr_hash_table_yank(fr_hash_table_t *ht, const void *data);
62 int             fr_hash_table_replace(fr_hash_table_t *ht, void *data);
63 void            *fr_hash_table_finddata(fr_hash_table_t *ht, const void *data);
64 int             fr_hash_table_num_elements(fr_hash_table_t *ht);
65 int             fr_hash_table_walk(fr_hash_table_t *ht,
66                                      fr_hash_table_walk_t callback,
67                                      void *ctx);
68
69 #ifdef __cplusplus
70 }
71 #endif
72
73 #endif /* FR_HASH_H */