mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipapython/graph.py complexity optimization
Hi! I've just read the code and I saw that graph bfs uses not optimal for Python solution. So I've edited it with more optimal one. https://pagure.io/freeipa/issue/7051 Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com> Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
parent
f18ce01355
commit
52a435978b
@ -1,6 +1,7 @@
|
||||
#
|
||||
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
|
||||
# Copyright (C) 2015-2017 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
from collections import deque
|
||||
|
||||
|
||||
class Graph(object):
|
||||
@ -69,11 +70,12 @@ class Graph(object):
|
||||
Return a set of all visited vertices
|
||||
"""
|
||||
if not start:
|
||||
start = list(self.vertices)[0]
|
||||
start = next(iter(self.vertices))
|
||||
visited = set()
|
||||
queue = [start]
|
||||
queue = deque([start])
|
||||
|
||||
while queue:
|
||||
vertex = queue.pop(0)
|
||||
vertex = queue.popleft()
|
||||
if vertex not in visited:
|
||||
visited.add(vertex)
|
||||
queue.extend(set(self._adj.get(vertex, [])) - visited)
|
||||
|
Loading…
Reference in New Issue
Block a user