Implement the PageRank module

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2730
This commit is contained in:
Lovro Lugovic
2020-03-19 10:05:27 +01:00
parent b7738c64b3
commit e5b3414335
2 changed files with 148 additions and 1 deletions

View File

@@ -439,12 +439,13 @@ class Record:
class Vertices:
'''Iterable over vertices in a graph.'''
__slots__ = ('_graph',)
__slots__ = ('_graph', '_len')
def __init__(self, graph):
if not isinstance(graph, _mgp.Graph):
raise TypeError("Expected '_mgp.Graph', got '{}'".format(type(graph)))
self._graph = graph
self._len = None
def __deepcopy__(self, memo):
# This is the same as the shallow copy, because we want to share the
@@ -468,6 +469,18 @@ class Vertices:
raise InvalidContextError()
vertex = vertices_it.next()
def __contains__(self, vertex):
try:
_ = self.graph.get_vertex_by_id(vertex.id)
return True
except IndexError:
return False
def __len__(self):
if not self._len:
self._len = sum(1 for _ in self)
return self._len
class Graph:
'''State of the graph database in current ProcCtx.'''