chiark / gitweb /
0c963af8ef8ad5e6a29b03fa8f74b3e0c61c706b
[elogind.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
11 #include "macro.h"
12 #include "siphash24.h"
13
14 typedef void (*hash_func_t)(const void *p, struct siphash *state);
15 typedef int (*compare_func_t)(const void *a, const void *b);
16
17 struct hash_ops {
18         hash_func_t hash;
19         compare_func_t compare;
20 };
21
22 void string_hash_func(const void *p, struct siphash *state);
23 int string_compare_func(const void *a, const void *b) _pure_;
24 extern const struct hash_ops string_hash_ops;
25
26 void path_hash_func(const void *p, struct siphash *state);
27 int path_compare_func(const void *a, const void *b) _pure_;
28 extern const struct hash_ops path_hash_ops;
29
30 /* This will compare the passed pointers directly, and will not dereference them. This is hence not useful for strings
31  * or suchlike. */
32 void trivial_hash_func(const void *p, struct siphash *state);
33 int trivial_compare_func(const void *a, const void *b) _const_;
34 extern const struct hash_ops trivial_hash_ops;
35
36 /* 32bit values we can always just embed in the pointer itself, but in order to support 32bit archs we need store 64bit
37  * values indirectly, since they don't fit in a pointer. */
38 void uint64_hash_func(const void *p, struct siphash *state);
39 int uint64_compare_func(const void *a, const void *b) _pure_;
40 extern const struct hash_ops uint64_hash_ops;
41
42 /* On some archs dev_t is 32bit, and on others 64bit. And sometimes it's 64bit on 32bit archs, and sometimes 32bit on
43  * 64bit archs. Yuck! */
44 #if SIZEOF_DEV_T != 8
45 void devt_hash_func(const void *p, struct siphash *state) _pure_;
46 int devt_compare_func(const void *a, const void *b) _pure_;
47 extern const struct hash_ops devt_hash_ops;
48 #else
49 #define devt_hash_func uint64_hash_func
50 #define devt_compare_func uint64_compare_func
51 #define devt_hash_ops uint64_hash_ops
52 #endif