summaryrefslogtreecommitdiffstats
path: root/src/libserver/css
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-18 20:19:40 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-01-22 15:58:05 +0000
commitc4911f4546ab834a6fd696b434d58cf86e7891d5 (patch)
treeb70d42fbdf0600af8180281f310d787a631fc2c8 /src/libserver/css
parenta90d8ba8022dad062548e97947be938ff5ebc60b (diff)
downloadrspamd-c4911f4546ab834a6fd696b434d58cf86e7891d5.tar.gz
rspamd-c4911f4546ab834a6fd696b434d58cf86e7891d5.zip
[Project] Add hashing method
Diffstat (limited to 'src/libserver/css')
-rw-r--r--src/libserver/css/css_property.hxx22
-rw-r--r--src/libserver/css/css_rule.hxx17
2 files changed, 35 insertions, 4 deletions
diff --git a/src/libserver/css/css_property.hxx b/src/libserver/css/css_property.hxx
index b3f7262a2..788f4554b 100644
--- a/src/libserver/css/css_property.hxx
+++ b/src/libserver/css/css_property.hxx
@@ -46,4 +46,24 @@ struct css_property {
}
-#endif //RSPAMD_CSS_PROPERTY_HXX
+/* Make properties hashable */
+namespace std {
+template<>
+class hash<rspamd::css::css_property> {
+public:
+ /* Mix bits to provide slightly better distribution but being constexpr */
+ constexpr size_t operator() (const rspamd::css::css_property &prop) const {
+ std::size_t key = 0xdeadbeef ^static_cast<std::size_t>(prop.type);
+ key = (~key) + (key << 21);
+ key = key ^ (key >> 24);
+ key = (key + (key << 3)) + (key << 8);
+ key = key ^ (key >> 14);
+ key = (key + (key << 2)) + (key << 4);
+ key = key ^ (key >> 28);
+ key = key + (key << 31);
+ return key;
+ }
+};
+}
+
+#endif //RSPAMD_CSS_PROPERTY_HXX \ No newline at end of file
diff --git a/src/libserver/css/css_rule.hxx b/src/libserver/css/css_rule.hxx
index bcd542b0c..596e246b3 100644
--- a/src/libserver/css/css_rule.hxx
+++ b/src/libserver/css/css_rule.hxx
@@ -44,10 +44,21 @@ public:
void add_value(const css_value &value) {
values.emplace_back(std::make_unique<css_value>(css_value{value}));
}
- const css_values_vec& get_values(void) { return values; }
- const css_property& get_prop(void) { return prop; }
+ constexpr const css_values_vec& get_values(void) const { return values; }
+ constexpr const css_property& get_prop(void) const { return prop; }
};
}
-#endif //RSPAMD_CSS_RULE_HXX
+/* Make rules hashable by property */
+namespace std {
+template<>
+class hash<rspamd::css::css_rule> {
+public:
+ constexpr size_t operator() (const rspamd::css::css_rule &rule) const {
+ return hash<rspamd::css::css_property>()(rule.get_prop());
+ }
+};
+}
+
+#endif //RSPAMD_CSS_RULE_HXX \ No newline at end of file