Package com.jgalgo.io

Class Sparse6GraphReader

  • All Implemented Interfaces:
    GraphReader<Integer,​Integer>

    public final class Sparse6GraphReader
    extends Object
    Read a graph in 'sparse6' format.

    'sparse6' is a format for storing undirected graphs in a compact manner, using only printable ASCII characters. Files in these format have text type and contain one line per graph. It is space-efficient for large sparse graphs. The format support graphs with vertices numbered 0..n-1 only, where n is the number of vertices, and edges numbered 0..m-1 only, where m is the number of edges. A sparse6 file contains the number of vertices, following by a list of edges, encoded in bytes, each in range 63..126 which are the printable ASCII characters. Each byte encode 6 bits.

    The format does not support specifying the ids of the edges, therefore the reader will number them from 0 to m-1 in the order it reads them.

    Self edges and parallel edges are supported by the format. The full description of the format can be found here, which also define the 'graph6' format, which is used for dense graph. See Graph6GraphReader for reading graphs in 'graph6' format.

    File with a graph in 'sparse6' format usually have the extension .s6.

    Author:
    Barak Ugav
    See Also:
    Sparse6GraphWriter
    • Constructor Detail

      • Sparse6GraphReader

        public Sparse6GraphReader()
        Create a new reader.
    • Method Detail

      • readGraph

        public IntGraph readGraph​(Reader reader)
        Description copied from interface: GraphReader
        Read a graph from an I/O reader.
        Parameters:
        reader - an I/O reader that contain a graph description
        Returns:
        a new graph read from the reader
      • readGraph

        public IntGraph readGraph​(File file)
        Description copied from interface: GraphReader
        Read a graph from a file.
        Parameters:
        file - a file that contain a graph description
        Returns:
        a new graph read from the file
      • readGraph

        public IntGraph readGraph​(String path)
        Description copied from interface: GraphReader
        Read a graph from a file, given a path to it.
        Parameters:
        path - a path to a file that contain a graph description
        Returns:
        a new graph read from the file