Class AdjacencyMapDiGraph<T>

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

public class AdjacencyMapDiGraph<T> extends Object implements DiGraph<T>
A directed graph implementation based on a Map between nodes and their outgoing sets.
  • Field Details

    • adjacency

      private final Map<T,Set<T>> adjacency
      A Map between nodes and their outgoing sets.

      Every node in the graph is a key of this map, and viceversa. Isolated nodes map to Collections.emptySet().

  • Constructor Details

    • AdjacencyMapDiGraph

      public AdjacencyMapDiGraph()
  • Method Details

    • addArc

      public void addArc(T src, T dst)
      Description copied from interface: DiGraph
      Adds an arc to this graph.

      It the source, or destination, node are not present in the graph, they are also added.

      Specified by:
      addArc in interface DiGraph<T>
      Parameters:
      src - the source of the arc to be added.
      dst - the destination of the arc to be added.
    • addNode

      public void addNode(T node)
      Description copied from interface: DiGraph
      Adds a node to this graph.
      Specified by:
      addNode in interface DiGraph<T>
      Parameters:
      node - the node to be added.
    • hasArc

      public boolean hasArc(T src, T dst)
      Description copied from interface: DiGraph
      Tells whether an arc belongs to this graph, or not.
      Specified by:
      hasArc in interface DiGraph<T>
      Parameters:
      src - the source of the arc to be queried.
      dst - the destination of the arc to be queried.
      Returns:
      whether the arc belongs to the graph, or not.
    • outgoing

      public Set<T> outgoing(T src)
      Description copied from interface: DiGraph
      Returns the set of outgoing nodes of a given node.
      Specified by:
      outgoing in interface DiGraph<T>
      Parameters:
      src - 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).
    • 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.