Add __hash__ to mgp.Vertex and mgp.Edge

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2725
This commit is contained in:
Ivan Paljak 2020-03-17 13:44:23 +01:00
parent 5632852890
commit 7b824ed622

View File

@ -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.'''