VertexMap

com.phasmidsoftware.gryphon.core.VertexMap
See theVertexMap companion object
case class VertexMap[V](map: Map[V, Vertex[V]]) extends Traversable[V]

Represents a mapping of vertex attributes to their corresponding vertices within a graph. Provides functionality to manage and traverse vertices via DFS and BFS using the Visitor V1.2.0 typeclass engine.

The mutable discovered flag pattern has been removed; visited-node tracking is now handled entirely by the immutable VisitedSet[V] inside the traversal engine.

Type parameters

V

the type representing the vertex attributes (invariant).

Value parameters

map

a mapping from vertex attributes to their associated Vertex instances.

Attributes

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

Members list

Value members

Concrete methods

def +(vertex: Vertex[V]): VertexMap[V]

Adds a vertex to the VertexMap.

Adds a vertex to the VertexMap.

Attributes

def +[E](edge: Edge[V, E]): VertexMap[V]

Adds a directed or undirected edge to the vertex map.

Adds a directed or undirected edge to the vertex map.

Attributes

def +(pair: (V, V, EdgeType)): VertexMap[V]

Adds a vertex pair (with EdgeType) to the VertexMap.

Adds a vertex pair (with EdgeType) to the VertexMap.

Attributes

def M: Int

Returns the number of edges in the graph.

Returns the number of edges in the graph.

TODO: this mechanism uses a var and we should change that.

Attributes

Returns

the number of edges in the graph.

def N: Int

Returns the number of vertices in the graph.

Returns the number of vertices in the graph.

Attributes

Returns

the number of vertices in the graph.

def addEdges[E, Z](edgeList: EdgeList[V, E, Z]): VertexMap[V]

Adds the edges from the provided EdgeList to this VertexMap.

Adds the edges from the provided EdgeList to this VertexMap.

Attributes

def addTriplet[Z, E](edgeFunction: Z => (ProtoConnexion[V, E]) => Connexion[V])(vertexFunction: V => Vertex[V])(triplet: Triplet[V, E, Z]): VertexMap[V]

Adds a single triplet to the VertexMap.

Adds a single triplet to the VertexMap.

Attributes

def addTriplets[E, Z](vertexFunction: V => Vertex[V], edgeFunction: Z => (ProtoConnexion[V, E]) => Connexion[V])(triplets: Seq[Triplet[V, E, Z]]): VertexMap[V]

Processes a sequence of triplets and adds them to the VertexMap.

Processes a sequence of triplets and adds them to the VertexMap.

Attributes

def addVertexPairs[E](pairs: Seq[(V, V, EdgeType)]): VertexMap[V]

Adds a sequence of vertex pairs with their EdgeTypes to this VertexMap.

Adds a sequence of vertex pairs with their EdgeTypes to this VertexMap.

Attributes

def adjacentVertices(v: V)(using random: Random): Iterator[V]

Returns an iterator over the vertices adjacent to the given vertex.

Returns an iterator over the vertices adjacent to the given vertex.

Value parameters

v

the vertex for which adjacent vertices are to be retrieved.

Attributes

Returns

an iterator over the adjacent vertex attributes.

Throws
GraphException

if the specified vertex is not found in the graph.

def apply(key: V): Vertex[V]

Returns the vertex for the key, throwing NoSuchElementException if absent.

Returns the vertex for the key, throwing NoSuchElementException if absent.

Attributes

def applyOrElse(x: V, defaultFunc: V => Vertex[V]): Vertex[V]

Returns the vertex for key x, or applies defaultFunc if absent.

Returns the vertex for key x, or applies defaultFunc if absent.

Attributes

def bfs[R, J <: Appendable[(V, Option[R])]](visitor: Visitor[V, R, J])(v: V, goal: V => Boolean = ...)(using ev: Evaluable[V, R], random: Random): Visitor[V, R, J]

Performs BFS from v, accumulating results into visitor.

Performs BFS from v, accumulating results into visitor.

Value parameters

goal

