847ff039648514276e17cdbcccb36cd67e49a908
[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 /*
31  *      Fast hash, which isn't too bad.  Don't use for cryptography,
32  *      just for hashing internal data.
33  */
34 uint32_t fr_hash(const void *, size_t);
35 uint32_t fr_hash_update(const void *data, size_t size, uint32_t hash);
36 uint32_t fr_hash_string(const char *p);
37
38 /*
39  *      If you need fewer than 32-bits of hash, use this macro to get
40  *      the number of bits in the hash you need.  The upper bits of the
41  *      hash will be set to zero.
42  */
43 uint32_t fr_hash_fold(uint32_t hash, int bits);
44
45 typedef struct fr_hash_table_t fr_hash_table_t;
46 typedef void (*fr_hash_table_free_t)(void *);
47 typedef uint32_t (*fr_hash_table_hash_t)(const void *);
48 typedef int (*fr_hash_table_cmp_t)(const void *, const void *);
49 typedef int (*fr_hash_table_walk_t)(void * /* ctx */, void * /* data */);
50
51 fr_hash_table_t *fr_hash_table_create(fr_hash_table_hash_t hashNode,
52                                           fr_hash_table_cmp_t cmpNode,
53                                           fr_hash_table_free_t freeNode);
54 void            fr_hash_table_free(fr_hash_table_t *ht);
55 int             fr_hash_table_insert(fr_hash_table_t *ht, void *data);
56 int             fr_hash_table_delete(fr_hash_table_t *ht, const void *data);
57 void            *fr_hash_table_yank(fr_hash_table_t *ht, const void *data);
58 int             fr_hash_table_replace(fr_hash_table_t *ht, void *data);
59 void            *fr_hash_table_finddata(fr_hash_table_t *ht, const void *data);
60 int             fr_hash_table_num_elements(fr_hash_table_t *ht);
61 int             fr_hash_table_walk(fr_hash_table_t *ht,
62                                      fr_hash_table_walk_t callback,
63                                      void *ctx);
64 #endif /* FR_HASH_H */