Package it.unimi.dsi.big.webgraph
Class EFGraph
- java.lang.Object
-
- it.unimi.dsi.big.webgraph.ImmutableGraph
-
- it.unimi.dsi.big.webgraph.EFGraph
-
- All Implemented Interfaces:
it.unimi.dsi.lang.FlyweightPrototype<ImmutableGraph>
public class EFGraph extends ImmutableGraph
An immutable graph based on the Elias–Fano representation of monotone sequences.- Author:
- Sebastiano Vigna
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classEFGraph.Accumulatorprotected static classEFGraph.EliasFanoSuccessorReaderprotected static classEFGraph.LongWordBitReaderprotected static classEFGraph.LongWordCachestatic classEFGraph.LongWordOutputBitStream-
Nested classes/interfaces inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
ImmutableGraph.LoadMethod
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.CharSequencebasenameThe basename of this graph (or possiblynull).protected longcachedNodeIf notLong.MIN_VALUE, the node whose degree is cached incachedOutdegree.protected longcachedOutdegreeIfcachedNodeis notLong.MIN_VALUE, its cached outdegree.protected longcachedPointerIfcachedNodeis notLong.MIN_VALUE, the position immediately after the coding of the outdegree ofcachedNode.static intDEFAULT_CACHE_SIZEThe default size of the bit cache.static intDEFAULT_LOG_2_QUANTUMThe default base-two logarithm of the quantum.static intEFGRAPH_VERSIONThis number classifies the present graph format.protected it.unimi.dsi.fastutil.longs.LongBigListgraphThe list containing the graph.static java.lang.StringGRAPH_EXTENSIONThe standard extension for the graph longword bit stream.protected intlog2QuantumThe base-two logarithm of the indexing quantum.protected longmThe number of arcs of the graph.protected longnThe number of nodes of the graph.protected it.unimi.dsi.fastutil.longs.LongBigListoffsetsAn Elias–Fano monotone list containing the pointers of the bit streams stored ingraph.static java.lang.StringOFFSETS_BIG_LIST_EXTENSIONThe standard extension for the cachedLongBigListcontaining the graph offsets.static java.lang.StringOFFSETS_EXTENSIONThe standard extension for the graph-offsets bit stream.protected EFGraph.LongWordBitReaderoutdegreeLongWordBitReaderA longword bit reader used to read outdegrees.protected longupperBoundThe upper bound used during the graph construction (greater than or equal ton.-
Fields inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
GRAPHCLASS_PROPERTY_KEY, NUMBER_OF_THREADS_PROPERTY, PROPERTIES_EXTENSION
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedEFGraph(java.lang.CharSequence basename, long n, long m, long upperBound, int log2Quantum, it.unimi.dsi.fastutil.longs.LongBigList graph, it.unimi.dsi.fastutil.longs.LongBigList offsets)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.CharSequencebasename()Returns a symbolic basename for this graph (optional operation).EFGraphcopy()Returns a flyweight copy of this immutable graph.static EFGraphload(java.lang.CharSequence basename)Creates a newEFGraphby loading a compressed graph file from disk to memory, with no progress logger and all offsets.static EFGraphload(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl)Creates a newEFGraphby loading a compressed graph file from disk to memory, with all offsets.protected static EFGraphloadInternal(java.lang.CharSequence basename, boolean mapped, it.unimi.dsi.logging.ProgressLogger pl)Loads a compressed graph file from disk into this graph.static it.unimi.dsi.fastutil.longs.LongBigArrayBigListloadLongBigList(java.lang.CharSequence filename, java.nio.ByteOrder byteOrder)Commodity method for loading a big list of binary longs with specified endianness into a long big array which just delegates toEFGraph.loadLongBigList(CharSequence, ByteOrder).static EFGraphloadMapped(java.lang.CharSequence basename)Creates a newEFGraphby memory-mapping a graph file.static EFGraphloadMapped(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl)Creates a newEFGraphby memory-mapping a graph file.static EFGraphloadOffline(java.lang.CharSequence basename)Creates a newEFGraphby loading just the metadata of a compressed graph file.static EFGraphloadOffline(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl)Creates a newEFGraphby loading just the metadata of a compressed graph file.static EFGraphloadSequential(java.lang.CharSequence basename)Deprecated.UseloadOffline(CharSequence)orloadMapped(CharSequence)instead.static EFGraphloadSequential(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl)Deprecated.static intlowerBits(long length, long upperBound)Returns the number of lower bits for the Elias–Fano encoding of a list of given length, upper bound and strictness.static voidmain(java.lang.String[] args)longnumArcs()Returns the number of arcs of this graph (optional operation).static longnumberOfPointers(long length, long upperBound, int log2Quantum)Returns the number of forward or skip pointers to the Elias–Fano encoding of a list of given length, upper bound and strictness.longnumNodes()Returns the number of nodes of this graph.longoutdegree(long x)Returns the outdegree of a node.static intpointerSize(long length, long upperBound)Returns the size in bits of forward or skip pointers to the Elias–Fano encoding of a list of given length, upper bound and strictness.booleanrandomAccess()Checks whether this graph provides random access to successor lists.static voidstore(ImmutableGraph graph, long upperBound, java.lang.CharSequence basename, int log2Quantum, int cacheSize, java.nio.ByteOrder byteOrder, it.unimi.dsi.logging.ProgressLogger pl)static voidstore(ImmutableGraph graph, long upperBound, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl)static voidstore(ImmutableGraph graph, java.lang.CharSequence basename)static voidstore(ImmutableGraph graph, java.lang.CharSequence basename, int log2Quantum, int cacheSize, java.nio.ByteOrder byteOrder, it.unimi.dsi.logging.ProgressLogger pl)static voidstore(ImmutableGraph graph, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl)LazyLongSkippableIteratorsuccessors(long x)Returns a lazy iterator over the successors of a given node.-
Methods inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
equals, hasCopiableIterators, hashCode, intNumNodes, load, loadOnce, nodeIterator, nodeIterator, outdegrees, splitNodeIterators, store, store, successorBigArray, toString, wrap, wrap
-
-
-
-
Field Detail
-
GRAPH_EXTENSION
public static final java.lang.String GRAPH_EXTENSION
The standard extension for the graph longword bit stream.- See Also:
- Constant Field Values
-
OFFSETS_EXTENSION
public static final java.lang.String OFFSETS_EXTENSION
The standard extension for the graph-offsets bit stream.- See Also:
- Constant Field Values
-
OFFSETS_BIG_LIST_EXTENSION
public static final java.lang.String OFFSETS_BIG_LIST_EXTENSION
The standard extension for the cachedLongBigListcontaining the graph offsets.- See Also:
- Constant Field Values
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZE
The default size of the bit cache.- See Also:
- Constant Field Values
-
EFGRAPH_VERSION
public static final int EFGRAPH_VERSION
This number classifies the present graph format. When new features require introducing binary incompatibilities, this number is bumped so to ensure that old classes do not try to read graphs they cannot understand.- See Also:
- Constant Field Values
-
DEFAULT_LOG_2_QUANTUM
public static final int DEFAULT_LOG_2_QUANTUM
The default base-two logarithm of the quantum.- See Also:
- Constant Field Values
-
n
protected final long n
The number of nodes of the graph.
-
upperBound
protected final long upperBound
The upper bound used during the graph construction (greater than or equal ton.
-
m
protected final long m
The number of arcs of the graph.
-
graph
protected final it.unimi.dsi.fastutil.longs.LongBigList graph
The list containing the graph.
-
offsets
protected final it.unimi.dsi.fastutil.longs.LongBigList offsets
An Elias–Fano monotone list containing the pointers of the bit streams stored ingraph.
-
basename
protected final java.lang.CharSequence basename
The basename of this graph (or possiblynull).
-
outdegreeLongWordBitReader
protected final EFGraph.LongWordBitReader outdegreeLongWordBitReader
A longword bit reader used to read outdegrees.
-
log2Quantum
protected final int log2Quantum
The base-two logarithm of the indexing quantum.
-
cachedNode
protected long cachedNode
If notLong.MIN_VALUE, the node whose degree is cached incachedOutdegree.
-
cachedOutdegree
protected long cachedOutdegree
IfcachedNodeis notLong.MIN_VALUE, its cached outdegree.
-
cachedPointer
protected long cachedPointer
IfcachedNodeis notLong.MIN_VALUE, the position immediately after the coding of the outdegree ofcachedNode.
-
-
Method Detail
-
basename
public java.lang.CharSequence basename()
Description copied from class:ImmutableGraphReturns 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:
basenamein classImmutableGraph- Returns:
- the basename.
-
lowerBits
public static int lowerBits(long length, long upperBound)Returns the number of lower bits for the Elias–Fano encoding of a list of given length, upper bound and strictness.- Parameters:
length- the number of elements of the list.upperBound- an upper bound for the elements of the list.- Returns:
- the number of bits for the Elias–Fano encoding of a list with the specified parameters.
-
pointerSize
public static int pointerSize(long length, long upperBound)Returns the size in bits of forward or skip pointers to the Elias–Fano encoding of a list of given length, upper bound and strictness.- Parameters:
length- the number of elements of the list.upperBound- an upper bound for the elements of the list.- Returns:
- the size of bits of forward or skip pointers the Elias–Fano encoding of a list with the specified parameters.
-
numberOfPointers
public static long numberOfPointers(long length, long upperBound, int log2Quantum)Returns the number of forward or skip pointers to the Elias–Fano encoding of a list of given length, upper bound and strictness.- Parameters:
length- the number of elements of the list.upperBound- an upper bound for the elements of the list.log2Quantum- the logarithm of the quantum size.- Returns:
- an upper bound on the number of skip pointers or the (exact) number of forward pointers.
-
load
public static EFGraph load(java.lang.CharSequence basename) throws java.io.IOException
Creates a newEFGraphby loading a compressed graph file from disk to memory, with no progress logger and all offsets.- Parameters:
basename- the basename of the graph.- Returns:
- a
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while reading the graph.
-
load
public static EFGraph load(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
Creates a newEFGraphby loading a compressed graph file from disk to memory, with all offsets.- Parameters:
basename- the basename of the graph.pl- a progress logger used while loading the graph, ornull.- Returns:
- a
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while reading the graph.
-
loadMapped
public static EFGraph loadMapped(java.lang.CharSequence basename) throws java.io.IOException
Creates a newEFGraphby memory-mapping a graph file.- Parameters:
basename- the basename of the graph.- Returns:
- an
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while memory-mapping the graph or reading the offsets.
-
loadMapped
public static EFGraph loadMapped(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
Creates a newEFGraphby memory-mapping a graph file.- Parameters:
basename- the basename of the graph.pl- a progress logger used while loading the offsets, ornull.- Returns:
- an
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while memory-mapping the graph or reading the offsets.
-
loadSequential
@Deprecated public static EFGraph loadSequential(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
Deprecated.Creates a newEFGraphby loading a compressed graph file from disk to memory, without offsets.- Parameters:
basename- the basename of the graph.pl- a progress logger used while loading the graph, ornull.- Returns:
- a
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while reading the graph.
-
loadSequential
@Deprecated public static EFGraph loadSequential(java.lang.CharSequence basename) throws java.io.IOException
Deprecated.UseloadOffline(CharSequence)orloadMapped(CharSequence)instead.Creates a newEFGraphby loading a compressed graph file from disk to memory, with no progress logger and without offsets.- Parameters:
basename- the basename of the graph.- Returns:
- a
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while reading the graph.
-
loadOffline
public static EFGraph loadOffline(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
Creates a newEFGraphby loading just the metadata of a compressed graph file.- Parameters:
basename- the basename of the graph.pl- a progress logger, ornull.- Returns:
- a
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while reading the metadata.
-
loadOffline
public static EFGraph loadOffline(java.lang.CharSequence basename) throws java.io.IOException
Creates a newEFGraphby loading just the metadata of a compressed graph file.- Parameters:
basename- the basename of the graph.- Returns:
- a
EFGraphcontaining the specified graph. - Throws:
java.io.IOException- if an I/O exception occurs while reading the metadata.
-
loadLongBigList
public static it.unimi.dsi.fastutil.longs.LongBigArrayBigList loadLongBigList(java.lang.CharSequence filename, java.nio.ByteOrder byteOrder) throws java.io.IOExceptionCommodity method for loading a big list of binary longs with specified endianness into a long big array which just delegates toEFGraph.loadLongBigList(CharSequence, ByteOrder).- Parameters:
filename- the file containing the longs.byteOrder- the endianness of the longs.- Returns:
- a big list of longs containing the longs in
filename. - Throws:
java.io.IOException
-
loadInternal
protected static EFGraph loadInternal(java.lang.CharSequence basename, boolean mapped, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
Loads a compressed graph file from disk into this graph. Note that this method should be called only on a newly created graph.- Parameters:
basename- the basename of the graph.mapped- whether we want to memory-map the file.pl- a progress logger used while loading the graph, ornull.- Returns:
- this graph.
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, long upperBound, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger pl) 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, java.lang.CharSequence basename, int log2Quantum, int cacheSize, java.nio.ByteOrder byteOrder, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, long upperBound, java.lang.CharSequence basename, int log2Quantum, int cacheSize, java.nio.ByteOrder byteOrder, it.unimi.dsi.logging.ProgressLogger pl) throws java.io.IOException
- Throws:
java.io.IOException
-
numNodes
public long 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.
-
numArcs
public long numArcs()
Description copied from class:ImmutableGraphReturns the number of arcs of this graph (optional operation).- Overrides:
numArcsin classImmutableGraph- Returns:
- the number of arcs.
-
randomAccess
public boolean randomAccess()
Description copied from class:ImmutableGraphChecks whether this graph provides random access to successor lists.- Specified by:
randomAccessin classImmutableGraph- Returns:
- true if this graph provides random access to successor lists.
-
outdegree
public long outdegree(long x)
Description copied from class:ImmutableGraphReturns the outdegree of a node.- Specified by:
outdegreein classImmutableGraph- Parameters:
x- a node.- Returns:
- the outdegree of the given node.
-
successors
public LazyLongSkippableIterator successors(long x)
Description copied from class:ImmutableGraphReturns a lazy iterator over the successors of a given node. The iteration terminates when -1 is returned.- Overrides:
successorsin classImmutableGraph- Parameters:
x- a node.- Returns:
- a lazy iterator over the successors of the node.
-
copy
public EFGraph copy()
Description copied from class:ImmutableGraphReturns a flyweight copy of this immutable graph.- Specified by:
copyin interfaceit.unimi.dsi.lang.FlyweightPrototype<ImmutableGraph>- Specified by:
copyin classImmutableGraph- Returns:
- a flyweight copy of this immutable graph.
- See Also:
FlyweightPrototype
-
main
public static void main(java.lang.String[] args) throws 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.SecurityExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.NoSuchMethodExceptionjava.io.IOExceptioncom.martiansoftware.jsap.JSAPExceptionjava.lang.ClassNotFoundExceptionjava.lang.InstantiationException
-
-