Class ASCIIGraph
- java.lang.Object
-
- it.unimi.dsi.webgraph.ImmutableGraph
-
- it.unimi.dsi.webgraph.ImmutableSequentialGraph
-
- it.unimi.dsi.webgraph.ASCIIGraph
-
- All Implemented Interfaces:
it.unimi.dsi.lang.FlyweightPrototype<ImmutableGraph>
public class ASCIIGraph extends ImmutableSequentialGraph
AnImmutableGraphthat 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)andloadOnce(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 ofArrayListMutableGraphbuilt by copying an offline instance of this class.Using
ASCIIGraphto convert your dataA 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 commandjava it.unimi.dsi.webgraph.BVGraph -g ASCIIGraph example bvexample
will produce a compressed graph inBVGraphformat with basenamebvexample. Even more convenient is theloadOnce(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 ofBVGraphto generate somehow an ASCII graph and store it in compressed form on the fly. The previous example could be then rewritten asjava it.unimi.dsi.webgraph.BVGraph -1 -g ASCIIGraph dummy bvexample <example.graph-txt
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class it.unimi.dsi.webgraph.ImmutableGraph
ImmutableGraph.LoadMethod
-
-
Field Summary
-
Fields inherited from class it.unimi.dsi.webgraph.ImmutableGraph
GRAPHCLASS_PROPERTY_KEY, NUMBER_OF_THREADS_PROPERTY, PROPERTIES_EXTENSION
-
-
Constructor Summary
Constructors Modifier Constructor Description ASCIIGraph(java.io.InputStream is)Creates a read-once ASCII graph.protectedASCIIGraph(java.lang.CharSequence graphFile)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ImmutableGraphload(java.lang.CharSequence basename)static ImmutableGraphload(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)static ASCIIGraphloadMapped(java.lang.CharSequence basename)static ASCIIGraphloadMapped(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)static ASCIIGraphloadOffline(java.lang.CharSequence basename)static ASCIIGraphloadOffline(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)static ASCIIGraphloadOnce(java.io.InputStream is)static ImmutableGraphloadSequential(java.lang.CharSequence basename)Deprecated.static ASCIIGraphloadSequential(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)Deprecated.static voidmain(java.lang.String[] args)NodeIteratornodeIterator(int from)Returns a node iterator for scanning the graph sequentially, starting from the given node.intnumNodes()Returns the number of nodes of this graph.NodeIterator[]splitNodeIterators(int howMany)Returns an array of node iterators, scanning each a portion of the nodes of a graph.static voidstore(ImmutableGraph graph, int shift, java.lang.CharSequence basename)static voidstore(ImmutableGraph graph, java.lang.CharSequence basename)static voidstore(ImmutableGraph graph, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)-
Methods inherited from class it.unimi.dsi.webgraph.ImmutableSequentialGraph
copy, outdegree, randomAccess, successorArray
-
Methods inherited from class it.unimi.dsi.webgraph.ImmutableGraph
basename, equals, hasCopiableIterators, hashCode, load, nodeIterator, numArcs, outdegrees, store, store, successors, toString
-
-
-
-
Constructor Detail
-
ASCIIGraph
protected ASCIIGraph(java.lang.CharSequence graphFile) throws java.lang.NumberFormatException, java.io.IOException- Throws:
java.lang.NumberFormatExceptionjava.io.IOException
-
ASCIIGraph
public ASCIIGraph(java.io.InputStream is) throws java.lang.NumberFormatException, java.io.IOExceptionCreates a read-once ASCII graph. Instances created using this constructor can be only accessed using a single call tonodeIterator(int).- Parameters:
is- an input stream containing an ASCII graph.- Throws:
java.lang.NumberFormatExceptionjava.io.IOException
-
-
Method Detail
-
numNodes
public int numNodes()
Description copied from class:ImmutableGraphReturns the number of nodes of this graph.Albeit this method is not optional, it is allowed that this method throws an
UnsupportedOperationExceptionif this graph has never been entirely traversed using anode iterator. This apparently bizarre behaviour is necessary to support implementations asArcListASCIIGraph, which do not know the actual number of nodes until a traversal has been completed.- Specified by:
numNodesin classImmutableGraph- Returns:
- the number of nodes.
-
nodeIterator
public NodeIterator nodeIterator(int from)
Description copied from class:ImmutableGraphReturns a node iterator for scanning the graph sequentially, starting from the given node.- Overrides:
nodeIteratorin classImmutableSequentialGraph- Parameters:
from- the node from which the iterator will iterate.- Returns:
- a
NodeIteratorfor accessing nodes and successors sequentially.
-
splitNodeIterators
public NodeIterator[] splitNodeIterators(int howMany)
Description copied from class:ImmutableGraphReturns an array of node iterators, scanning each a portion of the nodes of a graph. Iterators are guaranteed to scan mutually disjoint sets of nodes, and every node is guaranteed to be scanned by one iterator.This is an optional operation. If implemented, though, the returned iterators must properly implement
NodeIterator.copy(int).- Overrides:
splitNodeIteratorsin classImmutableGraph- Parameters:
howMany- the number of iterators to be returned (at the end of the array, some of them may be empty).- Returns:
- the required iterators.
-
loadSequential
@Deprecated public static ImmutableGraph loadSequential(java.lang.CharSequence basename) throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
loadSequential
@Deprecated public static ASCIIGraph loadSequential(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
loadOffline
public static ASCIIGraph loadOffline(java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
loadOffline
public static ASCIIGraph loadOffline(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
loadMapped
public static ASCIIGraph loadMapped(java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
loadMapped
public static ASCIIGraph loadMapped(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
loadOnce
public static ASCIIGraph loadOnce(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public static ImmutableGraph load(java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public static ImmutableGraph load(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, int shift, java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
main
public static void main(java.lang.String[] args) throws java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.io.IOException, com.martiansoftware.jsap.JSAPException, java.lang.ClassNotFoundException, java.lang.InstantiationException- Throws:
java.lang.IllegalArgumentExceptionjava.lang.SecurityExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.NoSuchMethodExceptionjava.io.IOExceptioncom.martiansoftware.jsap.JSAPExceptionjava.lang.ClassNotFoundExceptionjava.lang.InstantiationException
-
-