From: Vsevolod Stakhov Date: Sat, 14 May 2022 11:29:48 +0000 (+0100) Subject: [Minor] Move common hashing utils to a separate util header X-Git-Tag: 3.3~252 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ec8d06e7d0b961da5ae69841596e1a9873d2562d;p=rspamd.git [Minor] Move common hashing utils to a separate util header --- diff --git a/src/libutil/cxx/hash_util.hxx b/src/libutil/cxx/hash_util.hxx new file mode 100644 index 000000000..6d20ddb93 --- /dev/null +++ b/src/libutil/cxx/hash_util.hxx @@ -0,0 +1,54 @@ +/*- + * Copyright 2021 Vsevolod Stakhov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef RSPAMD_HASH_UTIL_HXX +#define RSPAMD_HASH_UTIL_HXX + +#pragma once + +#include +#include +#include "contrib/robin-hood/robin_hood.h" + + +namespace rspamd { + +/* Enable lookup by string view */ +struct smart_str_equal { + using is_transparent = void; + auto operator()(const std::string &a, const std::string &b) const { + return a == b; + } + auto operator()(const std::string_view &a, const std::string &b) const { + return a == b; + } + auto operator()(const std::string &a, const std::string_view &b) const { + return a == b; + } +}; + +struct smart_str_hash { + using is_transparent = void; + auto operator()(const std::string &a) const { + return robin_hood::hash()(a); + } + auto operator()(const std::string_view &a) const { + return robin_hood::hash()(a); + } +}; + +} + +#endif //RSPAMD_HASH_UTIL_HXX