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:
parent
5632852890
commit
7b824ed622
@ -158,6 +158,16 @@ class EdgeType:
|
|||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
return self._name
|
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:
|
class Edge:
|
||||||
'''Edge in the graph database.
|
'''Edge in the graph database.
|
||||||
@ -218,6 +228,9 @@ class Edge:
|
|||||||
raise InvalidContextError()
|
raise InvalidContextError()
|
||||||
return self._edge == other._edge
|
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):
|
if sys.version_info >= (3, 5, 2):
|
||||||
VertexId = typing.NewType('VertexId', int)
|
VertexId = typing.NewType('VertexId', int)
|
||||||
@ -304,6 +317,9 @@ class Vertex:
|
|||||||
raise InvalidContextError()
|
raise InvalidContextError()
|
||||||
return self._vertex == other._vertex
|
return self._vertex == other._vertex
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash(self.id)
|
||||||
|
|
||||||
|
|
||||||
class Path:
|
class Path:
|
||||||
'''Path containing Vertex and Edge instances.'''
|
'''Path containing Vertex and Edge instances.'''
|
||||||
|
Loading…
Reference in New Issue
Block a user