jcommon.graph.impl
Class SimpleTopologicalSort<TVertex extends IVertex>

java.lang.Object
  extended by jcommon.graph.impl.SimpleTopologicalSort<TVertex>
All Implemented Interfaces:
ITopologicalSortStrategy<TVertex>

public final class SimpleTopologicalSort<TVertex extends IVertex>
extends Object
implements ITopologicalSortStrategy<TVertex>

Please see the following for a description of this algorithm: http://www.cs.washington.edu/education/courses/cse373/02sp/lectures/cse373-21-TopoSort-4up.pdf


Constructor Summary
SimpleTopologicalSort()
           
 
Method Summary
 List<TVertex> sort(IAdjacencyList<TVertex> adjacencyList)
          Given an instance of IAdjacencyList, topologically sorts the graph.
 ITopologicalSortAsyncResult sortAsync(ExecutorService executorProcessors, IAdjacencyList<TVertex> adjacencyList, ITopologicalSortCallback<TVertex> callback, ITopologicalSortErrorCallback<TVertex> errorCallback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTopologicalSort

public SimpleTopologicalSort()
Method Detail

sort

public List<TVertex> sort(IAdjacencyList<TVertex> adjacencyList)
                                   throws CyclicGraphException
Description copied from interface: ITopologicalSortStrategy
Given an instance of IAdjacencyList, topologically sorts the graph.

Specified by:
sort in interface ITopologicalSortStrategy<TVertex extends IVertex>
Parameters:
adjacencyList - An instance of IAdjacencyList.
Returns:
The topologically sorted IGraph.
Throws:
CyclicGraphException - A CyclicGraphException is thrown if a cycle is detected during the sort.
See Also:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

public ITopologicalSortAsyncResult sortAsync(ExecutorService executorProcessors,
                                             IAdjacencyList<TVertex> adjacencyList,
                                             ITopologicalSortCallback<TVertex> callback,
                                             ITopologicalSortErrorCallback<TVertex> errorCallback)
Description copied from interface: ITopologicalSortStrategy
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

Specified by:
sortAsync in interface ITopologicalSortStrategy<TVertex extends IVertex>
Parameters:
executorProcessors - An instance of ExecutorService that will be used to submit tasks for processing vertices.
adjacencyList - An instance of IAdjacencyList.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
errorCallback - An instance of ITopologicalSortErrorCallback that will be called if an error during processing occurs either in the ITopologicalSortCallback.handle(IVertex, ITopologicalSortInput, ITopologicalSortCoordinator) method or in the ITopologicalSortStrategy.sortAsync(java.util.concurrent.ExecutorService, IAdjacencyList, ITopologicalSortCallback, ITopologicalSortErrorCallback) method.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
http://en.wikipedia.org/wiki/Topological_sorting


Copyright © 2012-2013. All Rights Reserved.