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