chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / src / basic / hash-funcs.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5   Copyright 2010 Lennart Poettering
6   Copyright 2014 Michal Schmidt
7 ***/
8
9 #include "macro.h"
10 #include "siphash24.h"
11
12 typedef void (*hash_func_t)(const void *p, struct siphash *state);
13 typedef int (*compare_func_t)(const void *a, const void *b);
14
15 struct hash_ops {
16         hash_func_t hash;
17         compare_func_t compare;
18 };
19
20 void string_hash_func(const void *p, struct siphash *state);
21 int string_compare_func(const void *a, const void *b) _pure_;
22 extern const struct hash_ops string_hash_ops;
23
24 void path_hash_func(const void *p, struct siphash *state);
25 int path_compare_func(const void *a, const void *b) _pure_;
26 extern const struct hash_ops path_hash_ops;
27
28 /* This will compare the passed pointers directly, and will not dereference them. This is hence not useful for strings
29  * or suchlike. */
30 void trivial_hash_func(const void *p, struct siphash *state);
31 int trivial_compare_func(const void *a, const void *b) _const_;
32 extern const struct hash_ops trivial_hash_ops;
33
34 /* 32bit values we can always just embed in the pointer itself, but in order to support 32bit archs we need store 64bit
35  * values indirectly, since they don't fit in a pointer. */
36 void uint64_hash_func(const void *p, struct siphash *state);
37 int uint64_compare_func(const void *a, const void *b) _pure_;
38 extern const struct hash_ops uint64_hash_ops;
39
40 /* On some archs dev_t is 32bit, and on others 64bit. And sometimes it's 64bit on 32bit archs, and sometimes 32bit on
41  * 64bit archs. Yuck! */
42 #if SIZEOF_DEV_T != 8
43 void devt_hash_func(const void *p, struct siphash *state) _pure_;
44 int devt_compare_func(const void *a, const void *b) _pure_;
45 extern const struct hash_ops devt_hash_ops;
46 #else
47 #define devt_hash_func uint64_hash_func
48 #define devt_compare_func uint64_compare_func
49 #define devt_hash_ops uint64_hash_ops
50 #endif