Class EliasFanoMonotoneLongBigList
- All Implemented Interfaces:
it.unimi.dsi.fastutil.BigList<Long>, it.unimi.dsi.fastutil.longs.LongBigList, it.unimi.dsi.fastutil.longs.LongCollection, it.unimi.dsi.fastutil.longs.LongIterable, it.unimi.dsi.fastutil.longs.LongStack, it.unimi.dsi.fastutil.Size64, it.unimi.dsi.fastutil.Stack<Long>, Serializable, Comparable<it.unimi.dsi.fastutil.BigList<? extends Long>>, Iterable<Long>, Collection<Long>
- Direct Known Subclasses:
EliasFanoIndexedMonotoneLongBigList, EliasFanoPrefixSumLongBigList, SparseSelect
Instances of this class represent in a highly compacted form a nondecreasing sequence of natural numbers. Instances are built by providing either an iterator returning the (nondecreasing) sequence, or an iterable object that provides such an iterator. In the first case, you must also provide in advance the number of elements that will be returned and an upper bound to their values (see below), and at the end of the construction the iterator will be exhausted.
An additional bulk method makes it possible to extract
several consecutive entries at high speed, and getDelta(long) computes directly the
difference between two consecutive elements. Moreover, the
nextLong() method of an
iterator will read read consecutive data much faster than
repeated calls to getLong(long).
Methods to not usually perform bound checks on the arguments. Bounds checks can be enabled, however, by enabling assertions.
Because Java array are limited in size, it might not be possible to build certain instances: you
can use the fits(long, long) methods to check is this might happen. In this case, please
use EliasFanoMonotoneBigLongBigList, which is slightly slower but has no such
limitations.
This class is thread safe.
Memory mapping
Instances of this class can be dumped and then loaded uses
MappedEliasFanoMonotoneLongBigList.
Implementation details
Given a monotone sequence 0 ≤ x0 ≤ x1 ≤ … ≤ xn − 1 < u, where u is a given upper bound (the size of the universe), the Elias–Fano representation makes it possible to store it using at most 2 + log(u/n) bits per element, which is very close to the information-theoretical lower bound ≈ log e + log(u/n). A typical example is a list of pointer into records of a large file: instead of using, for each pointer, a number of bit sufficient to express the length of the file, the Elias–Fano representation makes it possible to use, for each pointer, a number of bits roughly equal to the logarithm of the average length of a record. The representation was introduced in Peter Elias, “Efficient storage and retrieval by content and address of static files”, J. Assoc. Comput. Mach., 21(2):246−260, 1974, and also independently by Robert Fano, “On the number of bits required to implement an associative memory”, Memorandum 61, Computer Structures Group, Project MAC, MIT, Cambridge, Mass., n.d., 1971.
The elements of the sequence are recorded by storing separately the lower s = ⌊log(u/n)⌋ bits and the remaining upper bits. The lower bits are stored contiguously, whereas the upper bits are stored in an array of n + u / 2s bits by setting, for each 0 ≤ i < n, the bit of index xi / 2s + i; the value can then be recovered by selecting the i-th bit of the resulting bit array and subtracting i (note that this will work because the upper bits are nondecreasing).
This implementation uses SimpleSelect to support selection inside the upper-bits array,
and exploits SimpleSelect.select(long, long[], int, int) to implement
get(long, long[], int, int).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA list iterator over the values of thisEliasFanoMonotoneLongBigList.Nested classes/interfaces inherited from class it.unimi.dsi.fastutil.longs.AbstractLongBigList
it.unimi.dsi.fastutil.longs.AbstractLongBigList.LongRandomAccessSubList, it.unimi.dsi.fastutil.longs.AbstractLongBigList.LongSubList -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intThe number of lower bits.protected final longThe length of the sequence.protected long[]The list of lower bits of each element, stored explicitly.protected final longThe mask for the lower bits.protected final SimpleSelectThe select structure used to extract the upper bits.protected long[]The upper bits, stored as unary gaps. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEliasFanoMonotoneLongBigList(long[] a, it.unimi.dsi.fastutil.longs.LongIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.protectedEliasFanoMonotoneLongBigList(long length, int l, long[] upperBits, long[] lowerBits, SimpleSelect selectUpper) EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.bytes.ByteIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.ints.IntIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.longs.LongIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.shorts.ShortIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.bytes.ByteIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object.EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.ints.IntIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object.EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.longs.LongIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object.EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.shorts.ShortIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object. -
Method Summary
Modifier and TypeMethodDescriptionvoidDumps this list's lower bits in native order so that it can be used withMappedEliasFanoMonotoneLongBigList.voidDumps this list's lower bits so that it can be used withMappedEliasFanoMonotoneLongBigList.static booleanfits(long length, long upperBound) Returns true if this class can accommodate a list with the given number of elements and upper bound.long[]get(long index, long[] dest) Extracts a number of consecutive entries into a given array.long[]get(long index, long[] dest, int offset, int length) Extracts a number of consecutive entries into a given array fragment.longgetDelta(long index) Returns the difference between two consecutive elements of the sequence.longgetLong(long index) Returns the element at the specified position.iterator()Returns a list iterator over the values of thisEliasFanoMonotoneLongBigList.Returns a list iterator over the values of thisEliasFanoMonotoneLongBigList.listIterator(long from) Returns a list iterator over the values of thisEliasFanoMonotoneLongBigList.longnumBits()longsize64()Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongBigList
add, add, add, addAll, addAll, addAll, addAll, addElements, addElements, clear, compareTo, contains, ensureIndex, ensureRestrictedIndex, equals, forEach, get, getElements, hashCode, indexOf, indexOf, lastIndexOf, lastIndexOf, peek, peekLong, pop, popLong, push, push, rem, remove, removeElements, removeLong, set, set, setElements, size, size, subList, top, topLong, toStringMethods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongCollection
add, contains, containsAll, containsAll, forEach, remove, removeAll, removeAll, removeIf, retainAll, retainAll, toArray, toLongArray, toLongArrayMethods inherited from class AbstractCollection
isEmpty, toArray, toArrayMethods inherited from interface Collection
containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toArrayMethods inherited from interface it.unimi.dsi.fastutil.longs.LongBigList
addAll, addAll, addAll, addAll, getElements, setElements, setElements, spliteratorMethods inherited from interface it.unimi.dsi.fastutil.longs.LongCollection
add, contains, containsAll, longIterator, longParallelStream, longSpliterator, longStream, parallelStream, remove, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toArray, toLongArray, toLongArrayMethods inherited from interface it.unimi.dsi.fastutil.longs.LongIterable
forEach, forEachMethods inherited from interface it.unimi.dsi.fastutil.Stack
isEmpty
-
Field Details
-
length
protected final long lengthThe length of the sequence. -
l
protected final int lThe number of lower bits. -
upperBits
protected transient long[] upperBitsThe upper bits, stored as unary gaps. -
lowerBits
protected long[] lowerBitsThe list of lower bits of each element, stored explicitly. -
selectUpper
The select structure used to extract the upper bits. -
lowerBitsMask
protected final long lowerBitsMaskThe mask for the lower bits.
-
-
Constructor Details
-
EliasFanoMonotoneLongBigList
protected EliasFanoMonotoneLongBigList(long length, int l, long[] upperBits, long[] lowerBits, SimpleSelect selectUpper) -
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.ints.IntIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list- an iterable object returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.shorts.ShortIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list- an iterable object returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.bytes.ByteIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list- an iterable object returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(it.unimi.dsi.fastutil.longs.LongIterable list) Creates an Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list- an iterable object returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.bytes.ByteIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.This constructor is particularly useful if the elements of the iterator are provided by some sequential source.
- Parameters:
n- the number of elements returned byiterator.upperBound- a strict upper bound to the values returned byiterator(note that it used to be non-strict).iterator- an iterator returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.shorts.ShortIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.This constructor is particularly useful if the elements of the iterator are provided by some sequential source.
- Parameters:
n- the number of elements returned byiterator.upperBound- a strict upper bound to the values returned byiterator(note that it used to be non-strict).iterator- an iterator returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.ints.IntIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.This constructor is particularly useful if the elements of the iterator are provided by some sequential source.
- Parameters:
n- the number of elements returned byiterator.upperBound- a strict upper bound to the values returned byiterator(note that it used to be non-strict).iterator- an iterator returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
public EliasFanoMonotoneLongBigList(long n, long upperBound, it.unimi.dsi.fastutil.longs.LongIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.This constructor is particularly useful if the elements of the iterator are provided by some sequential source.
- Parameters:
n- the number of elements returned byiterator.upperBound- a strict upper bound to the values returned byiterator(note that it used to be non-strict).iterator- an iterator returning nondecreasing natural numbers.
-
EliasFanoMonotoneLongBigList
protected EliasFanoMonotoneLongBigList(long[] a, it.unimi.dsi.fastutil.longs.LongIterator iterator) Creates an Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.This constructor is used only internally, to work around the usual problems caused by the obligation to call
this()before anything else.- Parameters:
a- an array containing the number of elements returned byiteratorand a strict upper bound to the values returned byiterator(note that it used to be non-strict).iterator- an iterator returning nondecreasing natural numbers.
-
-
Method Details
-
fits
public static boolean fits(long length, long upperBound) Returns true if this class can accommodate a list with the given number of elements and upper bound.- Parameters:
length- the length of the list.upperBound- a strict upper bound to the values of the list.- Returns:
- true if this class can accommodate a list with the given number of elements and upper bound.
-
numBits
public long numBits() -
getLong
public long getLong(long index) Returns the element at the specified position.- Specified by:
getLongin interfaceit.unimi.dsi.fastutil.longs.LongBigList- Parameters:
index- a position in the list.- Returns:
- the element at the specified position; if
indexis out of bounds, behavior is undefined.
-
getDelta
public long getDelta(long index) Returns the difference between two consecutive elements of the sequence.- Parameters:
index- the index of an element (smaller thensize64()- 1).- Returns:
- the difference between the element of position
index + 1and that of positionindex; ifindexis out of bounds, behavior is undefined. - See Also:
-
get
public long[] get(long index, long[] dest, int offset, int length) Extracts a number of consecutive entries into a given array fragment.- Parameters:
index- the index of the first entry returned.dest- the destination array; it will be filled withlengthconsecutive entries starting at positionoffset; must be of length greater thanoffset.offset- the first position written indest.length- the number of elements written indeststarting atoffset.- Returns:
dest; if the arguments are out of bounds, behavior is undefined.- See Also:
-
get
public long[] get(long index, long[] dest) Extracts a number of consecutive entries into a given array.- Parameters:
index- the index of the first entry returned.dest- the destination array, of nonzero length; it will be filled with consecutive entries.- Returns:
dest; ifindexis out of bounds ordesthas length zero, behavior is undefined.- See Also:
-
listIterator
Returns a list iterator over the values of thisEliasFanoMonotoneLongBigList.Forward iteration will be faster than iterated calls to
getLong(). Backward iteration is available, but it will perform similarly togetLong().- Specified by:
listIteratorin interfaceit.unimi.dsi.fastutil.BigList<Long>- Specified by:
listIteratorin interfaceit.unimi.dsi.fastutil.longs.LongBigList- Overrides:
listIteratorin classit.unimi.dsi.fastutil.longs.AbstractLongBigList- Parameters:
from- the starting position in the sequence.- Returns:
- a list iterator over the values of this
EliasFanoMonotoneLongBigList. - See Also:
-
listIterator
Returns a list iterator over the values of thisEliasFanoMonotoneLongBigList.Forward iteration will be faster than iterated calls to
getLong(). Backward iteration is available, but it will perform similarly togetLong().- Specified by:
listIteratorin interfaceit.unimi.dsi.fastutil.BigList<Long>- Specified by:
listIteratorin interfaceit.unimi.dsi.fastutil.longs.LongBigList- Overrides:
listIteratorin classit.unimi.dsi.fastutil.longs.AbstractLongBigList- Returns:
- a list iterator over the values of this
EliasFanoMonotoneLongBigList. - See Also:
-
iterator
Returns a list iterator over the values of thisEliasFanoMonotoneLongBigList.Forward iteration will be faster than iterated calls to
getLong(). Backward iteration is available, but it will perform similarly togetLong().- Specified by:
iteratorin interfaceCollection<Long>- Specified by:
iteratorin interfaceIterable<Long>- Specified by:
iteratorin interfaceit.unimi.dsi.fastutil.longs.LongBigList- Specified by:
iteratorin interfaceit.unimi.dsi.fastutil.longs.LongCollection- Specified by:
iteratorin interfaceit.unimi.dsi.fastutil.longs.LongIterable- Overrides:
iteratorin classit.unimi.dsi.fastutil.longs.AbstractLongBigList- Returns:
- a list iterator over the values of this
EliasFanoMonotoneLongBigList. - See Also:
-
size64
public long size64()- Specified by:
size64in interfaceit.unimi.dsi.fastutil.Size64
-
dump
Dumps this list's lower bits in native order so that it can be used withMappedEliasFanoMonotoneLongBigList.- Parameters:
basename- the basename of the generated files.- Throws:
IOException
-
dump
Dumps this list's lower bits so that it can be used withMappedEliasFanoMonotoneLongBigList.Two files will be generated: a serialized object with extension
MappedEliasFanoMonotoneLongBigList.OBJECT_EXTENSIONand a list of longs in the specified byte order with extensionMappedEliasFanoMonotoneLongBigList.LOWER_BITS_EXTENSION.- Parameters:
basename- the basename of the generated files.byteOrder- the desired byte order.- Throws:
IOException
-