2 This file is part of elogind.
4 Copyright 2010 Lennart Poettering
5 Copyright 2014 Michal Schmidt
7 elogind 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.
12 elogind 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.
17 You should have received a copy of the GNU Lesser General Public License
18 along with elogind; If not, see <http://www.gnu.org/licenses/>.
21 #include "hash-funcs.h"
23 void string_hash_func(const void *p, struct siphash *state) {
24 siphash24_compress(p, strlen(p) + 1, state);
27 int string_compare_func(const void *a, const void *b) {
31 const struct hash_ops string_hash_ops = {
32 .hash = string_hash_func,
33 .compare = string_compare_func
36 void trivial_hash_func(const void *p, struct siphash *state) {
37 siphash24_compress(&p, sizeof(p), state);
40 int trivial_compare_func(const void *a, const void *b) {
41 return a < b ? -1 : (a > b ? 1 : 0);
44 const struct hash_ops trivial_hash_ops = {
45 .hash = trivial_hash_func,
46 .compare = trivial_compare_func
49 void uint64_hash_func(const void *p, struct siphash *state) {
50 siphash24_compress(p, sizeof(uint64_t), state);
53 int uint64_compare_func(const void *_a, const void *_b) {
55 a = *(const uint64_t*) _a;
56 b = *(const uint64_t*) _b;
57 return a < b ? -1 : (a > b ? 1 : 0);
60 const struct hash_ops uint64_hash_ops = {
61 .hash = uint64_hash_func,
62 .compare = uint64_compare_func
66 void devt_hash_func(const void *p, struct siphash *state) {
67 siphash24_compress(p, sizeof(dev_t), state);
70 int devt_compare_func(const void *_a, const void *_b) {
72 a = *(const dev_t*) _a;
73 b = *(const dev_t*) _b;
74 return a < b ? -1 : (a > b ? 1 : 0);
77 const struct hash_ops devt_hash_ops = {
78 .hash = devt_hash_func,
79 .compare = devt_compare_func