Class IncrementalImmutableSequentialGraph
- All Implemented Interfaces:
FlyweightPrototype<ImmutableGraph>
public class IncrementalImmutableSequentialGraph extends ImmutableSequentialGraph
ImmutableGraph
that can be filled incrementally using
a family of addition methods that make it possible to specify
the list of successors of each node in increasing order. At the end of the process, the user
must add the special marker list END_OF_GRAPH
.
The class provides a single
call to nodeIterator()
: once the returned NodeIterator
has been exhausted, numNodes()
will return the number of nodes,
which will be equal to the number of calls to addition methods.
The class works using a producer/consumer patten: in a typical usage, the thread invoking the addition method will be different from the thread performing the traversal, as in
final IncrementalImmutableSequentialGraph g = new IncrementalImmutableSequentialGraph(); ExecutorService executor = Executors.newSingleThreadExecutor(); final Future<Void> future = executor.submit(new Callable<Void>() { public Void call() throws IOException { BVGraph.store(g, basename); return null; } }); // Do one add() for each node, to specify the successors g.add(IncrementalImmutableSequentialGraph.END_OF_GRAPH); future.get(); executor.shutdown();
-
Nested Class Summary
Nested classes/interfaces inherited from class it.unimi.dsi.webgraph.ImmutableGraph
ImmutableGraph.LoadMethod
-
Field Summary
Fields Modifier and Type Field Description static int[]
END_OF_GRAPH
A marker for the end of the graph.Fields inherited from class it.unimi.dsi.webgraph.ImmutableGraph
GRAPHCLASS_PROPERTY_KEY, NUMBER_OF_THREADS_PROPERTY, PROPERTIES_EXTENSION
-
Constructor Summary
Constructors Constructor Description IncrementalImmutableSequentialGraph()
-
Method Summary
Modifier and Type Method Description void
add(int[] successor)
Adds a new node having as successors contained in the specified array.void
add(int[] successor, int offset, int length)
Adds a new node having as successors contained in the specified array fragment.NodeIterator
nodeIterator()
Returns a node iterator for scanning the graph sequentially, starting from the first node.int
numNodes()
Returns the number of nodes of this graph.Methods inherited from class it.unimi.dsi.webgraph.ImmutableSequentialGraph
copy, nodeIterator, outdegree, randomAccess, successorArray
Methods inherited from class it.unimi.dsi.webgraph.ImmutableGraph
basename, equals, hasCopiableIterators, hashCode, load, load, load, loadMapped, loadMapped, loadOffline, loadOffline, loadOnce, loadSequential, loadSequential, numArcs, outdegrees, splitNodeIterators, store, store, successors, toString
-
Field Details
-
END_OF_GRAPH
public static int[] END_OF_GRAPHA marker for the end of the graph.
-
-
Constructor Details
-
IncrementalImmutableSequentialGraph
public IncrementalImmutableSequentialGraph()
-
-
Method Details
-
numNodes
public int numNodes()Description copied from class:ImmutableGraph
Returns the number of nodes of this graph.Albeit this method is not optional, it is allowed that this method throws an
UnsupportedOperationException
if 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:
numNodes
in classImmutableGraph
- Returns:
- the number of nodes.
-
nodeIterator
Description copied from class:ImmutableGraph
Returns a node iterator for scanning the graph sequentially, starting from the first node.- Overrides:
nodeIterator
in classImmutableGraph
- Returns:
- a
NodeIterator
for accessing nodes and successors sequentially.
-
add
Adds a new node having as successors contained in the specified array fragment.The array must be sorted in increasing order.
- Parameters:
successor
- an array.offset
- the first valid entry insuccessor
.length
- the number of valid entries.- Throws:
InterruptedException
-
add
Adds a new node having as successors contained in the specified array.The array must be sorted in increasing order.
- Parameters:
successor
- an array.- Throws:
InterruptedException
-