jcommon.graph.impl
Class SimpleTopologicalSort<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
java.lang.Object
jcommon.graph.impl.SimpleTopologicalSort<TVertex,TValue,TProcessedValue>
- Type Parameters:
TValue - Type of Object that a topological sort will operate on.
- All Implemented Interfaces:
- ITopologicalSortStrategy<TVertex,TValue,TProcessedValue>
public final class SimpleTopologicalSort<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
- extends Object
- implements ITopologicalSortStrategy<TVertex,TValue,TProcessedValue>
Implements ITopologicalSortStrategy for doing iterative and concurrent topological sorts.
Please see the following for a description of the basic algorithm:
http://www.cs.washington.edu/education/courses/cse373/02sp/lectures/cse373-21-TopoSort-4up.pdf
- See Also:
- http://www.cs.washington.edu/education/courses/cse373/02sp/lectures/cse373-21-TopoSort-4up.pdf
|
Method Summary |
List<TValue> |
sort(IAdjacencyList<TVertex,TValue,TProcessedValue> adjacencyList)
Given an instance of IAdjacencyList, topologically sorts the graph. |
ITopologicalSortAsyncResult<TValue,TProcessedValue> |
sortAsync(ExecutorService executorProcessors,
IAdjacencyList<TVertex,TValue,TProcessedValue> adjacencyList,
ITopologicalSortCallback<TValue,TProcessedValue> callback,
ITopologicalSortErrorCallback<TValue> errorCallback)
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. |
SimpleTopologicalSort
public SimpleTopologicalSort()
- See Also:
ITopologicalSortStrategy
sort
public List<TValue> sort(IAdjacencyList<TVertex,TValue,TProcessedValue> 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<TValue>,TValue,TProcessedValue>
- 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:
ITopologicalSortStrategy.sort(IAdjacencyList)
sortAsync
public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executorProcessors,
IAdjacencyList<TVertex,TValue,TProcessedValue> adjacencyList,
ITopologicalSortCallback<TValue,TProcessedValue> callback,
ITopologicalSortErrorCallback<TValue> 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<TValue>,TValue,TProcessedValue>
- 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(Object, ITopologicalSortInput, IVertex, 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:
ITopologicalSortStrategy.sortAsync(ExecutorService, IAdjacencyList, ITopologicalSortCallback, ITopologicalSortErrorCallback)
Copyright © 2012-2013. All Rights Reserved.