Tracer

com.phasmidsoftware.visitor.core.Tracer
See theTracer companion object
trait Tracer[V]

Typeclass for algorithm tracing. Implementations produce human-readable output showing the steps of a graph algorithm at a given nesting depth; the depth is used to indent output so that the logical structure of the algorithm is visible.

Each trace call provides two lazily-evaluated messages:

  • brief — a short summary (e.g. a count); always used by non-silent tracers
  • detail — a fuller description (e.g. collection elements); used only by verbose

The canonical no-op given (Tracer.silent) is resolved automatically, so existing call sites require no changes. Students opt in by summoning a tracer:

 given Tracer[Int] = Tracer.verbose()
 Kosaraju.stronglyConnectedComponents(graph)

Both brief and detail are by-name so that string interpolation is never evaluated in the silent case — zero overhead in production use.

Three built-in modes:

  • silent — no output, neither brief nor detail evaluated
  • summary — emits brief only, and only at depth 0
  • verbose — emits detail (falling back to brief if detail is empty), up to a configurable maxDepth

Type parameters

V

the vertex type (present so that, for example, a vertex tracer and an edge tracer can coexist in scope via their distinct type parameters)

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def trace(depth: Int, brief: => String, detail: => String = ...): Unit

Emit a trace message at the given nesting depth.

Emit a trace message at the given nesting depth.

Value parameters

brief

a short summary message, evaluated lazily

depth

nesting depth (0 = top-level algorithm entry, 1 = outer loop body, 2 = inner loop / recursive call, etc.)

detail

a fuller description, evaluated lazily; defaults to "" so that existing single-string call sites compile unchanged

Attributes