Class ImplicitDiGraph<T>

java.lang.Object
it.unimi.di.prog2.h25.digraph.ImplicitDiGraph<T>
Type Parameters:
T - the type of the graph nodes.
All Implemented Interfaces:
DiGraph<T>

public class ImplicitDiGraph<T> extends Object implements DiGraph<T>
An implicit directed graph implementation.

Graphs of this class are defined just by a collection of nodes and a "delta" function that, for every node, returns a collection giving the outgoing set. The arcs are not memorized, but computed using the "delta" function.

  • Field Details

  • Constructor Details

    • ImplicitDiGraph

      public ImplicitDiGraph(Collection<T> nodes, Function<T,Collection<T>> delta)
      Creates a directed graph given nodes and a function to obtain the outgoing sets.

      Observe that if nodes is not required to be a set, duplicate elements will be not be considered at creation time; similarly, the delta function can return duplicate values, the outgoing(Object) method will take care to remove them.

      Parameters:
      nodes - a collection of nodes.
      delta - the function that will be used to compute the outgoing sets.
  • Method Details

    • nodes

      public Set<T> nodes()
      Description copied from interface: DiGraph
      Returns the graph nodes.
      Specified by:
      nodes in interface DiGraph<T>
      Returns:
      the graph nodes.
    • outgoing

      public Set<T> outgoing(T source)
      Description copied from interface: DiGraph
      Returns the set of outgoing nodes of a given node.
      Specified by:
      outgoing in interface DiGraph<T>
      Parameters:
      source - the source node.
      Returns:
      the nodes that have an arc with the given source in this graph (the collection is empty if the source does not belong to this graph).