]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |
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 | ||
22 | #include "hash-funcs.h" | |
23 | ||
24 | void string_hash_func(const void *p, struct siphash *state) { | |
25 | siphash24_compress(p, strlen(p) + 1, state); | |
26 | } | |
27 | ||
28 | int string_compare_func(const void *a, const void *b) { | |
29 | return strcmp(a, b); | |
30 | } | |
31 | ||
32 | const struct hash_ops string_hash_ops = { | |
33 | .hash = string_hash_func, | |
34 | .compare = string_compare_func | |
35 | }; | |
36 | ||
37 | void trivial_hash_func(const void *p, struct siphash *state) { | |
38 | siphash24_compress(&p, sizeof(p), state); | |
39 | } | |
40 | ||
41 | int trivial_compare_func(const void *a, const void *b) { | |
42 | return a < b ? -1 : (a > b ? 1 : 0); | |
43 | } | |
44 | ||
45 | const struct hash_ops trivial_hash_ops = { | |
46 | .hash = trivial_hash_func, | |
47 | .compare = trivial_compare_func | |
48 | }; | |
49 | ||
50 | void uint64_hash_func(const void *p, struct siphash *state) { | |
51 | siphash24_compress(p, sizeof(uint64_t), state); | |
52 | } | |
53 | ||
54 | int uint64_compare_func(const void *_a, const void *_b) { | |
55 | uint64_t a, b; | |
56 | a = *(const uint64_t*) _a; | |
57 | b = *(const uint64_t*) _b; | |
58 | return a < b ? -1 : (a > b ? 1 : 0); | |
59 | } | |
60 | ||
61 | const struct hash_ops uint64_hash_ops = { | |
62 | .hash = uint64_hash_func, | |
63 | .compare = uint64_compare_func | |
64 | }; | |
65 | ||
66 | #if SIZEOF_DEV_T != 8 | |
67 | void devt_hash_func(const void *p, struct siphash *state) { | |
68 | siphash24_compress(p, sizeof(dev_t), state); | |
69 | } | |
70 | ||
71 | int devt_compare_func(const void *_a, const void *_b) { | |
72 | dev_t a, b; | |
73 | a = *(const dev_t*) _a; | |
74 | b = *(const dev_t*) _b; | |
75 | return a < b ? -1 : (a > b ? 1 : 0); | |
76 | } | |
77 | ||
78 | const struct hash_ops devt_hash_ops = { | |
79 | .hash = devt_hash_func, | |
80 | .compare = devt_compare_func | |
81 | }; | |
82 | #endif |