KCC: setup_dijkstra() creates its own empty queue
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 7 May 2015 02:22:56 +0000 (14:22 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 12 Jun 2015 04:57:16 +0000 (06:57 +0200)
It needs to operate on an empty list, which is something the caller
really shouldn't have to worry about.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/kcc/graph.py

index 12e53f598b348175c3510076a87b883a201f9023..83555c214a85def751b07e28d1d14352d8b9cde0 100644 (file)
@@ -353,8 +353,7 @@ def dijkstra(graph, edge_type, include_black):
     :param include_black: boolean, whether to include black vertices
     :return: None
     """
-    queue = []
-    setup_dijkstra(graph, edge_type, include_black, queue)
+    queue = setup_dijkstra(graph, edge_type, include_black)
     while len(queue) > 0:
         cost, guid, vertex = heapq.heappop(queue)
         for edge in vertex.edges:
@@ -364,15 +363,15 @@ def dijkstra(graph, edge_type, include_black):
                     try_new_path(graph, queue, vertex, edge, v)
 
 
-def setup_dijkstra(graph, edge_type, include_black, queue):
-    """Initialise a queue for Dijksta's algorithm.
+def setup_dijkstra(graph, edge_type, include_black):
+    """Create a vertex queue for Dijksta's algorithm.
 
     :param graph: an IntersiteGraph object
     :param edge_type: a transport type GUID
     :param include_black: boolean, whether to include black vertices
-    :param queue: the empty queue to initialise.
-    :return: None
+    :return: A heap queue of vertices
     """
+    queue = []
     setup_vertices(graph)
     for vertex in graph.vertices:
         if vertex.is_white():
@@ -387,6 +386,8 @@ def setup_dijkstra(graph, edge_type, include_black, queue):
         else:
             heapq.heappush(queue, (vertex.repl_info.cost, vertex.guid, vertex))
 
+    return queue
+
 
 def try_new_path(graph, queue, vfrom, edge, vto):
     """Helper function for Dijksta's algorithm.