Documentation of 'edu.princeton.cs.algs4.SymbolDigraph' Java class
SymbolDigraph
edu.princeton.cs.algs4

Class SymbolDigraph



  • public class SymbolDigraph
    extends java.lang.Object
    The SymbolDigraph class represents a digraph, where the vertex names are arbitrary strings. By providing mappings between string vertex names and integers, it serves as a wrapper around the Digraph data type, which assumes the vertex names are integers between 0 and V - 1. It also supports initializing a symbol digraph from a file.

    This implementation uses an ST to map from strings to integers, an array to map from integers to strings, and a Digraph to store the underlying graph. The indexOf and contains operations take time proportional to log V, where V is the number of vertices. The nameOf operation takes constant time.

    For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • Constructor Summary

      Constructors 
      Constructor and Description
      SymbolDigraph(java.lang.String filename, java.lang.String delimiter)
      Initializes a digraph from a file using the specified delimiter.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      boolean contains(java.lang.String s)
      Does the digraph contain the vertex named s?
      Digraph digraph()
      Returns the digraph assoicated with the symbol graph.
      Digraph G()
      Deprecated. 
      Replaced by digraph().
      int index(java.lang.String s)
      Deprecated. 
      Replaced by indexOf(String).
      int indexOf(java.lang.String s)
      Returns the integer associated with the vertex named s.
      static void main(java.lang.String[] args)
      Unit tests the SymbolDigraph data type.
      java.lang.String name(int v)
      Deprecated. 
      Replaced by nameOf(int).
      java.lang.String nameOf(int v)
      Returns the name of the vertex associated with the integer v.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SymbolDigraph

        public SymbolDigraph(java.lang.String filename,
                             java.lang.String delimiter)
        Initializes a digraph from a file using the specified delimiter. Each line in the file contains the name of a vertex, followed by a list of the names of the vertices adjacent to that vertex, separated by the delimiter.
        Parameters:
        filename - the name of the file
        delimiter - the delimiter between fields
    • Method Detail

      • contains

        public boolean contains(java.lang.String s)
        Does the digraph contain the vertex named s?
        Parameters:
        s - the name of a vertex
        Returns:
        true if s is the name of a vertex, and false otherwise
      • index

        @Deprecated
        public int index(java.lang.String s)
        Deprecated. Replaced by indexOf(String).
        Returns the integer associated with the vertex named s.
        Parameters:
        s - the name of a vertex
        Returns:
        the integer (between 0 and V - 1) associated with the vertex named s
      • indexOf

        public int indexOf(java.lang.String s)
        Returns the integer associated with the vertex named s.
        Parameters:
        s - the name of a vertex
        Returns:
        the integer (between 0 and V - 1) associated with the vertex named s
      • name

        @Deprecated
        public java.lang.String name(int v)
        Deprecated. Replaced by nameOf(int).
        Returns the name of the vertex associated with the integer v.
        Parameters:
        v - the integer corresponding to a vertex (between 0 and V - 1)
        Returns:
        the name of the vertex associated with the integer v
        Throws:
        java.lang.IllegalArgumentException - unless 0 <= v < V
      • nameOf

        public java.lang.String nameOf(int v)
        Returns the name of the vertex associated with the integer v.
        Parameters:
        v - the integer corresponding to a vertex (between 0 and V - 1)
        Returns:
        the name of the vertex associated with the integer v
        Throws:
        java.lang.IllegalArgumentException - unless 0 <= v < V
      • G

        @Deprecated
        public Digraph G()
        Deprecated. Replaced by digraph().
        Returns the digraph assoicated with the symbol graph. It is the client's responsibility not to mutate the digraph.
        Returns:
        the digraph associated with the symbol digraph
      • digraph

        public Digraph digraph()
        Returns the digraph assoicated with the symbol graph. It is the client's responsibility not to mutate the digraph.
        Returns:
        the digraph associated with the symbol digraph
      • main

        public static void main(java.lang.String[] args)
        Unit tests the SymbolDigraph data type.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.