early-termination predicate (default: never stop early).

v

the starting vertex.

visitor

the visitor to accumulate results.

Attributes

def bfse[E, R, J <: Appendable[(Edge[V, E], Option[R])]](visitor: Visitor[Edge[V, E], R, J])(v: V)(goal: V => Boolean)(using ev: Evaluable[Edge[V, E], R], random: Random): Visitor[Edge[V, E], R, J]

BFS over edges rather than vertices. NOTE: this is a stub — the old implementation was also effectively a stub. TODO implement this properly.

BFS over edges rather than vertices. NOTE: this is a stub — the old implementation was also effectively a stub. TODO implement this properly.

Value parameters

goal

early-termination predicate on destination vertices.

v

the starting vertex.

visitor

the visitor processing edges.

Attributes

def contains(key: V): Boolean

Checks if the specified key is present in the VertexMap.

Checks if the specified key is present in the VertexMap.

Attributes

def createAdjacency[E, Z](edgeFunction: (ProtoConnexion[V, E]) => Connexion[V])(vv1: Vertex[V], vv2: Vertex[V], maybeE: Option[E]): Adjacency[V]

Creates an Adjacency from an optional edge.

Creates an Adjacency from an optional edge.

Attributes

def createVerticesFromTriplet[E, Z](f: V => Vertex[V])(g: (Vertex[V], Vertex[V], Option[E]) => Adjacency[V])(condition: Boolean)(triplet: Triplet[V, E, Z]): VertexMap[V]

Creates vertices and adjacencies from a triplet.

Creates vertices and adjacencies from a triplet.

Attributes

def debug: String
def dfs[R, J <: Appendable[(V, Option[R])]](visitor: Visitor[V, R, J], order: DfsOrder = ...)(v: V)(using ev: Evaluable[V, R], random: Random): Visitor[V, R, J]

Performs DFS from v, accumulating results into visitor.

Performs DFS from v, accumulating results into visitor.

A local GraphNeighbours[V] derived from adjacentVertices is provided to the engine.

Value parameters

v

the starting vertex.

visitor

the visitor to accumulate results.

Attributes

def dfsAll[R, J <: Appendable[(V, Option[R])]](visitor: Visitor[V, R, J])(using ev: Evaluable[V, R], random: Random): Visitor[V, R, J]

Performs DFS for all vertices in the graph, including those not reachable from any single start vertex.

Performs DFS for all vertices in the graph, including those not reachable from any single start vertex.

Value parameters

visitor

the visitor to accumulate results.

Attributes

def filteredAdjacencies(predicate: Adjacency[V] => Boolean)(v: V): Iterator[Adjacency[V]]

Filters the adjacencies of a given vertex based on a specified predicate.

Filters the adjacencies of a given vertex based on a specified predicate.

Value parameters

predicate

a function that evaluates each Adjacency[V] and returns true if the adjacency satisfies the specified condition.

v

the vertex whose adjacencies are to be filtered.

Attributes

Returns

an iterator over the adjacencies of the given vertex that satisfy the predicate.

def get(key: V): Option[Vertex[V]]

Retrieves the vertex associated with the specified key.

Retrieves the vertex associated with the specified key.

Attributes

def getOrElse(key: V, default: => Vertex[V]): Vertex[V]

Returns the vertex for the key, or the default if not present.

Returns the vertex for the key, or the default if not present.

Attributes

def iterator: Iterator[V]

Provides an iterator over the keys in the underlying map.

Provides an iterator over the keys in the underlying map.

Attributes

def keySet: Set[V]

Retrieves the set of keys present in the VertexMap.

Retrieves the set of keys present in the VertexMap.

Attributes

Returns a new VertexMap with the same vertex keys but empty adjacency lists. Used to seed a reversed or transformed graph before re-adding edges.

Returns a new VertexMap with the same vertex keys but empty adjacency lists. Used to seed a reversed or transformed graph before re-adding edges.

Attributes

def modifyVertex(f: Vertex[V] => Vertex[V])(v: V): VertexMap[V]

