From 7b824ed622ef14ccbd81fffa55c7db001a7e769b Mon Sep 17 00:00:00 2001
From: Ivan Paljak <ivan.paljak@memgraph.io>
Date: Tue, 17 Mar 2020 13:44:23 +0100
Subject: [PATCH] Add __hash__ to mgp.Vertex and mgp.Edge

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2725
---
 include/mgp.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/mgp.py b/include/mgp.py
index 7a369686e..467164a3f 100644
--- a/include/mgp.py
+++ b/include/mgp.py
@@ -158,6 +158,16 @@ class EdgeType:
     def name(self) -> str:
         return self._name
 
+    def __eq__(self, other) -> bool:
+        if isinstance(other, EdgeType):
+            return self.name == other.name
+        if isinstance(other, str):
+            return self.name == other
+        return NotImplemented
+
+    def __hash__(self) -> int:
+        return hash(self.name)
+
 
 class Edge:
     '''Edge in the graph database.
@@ -218,6 +228,9 @@ class Edge:
             raise InvalidContextError()
         return self._edge == other._edge
 
+    def __hash__(self) -> int:
+        return hash((self.from_vertex, self.to_vertex, self.type))
+
 
 if sys.version_info >= (3, 5, 2):
     VertexId = typing.NewType('VertexId', int)
@@ -304,6 +317,9 @@ class Vertex:
             raise InvalidContextError()
         return self._vertex == other._vertex
 
+    def __hash__(self) -> int:
+        return hash(self.id)
+
 
 class Path:
     '''Path containing Vertex and Edge instances.'''