1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of elogind.
6 Copyright 2010 Lennart Poettering
7 Copyright 2014 Michal Schmidt
9 elogind is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 elogind is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with elogind; If not, see <http://www.gnu.org/licenses/>.
23 #include "hash-funcs.h"
25 void string_hash_func(const void *p, struct siphash *state) {
26 siphash24_compress(p, strlen(p) + 1, state);
29 int string_compare_func(const void *a, const void *b) {
33 const struct hash_ops string_hash_ops = {
34 .hash = string_hash_func,
35 .compare = string_compare_func
38 void trivial_hash_func(const void *p, struct siphash *state) {
39 siphash24_compress(&p, sizeof(p), state);
42 int trivial_compare_func(const void *a, const void *b) {
43 return a < b ? -1 : (a > b ? 1 : 0);
46 const struct hash_ops trivial_hash_ops = {
47 .hash = trivial_hash_func,
48 .compare = trivial_compare_func
51 void uint64_hash_func(const void *p, struct siphash *state) {
52 siphash24_compress(p, sizeof(uint64_t), state);
55 int uint64_compare_func(const void *_a, const void *_b) {
57 a = *(const uint64_t*) _a;
58 b = *(const uint64_t*) _b;
59 return a < b ? -1 : (a > b ? 1 : 0);
62 const struct hash_ops uint64_hash_ops = {
63 .hash = uint64_hash_func,
64 .compare = uint64_compare_func
68 void devt_hash_func(const void *p, struct siphash *state) {
69 siphash24_compress(p, sizeof(dev_t), state);
72 int devt_compare_func(const void *_a, const void *_b) {
74 a = *(const dev_t*) _a;
75 b = *(const dev_t*) _b;
76 return a < b ? -1 : (a > b ? 1 : 0);
79 const struct hash_ops devt_hash_ops = {
80 .hash = devt_hash_func,
81 .compare = devt_compare_func