The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
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 */
24RCSIDH(hash_h, "$Id: e2eedc00e0c744f014b3d80565c3a731ea694064 $")
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <freeradius-devel/util/misc.h>
31
32#include <stddef.h>
33#include <stdint.h>
34
36typedef uint32_t (*fr_hash_t)(void const *);
37
38/** Stores the state of the current iteration operation
39 *
40 */
45
46/*
47 * Fast hash, which isn't too bad. Don't use for cryptography,
48 * just for hashing internal data.
49 */
50uint32_t fr_hash(void const *, size_t);
51uint32_t fr_hash_update(void const *data, size_t size, uint32_t hash);
52uint32_t fr_hash_string(char const *p);
53uint32_t fr_hash_case_string(char const *p);
54
56typedef 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
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
70void *fr_hash_table_find(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
71
72void *fr_hash_table_find_by_key(fr_hash_table_t *ht, uint32_t key, void const *data) CC_HINT(nonnull);
73
74bool fr_hash_table_insert(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
75
76int fr_hash_table_replace(void **old, fr_hash_table_t *ht, void const *data) CC_HINT(nonnull(2,3));
77
78void *fr_hash_table_remove(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
79
80bool fr_hash_table_delete(fr_hash_table_t *ht, void const *data) CC_HINT(nonnull);
81
83
85
87
88int fr_hash_table_flatten(TALLOC_CTX *ctx, void **out[], fr_hash_table_t *ht) CC_HINT(nonnull(2,3));
89
91
93
94#ifdef __cplusplus
95}
96#endif
#define RCSIDH(h, id)
Definition build.h:484
Definition hash.c:43
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:626
void * fr_hash_table_find(fr_hash_table_t *ht, void const *data)
Find data in a hash table.
Definition hash.c:429
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:528
void * fr_hash_table_iter_init(fr_hash_table_t *ht, fr_hash_iter_t *iter)
Initialise an iterator.
Definition hash.c:678
uint32_t fr_hash_case_string(char const *p)
Hash a C string, converting all chars to lowercase.
Definition hash.c:881
uint32_t fr_hash_update(void const *data, size_t size, uint32_t hash)
Definition hash.c:846
bool fr_hash_table_insert(fr_hash_table_t *ht, void const *data)
Insert data into a hash table.
Definition hash.c:468
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:448
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:559
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_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:865
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:594
void fr_hash_table_verify(fr_hash_table_t *ht)
Check hash table is sane.
Definition hash.c:897
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:719
uint32_t fr_hash(void const *, size_t)
Definition hash.c:812
uint32_t fr_hash_table_num_elements(fr_hash_table_t *ht)
Definition hash.c:610
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:695
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
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:1265
int nonnull(2, 5))
static size_t char ** out
Definition value.h:997