commit ec8d06e: [Minor] Move common hashing utils to a separate util header

Vsevolod Stakhov vsevolod at rspamd.com
Sat May 14 12:49:05 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-05-14 12:29:48 +0100
URL: https://github.com/rspamd/rspamd/commit/ec8d06e7d0b961da5ae69841596e1a9873d2562d

[Minor] Move common hashing utils to a separate util header

---
 src/libutil/cxx/hash_util.hxx | 54 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

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 <string_view>
+#include <string>
+#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<std::string>()(a);
+	}
+	auto operator()(const std::string_view &a) const {
+		return robin_hood::hash<std::string_view>()(a);
+	}
+};
+
+}
+
+#endif //RSPAMD_HASH_UTIL_HXX


More information about the Commits mailing list