Modifies a vertex in this VertexMap using the provided function.

Modifies a vertex in this VertexMap using the provided function.

Value parameters

f

the function to apply to the vertex.

v

the identifier of the vertex to modify.

Attributes

Returns

a new VertexMap with the vertex modified if it exists.

def neighboursGiven: GraphNeighbours[V]

Provides a GraphNeighbours[V] instance derived from the graphNeighbours method. The GraphNeighbours[V] instance facilitates efficient access to the neighbors of a vertex within the graph, enabling traversal algorithms to query adjacent vertices.

Provides a GraphNeighbours[V] instance derived from the graphNeighbours method. The GraphNeighbours[V] instance facilitates efficient access to the neighbors of a vertex within the graph, enabling traversal algorithms to query adjacent vertices.

Attributes

Returns

a GraphNeighbours[V] instance for querying vertex neighbors.

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def vertices: Iterable[Vertex[V]]

Retrieves all vertices in the VertexMap.

Retrieves all vertices in the VertexMap.

Attributes

Returns

an Iterable of all Vertex instances.

Inherited methods

def filteredAdjacentVertices(predicate: V => Boolean)(v: V): Iterator[V]

Filters the adjacent vertices of a given vertex based on a specified predicate.

Filters the adjacent vertices of a given vertex based on a specified predicate.

Value parameters

predicate

a function that evaluates each adjacent vertex and returns true if the vertex satisfies the specified condition.

v

the vertex whose adjacent vertices are to be filtered.

Attributes

Returns

an iterator over the vertices that are adjacent to v and satisfy the predicate.

Inherited from:
Traversable
def getConnexions[E](start: V): Connexions[V, E]

Retrieves the connexions (edges) reachable from start via DFS.

Retrieves the connexions (edges) reachable from start via DFS.

Type parameters

E

the type of the edges in the graph.

Value parameters

start

the starting vertex.

Attributes

Returns

a Connexions[V, E] object representing the discovered connexions.

Inherited from:
Traversable
def graphNeighbours(using random: Random): GraphNeighbours[V]

Derives a GraphNeighbours[V] instance from adjacentVertices. Used internally by the default implementations of vertexMappedTraversalDfs, vertexMappedTraversalBfs, and getConnexions.

Derives a GraphNeighbours[V] instance from adjacentVertices. Used internally by the default implementations of vertexMappedTraversalDfs, vertexMappedTraversalBfs, and getConnexions.

CONSIDER making this protected again but that requires multiple instances in each type of Traversal.

NOTE: do not be tempted to add a default Random implementation for this context. We need to enforce consistency of Random instances.

Attributes

Inherited from:
Traversable
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 vertexMappedTraversalBfs[T](fulfill: V => T)(start: V)(using random: Random = ...): Try[TraversalResult[V, T]]

Performs a BFS traversal applying fulfill to each visited vertex and returns a VertexTraversalResult mapping each vertex to its result.

Performs a BFS traversal applying fulfill to each visited vertex and returns a VertexTraversalResult mapping each vertex to its result.

Type parameters

T

the result type produced by fulfill.

Value parameters

fulfill

transformation function applied to each vertex.

start

the starting vertex.

Attributes

Returns

Try[TraversalResult[V, T]] containing the traversal result or a failure.

Inherited from:
Traversable
def vertexMappedTraversalDfs[T](fulfill: V => T)(start: V)(using random: Random = ...): Try[TraversalResult[V, T]]

Performs a DFS traversal applying fulfill to each visited vertex and returns a VertexTraversalResult mapping each vertex to its result.

Performs a DFS traversal applying fulfill to each visited vertex and returns a VertexTraversalResult mapping each vertex to its result.

Type parameters

T

the result type produced by fulfill.

Value parameters

fulfill

transformation function applied to each vertex.

start

the starting vertex.

Attributes

Returns

Try[TraversalResult[V, T]] containing the traversal result or a failure.

Inherited from:
Traversable