758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering/***
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering This file is part of systemd.
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering Copyright 2010 Lennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering Copyright 2014 Michal Schmidt
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering systemd is free software; you can redistribute it and/or modify it
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering under the terms of the GNU Lesser General Public License as published by
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering (at your option) any later version.
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering systemd is distributed in the hope that it will be useful, but
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering Lesser General Public License for more details.
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering You should have received a copy of the GNU Lesser General Public License
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering***/
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering#include "hash-funcs.h"
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringvoid string_hash_func(const void *p, struct siphash *state) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering siphash24_compress(p, strlen(p) + 1, state);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringint string_compare_func(const void *a, const void *b) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering return strcmp(a, b);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringconst struct hash_ops string_hash_ops = {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .hash = string_hash_func,
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .compare = string_compare_func
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering};
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringvoid trivial_hash_func(const void *p, struct siphash *state) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering siphash24_compress(&p, sizeof(p), state);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringint trivial_compare_func(const void *a, const void *b) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering return a < b ? -1 : (a > b ? 1 : 0);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringconst struct hash_ops trivial_hash_ops = {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .hash = trivial_hash_func,
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .compare = trivial_compare_func
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering};
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringvoid uint64_hash_func(const void *p, struct siphash *state) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering siphash24_compress(p, sizeof(uint64_t), state);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringint uint64_compare_func(const void *_a, const void *_b) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering uint64_t a, b;
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering a = *(const uint64_t*) _a;
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering b = *(const uint64_t*) _b;
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering return a < b ? -1 : (a > b ? 1 : 0);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringconst struct hash_ops uint64_hash_ops = {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .hash = uint64_hash_func,
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .compare = uint64_compare_func
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering};
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering#if SIZEOF_DEV_T != 8
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringvoid devt_hash_func(const void *p, struct siphash *state) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering siphash24_compress(p, sizeof(dev_t), state);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringint devt_compare_func(const void *_a, const void *_b) {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering dev_t a, b;
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering a = *(const dev_t*) _a;
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering b = *(const dev_t*) _b;
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering return a < b ? -1 : (a > b ? 1 : 0);
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering}
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poetteringconst struct hash_ops devt_hash_ops = {
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .hash = devt_hash_func,
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering .compare = devt_compare_func
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering};
758dd67e8d40e65f695103bb03a77afaa087c5beLennart Poettering#endif