]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/hash-funcs.c
log: minimize includes in log.h
[thirdparty/systemd.git] / src / basic / hash-funcs.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
758dd67e
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2010 Lennart Poettering
6 Copyright 2014 Michal Schmidt
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
dccca82b
LP
22#include <string.h>
23
758dd67e
LP
24#include "hash-funcs.h"
25
26void string_hash_func(const void *p, struct siphash *state) {
27 siphash24_compress(p, strlen(p) + 1, state);
28}
29
30int string_compare_func(const void *a, const void *b) {
31 return strcmp(a, b);
32}
33
34const struct hash_ops string_hash_ops = {
35 .hash = string_hash_func,
36 .compare = string_compare_func
37};
38
39void trivial_hash_func(const void *p, struct siphash *state) {
40 siphash24_compress(&p, sizeof(p), state);
41}
42
43int trivial_compare_func(const void *a, const void *b) {
44 return a < b ? -1 : (a > b ? 1 : 0);
45}
46
47const struct hash_ops trivial_hash_ops = {
48 .hash = trivial_hash_func,
49 .compare = trivial_compare_func
50};
51
52void uint64_hash_func(const void *p, struct siphash *state) {
53 siphash24_compress(p, sizeof(uint64_t), state);
54}
55
56int uint64_compare_func(const void *_a, const void *_b) {
57 uint64_t a, b;
58 a = *(const uint64_t*) _a;
59 b = *(const uint64_t*) _b;
60 return a < b ? -1 : (a > b ? 1 : 0);
61}
62
63const struct hash_ops uint64_hash_ops = {
64 .hash = uint64_hash_func,
65 .compare = uint64_compare_func
66};
67
68#if SIZEOF_DEV_T != 8
69void devt_hash_func(const void *p, struct siphash *state) {
70 siphash24_compress(p, sizeof(dev_t), state);
71}
72
73int devt_compare_func(const void *_a, const void *_b) {
74 dev_t a, b;
75 a = *(const dev_t*) _a;
76 b = *(const dev_t*) _b;
77 return a < b ? -1 : (a > b ? 1 : 0);
78}
79
80const struct hash_ops devt_hash_ops = {
81 .hash = devt_hash_func,
82 .compare = devt_compare_func
83};
84#endif