}
-#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
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