]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/hash-funcs.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / hash-funcs.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
8 Copyright 2014 Michal Schmidt
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include "macro.h"
25 #include "siphash24.h"
26
27 typedef void (*hash_func_t)(const void *p, struct siphash *state);
28 typedef int (*compare_func_t)(const void *a, const void *b);
29
30 struct hash_ops {
31 hash_func_t hash;
32 compare_func_t compare;
33 };
34
35 void string_hash_func(const void *p, struct siphash *state);
36 int string_compare_func(const void *a, const void *b) _pure_;
37 extern const struct hash_ops string_hash_ops;
38
39 /* This will compare the passed pointers directly, and will not
40 * dereference them. This is hence not useful for strings or
41 * suchlike. */
42 void trivial_hash_func(const void *p, struct siphash *state);
43 int trivial_compare_func(const void *a, const void *b) _const_;
44 extern const struct hash_ops trivial_hash_ops;
45
46 /* 32bit values we can always just embed in the pointer itself, but
47 * in order to support 32bit archs we need store 64bit values
48 * indirectly, since they don't fit in a pointer. */
49 void uint64_hash_func(const void *p, struct siphash *state);
50 int uint64_compare_func(const void *a, const void *b) _pure_;
51 extern const struct hash_ops uint64_hash_ops;
52
53 /* On some archs dev_t is 32bit, and on others 64bit. And sometimes
54 * it's 64bit on 32bit archs, and sometimes 32bit on 64bit archs. Yuck! */
55 #if SIZEOF_DEV_T != 8
56 void devt_hash_func(const void *p, struct siphash *state) _pure_;
57 int devt_compare_func(const void *a, const void *b) _pure_;
58 extern const struct hash_ops devt_hash_ops = {
59 .hash = devt_hash_func,
60 .compare = devt_compare_func
61 };
62 #else
63 #define devt_hash_func uint64_hash_func
64 #define devt_compare_func uint64_compare_func
65 #define devt_hash_ops uint64_hash_ops
66 #endif