Class Digraph6GraphWriter
- java.lang.Object
-
- com.jgalgo.io.Digraph6GraphWriter
-
- All Implemented Interfaces:
GraphWriter<Integer,Integer>
public final class Digraph6GraphWriter extends Object
Write a graph in 'digraph6' format.'digraph6' is a format for storing directed 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 suitable for small graphs, or large dense 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 digraph6 file contains a bit vector with
n^2
bits representing the edges of the graph. All bytes of a digraph6 file are in the range 63..126, which are the printable ASCII characters, therefore a bit vector is represented by a sequence of bytes in which each byte encode only 6 bits.The format does not support specifying the ids of the edges, therefore the writer will not write them. Nevertheless, its possible to write and later read the graph using the
Digraph6GraphReader
class while keeping the edges ids: if the edges in the written graph are numbered 0..m-1, and when they are iterated from0
tom-1
they are also ordered by the order of the bit vector, then the reader will assigned the same ids to the edges. The order of the bit vector and the format details can be found here. This way of keeping the edges ids is enforced by the writer by default, but can be disabled by callingkeepEdgesIds(boolean)
withfalse
.The 'digraph6' format support directed graphs only, for undirected graphs the 'graph6' format should be used.
Parallel edges are not supported by the format.
File with a graph in 'digraph6' format usually have the extension
.d6
.- Author:
- Barak Ugav
- See Also:
Digraph6GraphReader
-
-
Constructor Summary
Constructors Constructor Description Digraph6GraphWriter()
Create a new writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
keepEdgesIds(boolean enable)
Enable or disable keeping the edges ids.void
writeGraph(Graph<V,E> graph, Writer writer)
Write a graph to an I/O writer.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.jgalgo.io.GraphWriter
writeGraph, writeGraph
-
-
-
-
Method Detail
-
keepEdgesIds
public void keepEdgesIds(boolean enable)
Enable or disable keeping the edges ids.The format does not support specifying the ids of the edges, therefore the writer will not write them. Nevertheless, its possible to write and later read the graph using the
Digraph6GraphReader
class while keeping the edges ids: if the edges in the written graph are numbered 0..m-1, and when they are iterated from0
tom-1
they are also ordered by the order of the bit vector, then the reader will assigned the same ids to the edges. The order of the bit vector and the format details can be found here.If this option is enabled, which is also the default, if a graph is written by the writer and the edges iterated from
0
tom-1
are not ordered by the order of the bit vector, then an exception will be thrown. If this option is disabled, the ids of the edges will be ignored and there is not guarantee that the reader will assign the same ids to the edges.- Parameters:
enable
-true
to enable keeping the edges ids,false
to disable it
-
writeGraph
public final void writeGraph(Graph<V,E> graph, Writer writer)
Description copied from interface:GraphWriter
Write a graph to an I/O writer.- Specified by:
writeGraph
in interfaceGraphWriter<V,E>
- Parameters:
graph
- a graphwriter
- an I/O writer to which the graph description will be written to
-
-