Pulled from branch_1_1. Untested!
[freeradius.git] / src / include / hash.h
1 #ifndef LRAD_HASH_H
2 #define LRAD_HASH_H
3
4 /*
5  * hasht.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 /*
28  *      Fast hash, which isn't too bad.  Don't use for cryptography,
29  *      just for hashing internal data.
30  */
31 uint32_t lrad_hash(const void *, size_t);
32 uint32_t lrad_hash_update(const void *data, size_t size, uint32_t hash);
33 uint32_t lrad_hash_string(const char *p);
34
35 /*
36  *      If you need fewer than 32-bits of hash, use this macro to get
37  *      the number of bits in the hash you need.  The upper bits of the
38  *      hash will be set to zero.
39  */
40 uint32_t lrad_hash_fold(uint32_t hash, int bits);
41
42 typedef struct lrad_hash_table_t lrad_hash_table_t;
43 typedef void (*lrad_hash_table_free_t)(void *);
44 typedef uint32_t (*lrad_hash_table_hash_t)(const void *);
45 typedef int (*lrad_hash_table_cmp_t)(const void *, const void *);
46 typedef int (*lrad_hash_table_walk_t)(void * /* ctx */, void * /* data */);
47
48 lrad_hash_table_t *lrad_hash_table_create(lrad_hash_table_hash_t hashNode,
49                                           lrad_hash_table_cmp_t cmpNode,
50                                           lrad_hash_table_free_t freeNode);
51 void            lrad_hash_table_free(lrad_hash_table_t *ht);
52 int             lrad_hash_table_insert(lrad_hash_table_t *ht, void *data);
53 int             lrad_hash_table_delete(lrad_hash_table_t *ht, const void *data);
54 void            *lrad_hash_table_yank(lrad_hash_table_t *ht, const void *data);
55 int             lrad_hash_table_replace(lrad_hash_table_t *ht, void *data);
56 void            *lrad_hash_table_finddata(lrad_hash_table_t *ht, const void *data);
57 int             lrad_hash_table_num_elements(lrad_hash_table_t *ht);
58 int             lrad_hash_table_walk(lrad_hash_table_t *ht,
59                                      lrad_hash_table_walk_t callback,
60                                      void *ctx);
61 #endif /* LRAD_HASH_H */