Class BitStreamArcLabelledImmutableGraph
- All Implemented Interfaces:
FlyweightPrototype<ImmutableGraph>
Instances of this class wrap a given immutable graph and a bit stream.
Given a prototype Label
, the bit stream is then considered as containing all labels of all arcs
as returned by a complete enumeration (made using ArcLabelledImmutableGraph.nodeIterator()
). The overall graph is described
by a label file (with extension
.labels
), an offset file (with extension
.labeloffsets
) and a property file (with extension
.properties
). The latter, not surprisingly, is a Java property file.
Optionally, a label offset big-list file (with extension
.labelobl
) can be created to load label offsets faster.
The Label and Offset Files
Since the labels are stored as a bit stream, we must have some way to know where the labels related to the successors of each node start. This information is stored in the offset file, which contains the bit offset of the list of labels of the arcs going out of each node (in particular, the offset of the first list will be zero). As a commodity, the offset file contains an additional offset pointing just after the last list (providing, as a side-effect, the actual bit length of the label file). Each offset (except for the first one) is stored as a γ-coded difference from the previous offset.
Note that by default the EliasFanoMonotoneLongBigList
instance is created from scratch
using the file of label offsets. This is a long and tedious process, in particular with large label files.
The main method of this class has an option that will generate such a list once for all and
serialise it in a file with extension .labelobl
. The list will be quickly deserialised if
this file is present.
The Property File
The property file for an instance of this class must contain the following entries:
- graphclass
- the name of this class; it is necessary so that load methods in
ImmutableGraph
can identify this class; - underlyinggraph
- the basename (relative to the name of the property file, unless it is absolute) of the underlying
ImmutableGraph
; - labelspec
- a string describing a constructor call for a label class; an example is
it.unimi.dsi.webgraph.labelling.FixedWidthIntLabel(FOO,10)
Label
for details about string-based constructors).
The load()
method of this class takes care of looking at the property file, loading the underlying immutable graph,
and setting up either sequential or random access to the bit stream containing the labels. If
just sequential access is required, the offsets are not loaded into memory, and if just offline
access is required, bit stream is never loaded into memory.
Saving labels
The store(ArcLabelledImmutableGraph, CharSequence, CharSequence)
and store(ArcLabelledImmutableGraph, CharSequence, CharSequence, ProgressLogger)
methods will save the labels of an instance of this graph as expected, that is,
the bitstream and its offsets will be saved with the extensions described above.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Nested classes/interfaces inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
ImmutableGraph.LoadMethod
-
Field Summary
Modifier and TypeFieldDescriptionprotected final CharSequence
The basename of this graph (required for offline access).final ImmutableGraph
The underlying immutable graph.static final String
The standard extension for the cachedLongBigList
containing the label offsets.static final String
The standard extension for the label offsets bit stream.static final String
The standard extension for the labels bit stream.static final String
The standard property key for a label specification.protected final LongBigList
The offset array, ornull
for sequential access.protected final Label
A prototype label, used to deserialise labels and create copies.Fields inherited from class it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph
UNDERLYINGGRAPH_PROPERTY_KEY, UNDERLYINGGRAPH_SUFFIX
Fields inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
GRAPHCLASS_PROPERTY_KEY, NUMBER_OF_THREADS_PROPERTY, PROPERTIES_EXTENSION
-
Constructor Summary
ModifierConstructorDescriptionprotected
BitStreamArcLabelledImmutableGraph
(CharSequence basename, ImmutableGraph g, Label prototype, byte[] byteArray, FastMultiByteArrayInputStream labelStream, ByteBufferInputStream mappedLabelStream, LongBigList offset) Builds a new labelled graph using a bit stream of labels. -
Method Summary
Modifier and TypeMethodDescriptionbasename()
Returns a symbolic basename for this graph (optional operation).copy()
Returns a flyweight copy of this immutable graph.boolean
Whether the node iterators returned by this graph supportNodeIterator.copy(long)
.protected static BitStreamArcLabelledImmutableGraph
load
(ImmutableGraph.LoadMethod method, CharSequence basename, ProgressLogger pl) Loads a labelled graph using the given method and offset step.load
(CharSequence basename) load
(CharSequence basename, ProgressLogger pl) loadMapped
(CharSequence basename) loadMapped
(CharSequence basename, ProgressLogger pl) loadOffline
(CharSequence basename) loadOffline
(CharSequence basename, ProgressLogger pl) loadSequential
(CharSequence basename) Deprecated.loadSequential
(CharSequence basename, ProgressLogger pl) Deprecated.static void
Reads an arc-labelled immutable graph and stores it as aBitStreamArcLabelledImmutableGraph
.protected InputBitStream
Returns the label bit stream.nodeIterator
(long from) Returns a node iterator for scanning the graph sequentially, starting from the given node.long
numArcs()
Returns the number of arcs of this graph (optional operation).long
numNodes()
Returns the number of nodes of this graph.protected long
offset
(long x) Return the actual offset of the labels of the arcs going out of a given node.long
outdegree
(long x) Returns the outdegree of a node.Returns a prototype of the labels used by this graph.boolean
Checks whether this graph provides random access to successor lists.static void
store
(ArcLabelledImmutableGraph graph, CharSequence basename, CharSequence underlyingBasename) static void
store
(ArcLabelledImmutableGraph graph, CharSequence basename, CharSequence underlyingBasename, ProgressLogger pl) long[][]
successorBigArray
(long x) Returns a reference to a big array containing the successors of a given node.successors
(long x) Returns a lazy iterator over the successors of a given node.Methods inherited from class it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph
equals, labelBigArray, loadOnce, nodeIterator, toString
Methods inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
hashCode, intNumNodes, load, outdegrees, splitNodeIterators, store, store, wrap, wrap
-
Field Details
-
LABELS_EXTENSION
The standard extension for the labels bit stream.- See Also:
-
LABEL_OFFSETS_EXTENSION
The standard extension for the label offsets bit stream.- See Also:
-
LABEL_OFFSETS_BIG_LIST_EXTENSION
The standard extension for the cachedLongBigList
containing the label offsets.- See Also:
-
LABELSPEC_PROPERTY_KEY
The standard property key for a label specification.- See Also:
-
g
The underlying immutable graph. -
prototype
A prototype label, used to deserialise labels and create copies. -
basename
The basename of this graph (required for offline access). -
offset
The offset array, ornull
for sequential access.
-
-
Constructor Details
-
BitStreamArcLabelledImmutableGraph
protected BitStreamArcLabelledImmutableGraph(CharSequence basename, ImmutableGraph g, Label prototype, byte[] byteArray, FastMultiByteArrayInputStream labelStream, ByteBufferInputStream mappedLabelStream, LongBigList offset) Builds a new labelled graph using a bit stream of labels.- Parameters:
basename
- the basename of the graph (mandatory for offline access).g
- the underlying immutable graph.prototype
- a label instance.byteArray
- a byte array containing the bit stream of labels, ornull
for offile access or large file access.labelStream
- ifbyteArray
isnull
, this stream is used as the bit stream of labels.mappedLabelStream
- ifbyteArray
andlabelStream
arenull
, this memory-mapped stream is used as the bit stream of labels.offset
- the offset array for random access, ornull
.
-
-
Method Details
-
copy
Description copied from class:ImmutableGraph
Returns a flyweight copy of this immutable graph.- Specified by:
copy
in interfaceFlyweightPrototype<ImmutableGraph>
- Specified by:
copy
in classArcLabelledImmutableGraph
- Returns:
- a flyweight copy of this immutable graph.
- See Also:
-
newInputBitStream
Returns the label bit stream.This method takes care of creating the bit stream from the right source—the byte array, the stream of multiple byte arrays or the label file itself.
- Returns:
- the label bit stream.
- Throws:
FileNotFoundException
-
basename
Description copied from class:ImmutableGraph
Returns a symbolic basename for this graph (optional operation).Implementors of this class may provide a basename (usually a pathname from which various files storing the graph are stemmed). This method is optional because it is sometimes unmeaningful (e.g., for one-off anonymous classes).
- Overrides:
basename
in classImmutableGraph
- Returns:
- the basename.
-
offset
protected long offset(long x) Return the actual offset of the labels of the arcs going out of a given node.- Parameters:
x
- a node.- Returns:
- the offset of the labels of the arcs going out of
x
.
-
successors
Description copied from class:ImmutableGraph
Returns a lazy iterator over the successors of a given node. The iteration terminates when -1 is returned.- Specified by:
successors
in classArcLabelledImmutableGraph
- Parameters:
x
- a node.- Returns:
- a lazy iterator over the successors of the node.
-
successorBigArray
public long[][] successorBigArray(long x) Description copied from class:ImmutableGraph
Returns a reference to a big array containing the successors of a given node.The returned big array may contain more entries than the outdegree of
x
. However, only those with indices from 0 (inclusive) to the outdegree ofx
(exclusive) contain valid data.- Overrides:
successorBigArray
in classImmutableGraph
- Parameters:
x
- a node.- Returns:
- a big array whose first elements are the successors of the node; the array must not be modified by the caller.
-
numNodes
public long 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.
-
numArcs
public long numArcs()Description copied from class:ImmutableGraph
Returns the number of arcs of this graph (optional operation).- Overrides:
numArcs
in classImmutableGraph
- Returns:
- the number of arcs.
-
randomAccess
public boolean randomAccess()Description copied from class:ImmutableGraph
Checks whether this graph provides random access to successor lists.- Specified by:
randomAccess
in classImmutableGraph
- Returns:
- true if this graph provides random access to successor lists.
-
hasCopiableIterators
public boolean hasCopiableIterators()Description copied from class:ImmutableGraph
Whether the node iterators returned by this graph supportNodeIterator.copy(long)
.- Overrides:
hasCopiableIterators
in classImmutableGraph
- Returns:
- true if this graph provides copiable iterators.
-
outdegree
public long outdegree(long x) Description copied from class:ImmutableGraph
Returns the outdegree of a node.- Specified by:
outdegree
in classImmutableGraph
- Parameters:
x
- a node.- Returns:
- the outdegree of the given node.
-
loadSequential
@Deprecated public static BitStreamArcLabelledImmutableGraph loadSequential(CharSequence basename) throws IOException Deprecated.- Throws:
IOException
-
loadSequential
@Deprecated public static BitStreamArcLabelledImmutableGraph loadSequential(CharSequence basename, ProgressLogger pl) throws IOException Deprecated.- Throws:
IOException
-
loadOffline
public static BitStreamArcLabelledImmutableGraph loadOffline(CharSequence basename) throws IOException - Throws:
IOException
-
loadOffline
public static BitStreamArcLabelledImmutableGraph loadOffline(CharSequence basename, ProgressLogger pl) throws IOException - Throws:
IOException
-
loadMapped
public static BitStreamArcLabelledImmutableGraph loadMapped(CharSequence basename) throws IOException - Throws:
IOException
-
loadMapped
public static BitStreamArcLabelledImmutableGraph loadMapped(CharSequence basename, ProgressLogger pl) throws IOException - Throws:
IOException
-
load
- Throws:
IOException
-
load
public static BitStreamArcLabelledImmutableGraph load(CharSequence basename, ProgressLogger pl) throws IOException - Throws:
IOException
-
load
protected static BitStreamArcLabelledImmutableGraph load(ImmutableGraph.LoadMethod method, CharSequence basename, ProgressLogger pl) throws IOException Loads a labelled graph using the given method and offset step.If
offsetStep
is larger than 1 and the the underlying graph is aBVGraph
, the value will be passed toBVGraph.load(CharSequence, int, ProgressLogger)
.- Parameters:
method
- a load method.basename
- the basename of the graph.pl
- a progress logger.- Returns:
- a graph labelled using a bit stream.
- Throws:
IOException
-
nodeIterator
Description copied from class:ArcLabelledImmutableGraph
Returns a node iterator for scanning the graph sequentially, starting from the given node.- Overrides:
nodeIterator
in classArcLabelledImmutableGraph
- Parameters:
from
- the node from which the iterator will iterate.- Returns:
- an
ArcLabelledNodeIterator
for accessing nodes, successors and their labels sequentially. - See Also:
-
prototype
Description copied from class:ArcLabelledImmutableGraph
Returns a prototype of the labels used by this graph. The prototype can be used to produce new copies, but must not be modified by the caller.- Specified by:
prototype
in classArcLabelledImmutableGraph
- Returns:
- a prototype for the labels of this graph.
-
store
public static void store(ArcLabelledImmutableGraph graph, CharSequence basename, CharSequence underlyingBasename) throws IOException - Throws:
IOException
-
store
public static void store(ArcLabelledImmutableGraph graph, CharSequence basename, CharSequence underlyingBasename, ProgressLogger pl) throws IOException - Throws:
IOException
-
main
Reads an arc-labelled immutable graph and stores it as aBitStreamArcLabelledImmutableGraph
.- Throws:
JSAPException
IOException
-