Class ASCIIGraph

All Implemented Interfaces:
FlyweightPrototype<ImmutableGraph>

public class ASCIIGraph
extends ImmutableSequentialGraph
An ImmutableGraph that corresponds to graphs stored in a human-readable ASCII format where each line contains the list of successors of a given node.

The file format is as follows: the graph is stored in a file named basename.graph-txt. The first line contains the number of nodes, n. Then, n lines follow, the i-th line containing the successors of node i in increasing order (nodes are numbered from 0 to n−1). Successors are separated by a single space.

Contrarily to other classes, the load methods of this class do not always return instances of this class. In particular, loadOffline(CharSequence) and loadOnce(InputStream) will return an instance of this class for offline access. The instance will not provide random access, but sequential access will be backed by the original text file and only one array of successor will be loaded in core memory at any time.

The load(CharSequence) method, on the other hand, will return an instance of ArrayListMutableGraph built by copying an offline instance of this class.

Using ASCIIGraph to convert your data

A simple (albeit rather inefficient) way to import data into WebGraph is using ASCII graphs. Suppose you create the following file, named example.graph-txt:

  2
  1
  0 1
  
Then, the command
  java it.unimi.dsi.webgraph.BVGraph -g ASCIIGraph example bvexample
  
will produce a compressed graph in BVGraph format with basename bvexample. Even more convenient is the loadOnce(InputStream) method, which reads from an input stream an ASCII graph and exposes it for a single traversal. It can be used, for instance, with the main method of BVGraph to generate somehow an ASCII graph and store it in compressed form on the fly. The previous example could be then rewritten as
  java it.unimi.dsi.webgraph.BVGraph -1 -g ASCIIGraph dummy bvexample <example.graph-txt