The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
hash.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /** Structures and prototypes for resizable hash tables
19  *
20  * @file src/lib/util/hash.h
21  *
22  * @copyright 2005,2006 The FreeRADIUS server project
23  */
24 RCSIDH(hash_h, "$Id: e2eedc00e0c744f014b3d80565c3a731ea694064 $")
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <freeradius-devel/util/misc.h>
31 
32 #include <stddef.h>
33 #include <stdint.h>
34 
35 typedef struct fr_hash_entry_s fr_hash_entry_t;
36 typedef uint32_t (*fr_hash_t)(void const *);
37 
38 /** Stores the state of the current iteration operation
39  *
40  */
41 typedef struct fr_hash_iter_s {
45 
46 /*
47  * Fast hash, which isn't too bad. Don't use for cryptography,
48  * just for hashing internal data.
49  */
50 uint32_t fr_hash(void const *, size_t);
51 uint32_t fr_hash_update(void const *data, size_t size, uint32_t hash);
52 uint32_t fr_hash_string(char const *p);
54 
55 typedef struct fr_hash_table_s fr_hash_table_t;
56 typedef int (*fr_hash_table_walk_t)(void *data, void *uctx);
57 
58 #define fr_hash_table_alloc(_ctx, _hash_node, _cmp_node, _free_node) \
59  _fr_hash_table_alloc(_ctx, NULL, _hash_node, _cmp_node, _free_node)
60 
61 #define fr_hash_table_talloc_alloc(_ctx, _type, _hash_node, _cmp_node, _free_node) \
62  _fr_hash_table_alloc(_ctx, #_type, _hash_node, _cmp_node, _free_node)
63 
64 fr_hash_table_t *_fr_hash_table_alloc(TALLOC_CTX *ctx,
65  char const *type,
66  fr_hash_t hash_node,
67  fr_cmp_t cmp_node,
68  fr_free_t free_node) CC_HINT(nonnull(3,4));
69 
70 void *fr_hash_table_find(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
71 
72 void *fr_hash_table_find_by_key(fr_hash_table_t *ht, uint32_t key, void const *data) CC_HINT(nonnull);
73 
74 bool fr_hash_table_insert(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
75 
76 int fr_hash_table_replace(void **old, fr_hash_table_t *ht, void const *data) CC_HINT(nonnull(2,3));
77 
78 void *fr_hash_table_remove(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
79 
80 bool fr_hash_table_delete(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
81 
83 
85 
87 
88 int fr_hash_table_flatten(TALLOC_CTX *ctx, void **out[], fr_hash_table_t *ht) CC_HINT(nonnull(2,3));
89 
90 void fr_hash_table_fill(fr_hash_table_t *ht) CC_HINT(nonnull);
91 
93 
94 #ifdef __cplusplus
95 }
96 #endif
#define RCSIDH(h, id)
Definition: build.h:445
Definition: hash.c:43
void * fr_hash_table_iter_init(fr_hash_table_t *ht, fr_hash_iter_t *iter)
Initialise an iterator.
Definition: hash.c:672
int fr_hash_table_replace(void **old, fr_hash_table_t *ht, void const *data))
Replace old data with new data, OR insert if there is no old.
Definition: hash.c:525
void * fr_hash_table_iter_next(fr_hash_table_t *ht, fr_hash_iter_t *iter)
Iterate over entries in a hash table.
Definition: hash.c:620
void * fr_hash_table_remove(fr_hash_table_t *ht, void const *data)
Remove an entry from the hash table, without freeing the data.
Definition: hash.c:555
void * fr_hash_table_find(fr_hash_table_t *ht, void const *data)
Find data in a hash table.
Definition: hash.c:428
uint32_t fr_hash_case_string(char const *p)
Hash a C string, converting all chars to lowercase.
Definition: hash.c:874
uint32_t fr_hash_update(void const *data, size_t size, uint32_t hash)
Definition: hash.c:840
bool fr_hash_table_insert(fr_hash_table_t *ht, void const *data)
Insert data into a hash table.
Definition: hash.c:466
uint32_t(* fr_hash_t)(void const *)
Definition: hash.h:36
struct fr_hash_iter_s fr_hash_iter_t
Stores the state of the current iteration operation.
fr_hash_entry_t * node
Definition: hash.h:43
uint32_t fr_hash_string(char const *p)
Definition: hash.c:859
bool fr_hash_table_delete(fr_hash_table_t *ht, void const *data)
Remove and free data (if a free function was specified)
Definition: hash.c:589
void fr_hash_table_verify(fr_hash_table_t *ht)
Check hash table is sane.
Definition: hash.c:889
uint32_t bucket
Definition: hash.h:42
void fr_hash_table_fill(fr_hash_table_t *ht)
Ensure all buckets are filled.
Definition: hash.c:713
fr_hash_table_t * _fr_hash_table_alloc(TALLOC_CTX *ctx, char const *type, fr_hash_t hash_node, fr_cmp_t cmp_node, fr_free_t free_node))
Definition: hash.c:280
uint32_t fr_hash(void const *, size_t)
Definition: hash.c:806
void * fr_hash_table_find_by_key(fr_hash_table_t *ht, uint32_t key, void const *data)
Hash table lookup with pre-computed key.
Definition: hash.c:447
uint32_t fr_hash_table_num_elements(fr_hash_table_t *ht)
Definition: hash.c:604
int fr_hash_table_flatten(TALLOC_CTX *ctx, void **out[], fr_hash_table_t *ht))
Copy all entries out of a hash table into an array.
Definition: hash.c:689
int(* fr_hash_table_walk_t)(void *data, void *uctx)
Definition: hash.h:56
Stores the state of the current iteration operation.
Definition: hash.h:41
unsigned int uint32_t
Definition: merged_model.c:33
int8_t(* fr_cmp_t)(void const *a, void const *b)
Definition: misc.h:38
void(* fr_free_t)(void *)
Definition: misc.h:39
static unsigned int hash(char const *username, unsigned int tablesize)
Definition: rlm_passwd.c:132
fr_aka_sim_id_type_t type
static fr_slen_t data
Definition: value.h:1259
int nonnull(2, 5))
static size_t char ** out
Definition: value.h:984