TopologicalSort

com.phasmidsoftware.gryphon.traverse.TopologicalSort
See theTopologicalSort companion object
case class TopologicalSort[V](map: Map[V, Int]) extends AbstractVertexTraversalResult[V, Int]

Represents a "topological sort" of a directed acyclic graph, mapping each vertex to its position in topological order. NOTE that it would also be possible to get the same effect using the Kosaraju algorithm (see Kosaraju.stronglyConnectedComponents) especially if you're not sure that the directed graph is in fact acyclic. If you have significant doubt, it may be better to use Kosaraju instead. A DAG will result in a topologically sorted set of SCCs, each of which holds only one vertex.

Type parameters

V

the type representing a vertex in the graph.

Value parameters

map

a mapping of vertices of type V to their position (Int) in topological order.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait TraversalResult[V, Int]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def unit(m: Map[V, Int]): TraversalResult[V, Int]

Creates a new instance with the provided vertex-to-position mapping.

Creates a new instance with the provided vertex-to-position mapping.

Value parameters

m

the updated mapping.

Attributes

Returns

a new TraversalResult[V, Int].

Inherited methods

def +(t: (V, Int)): TraversalResult[V, Int]

Adds a new mapping of a vertex to its corresponding traversal result to the existing map, returning a new VertexTraversalResult instance with the updated mapping.

Adds a new mapping of a vertex to its corresponding traversal result to the existing map, returning a new VertexTraversalResult instance with the updated mapping.

Value parameters

t

a tuple where the first element is a vertex of type V, and the second element is its associated traversal result of type T.

Attributes

Returns

a new VertexTraversalResult instance of type VertexTraversalResult[V, E, T] containing the updated map.

Inherited from:
AbstractVertexTraversalResult
def edgeTraverse(x: Int): Int

Traverses a specified edge within a graph-like structure and produces a result of type T.

Traverses a specified edge within a graph-like structure and produces a result of type T.

Value parameters

x

the index of the edge to be traversed

Attributes

Returns

the result of the traversal

Inherited from:
AbstractVertexTraversalResult
def keySet: Set[V]

Retrieves the set of keys from the underlying map that represents the traversal result.

Retrieves the set of keys from the underlying map that represents the traversal result.

Attributes

Returns

a set of keys of type V contained in the underlying map.

Inherited from:
AbstractVertexTraversalResult
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
def size: Int

Returns the number of key-value pairs in the map.

Returns the number of key-value pairs in the map.

Attributes

Returns

the size of the map as an integer

Inherited from:
AbstractVertexTraversalResult
def vertexTraverse(v: V): Option[Int]

Traverses the specified vertex in the graph and retrieves the associated traversal result from the underlying map. If the vertex does not exist, a NoSuchElementException is thrown.

Traverses the specified vertex in the graph and retrieves the associated traversal result from the underlying map. If the vertex does not exist, a NoSuchElementException is thrown.

Value parameters

v

the vertex to be traversed and looked up in the map.

Attributes

Returns

the traversal result of type T associated with the provided vertex.

Throws
NoSuchElementException

if the vertex does not exist in the map.

Inherited from:
AbstractVertexTraversalResult