Visitor

com.phasmidsoftware.visitor.core.Visitor
trait Visitor[V, R, J <: Appendable[(V, Option[R])]]

A Visitor accumulates (V, Option[R]) pairs into a journal J as it traverses a structure.

Two members provide access to the accumulated journal:

  • journal — the raw journal value of type J; used internally by concrete implementations (e.g. JournaledVisitor.copy(journal = ...)) where the specific J type must be visible for polymorphic copying.
  • result — a public alias for journal, defaulting to journal; intended as the external API for consumers of a completed traversal. A concrete implementation could override result to apply post-processing (e.g. reversing a ListJournal) without affecting the internal journal.

Two events are distinguished:

  • visit(v) — called when a vertex is settled (dequeued/popped and processed). Records (v, ev.evaluate(v)) in the journal.
  • discover(v, cameFrom) — called when a vertex is first seen as a neighbour of cameFrom, before it is added to the frontier. Default implementation is a no-op; override in concrete implementations that track came-from pointers.

Type parameters

J

the journal type (must be Appendable of (V, Option[R]))

R

the result type extracted from each node

V

the node type

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class JournaledVisitor[V, R, J]

Members list

Value members

Abstract methods

def journal: J

Retrieves the journal J that accumulates pairs of (V, Option[R]) as a result of traversing a structure. The journal is an appendable collection used for recording events during the traversal.

Retrieves the journal J that accumulates pairs of (V, Option[R]) as a result of traversing a structure. The journal is an appendable collection used for recording events during the traversal.

Attributes

Returns

the journal of type J containing the accumulated data.

def visit(v: V)(using ev: Evaluable[V, R]): Visitor[V, R, J]

Visits a vertex v, evaluates it using the implicit Evaluable instance, and records the result in the journal. The visitor is returned after the operation with an updated state.

Visits a vertex v, evaluates it using the implicit Evaluable instance, and records the result in the journal. The visitor is returned after the operation with an updated state.

Value parameters

ev

the implicit Evaluable instance to extract a result of type R from the vertex v.

v

the vertex to be visited.

Attributes

Returns

the updated Visitor after the vertex is processed, with its journal containing the new (v, Option[R]) entry.

Concrete methods

def discover(v: V, cameFrom: V): Visitor[V, R, J]

Called when vertex v is discovered as a neighbour of cameFrom. Default: no-op. Override to record came-from relationships.

Called when vertex v is discovered as a neighbour of cameFrom. Default: no-op. Override to record came-from relationships.

Value parameters

cameFrom

the vertex being visited when v was discovered.

v

the newly discovered vertex.

Attributes

Returns

an updated visitor.

def result: J

Public accessor for the traversal result. Defaults to journal. Override to apply post-processing before returning results to callers.

Public accessor for the traversal result. Defaults to journal. Override to apply post-processing before returning results to callers.

Attributes