Quellcode durchsuchen

LibManual: Compare nodes by path

This makes them suited for hash map usage.
kleines Filmröllchen vor 2 Jahren
Ursprung
Commit
f53aa959df
1 geänderte Dateien mit 18 neuen und 0 gelöschten Zeilen
  1. 18 0
      Userland/Libraries/LibManual/Node.h

+ 18 - 0
Userland/Libraries/LibManual/Node.h

@@ -38,6 +38,24 @@ public:
     // Finds a page via the help://man/<number>/<subsections...>/page URLs.
     // This will automatically start discovering pages by inspecting the filesystem.
     static ErrorOr<NonnullRefPtr<Node const>> try_find_from_help_url(URL const&);
+
+    bool operator==(Node const& other) const
+    {
+        if (auto this_path = this->path(), other_path = other.path();
+            !this_path.is_error() && !other_path.is_error()) {
+            return this_path.release_value() == other_path.release_value();
+        }
+        return false;
+    }
+};
+
+}
+
+namespace AK {
+
+template<typename T>
+requires(IsBaseOf<Manual::Node, T>) struct Traits<T> : public GenericTraits<T> {
+    static unsigned hash(T p) { return Traits::hash(p.path()); }
 };
 
 }