Class EliasFanoIndexedMonotoneLongBigList
- All Implemented Interfaces:
BigList<Long>
,LongBigList
,LongCollection
,LongIterable
,LongStack
,Size64
,Stack<Long>
,Serializable
,Comparable<BigList<? extends Long>>
,Iterable<Long>
,Collection<Long>
EliasFanoMonotoneLongBigList
providing indexing (i.e., content-based
addressing).
This implementation uses a SimpleSelectZero
structure to support zero-selection inside
the upper-bits array, which makes it possible to implement fast content-addressed based access
methods such as successor(long)
, strictSuccessor(long)
,
predecessor(long)
, weakPredecessor(long)
, contains(long)
and
indexOf(long)
.
Beside standard interface methods, additional unsafe methods such as
successorUnsafe(long)
have restricted argument ranges and skip bounds check for maximum
performance. Bounds checks are performed even for these methods, however, when assertions are
enabled.
This class is thread safe as long as you do not use index()
, as its value depend on an
internal variable that caches the result of successor(long)
,
successorUnsafe(long)
, strictSuccessor(long)
,
strictSuccessorUnsafe(long)
, predecessor(long)
,
predecessorUnsafe(long)
, weakPredecessor(long)
, and
weakPredecessorUnsafe(long)
. Usually it is possible to work around the issue using the
alternative methods successorIndex(long)
, successorIndexUnsafe(long)
,
strictSuccessorIndex(long)
, strictSuccessorIndexUnsafe(long)
,
predecessorIndex(long)
, predecessorIndexUnsafe(long)
,
weakPredecessorIndex(long)
, and weakPredecessorIndexUnsafe(long)
.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionfinal class
An list iterator over the values of thisEliasFanoIndexedMonotoneLongBigList
Nested classes/interfaces inherited from class it.unimi.dsi.sux4j.util.EliasFanoMonotoneLongBigList
EliasFanoMonotoneLongBigList.EliasFanoMonotoneLongBigListIterator
Nested classes/interfaces inherited from class it.unimi.dsi.fastutil.longs.AbstractLongBigList
AbstractLongBigList.LongRandomAccessSubList, AbstractLongBigList.LongSubList
-
Field Summary
Modifier and TypeFieldDescriptionprotected final SimpleSelectZero
The select structure used to extract the upper bits.Fields inherited from class it.unimi.dsi.sux4j.util.EliasFanoMonotoneLongBigList
l, length, lowerBits, lowerBitsMask, selectUpper, upperBits
-
Constructor Summary
ConstructorDescriptionEliasFanoIndexedMonotoneLongBigList
(long n, long upperBound, ByteIterator iterator) Creates an indexed Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.EliasFanoIndexedMonotoneLongBigList
(long n, long upperBound, IntIterator iterator) Creates an indexed Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.EliasFanoIndexedMonotoneLongBigList
(long n, long upperBound, LongIterator iterator) Creates an indexed Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.EliasFanoIndexedMonotoneLongBigList
(long n, long upperBound, ShortIterator iterator) Creates an indexed Elias–Fano representation of the values returned by an iterator, given that the overall number of elements and an upper bound are provided, too.Creates an indexed Elias–Fano representation of the values returned by the given iterable object.Creates an indexed Elias–Fano representation of the values returned by the given iterable object.Creates an indexed Elias–Fano representation of the values returned by the given iterable object.Creates an indexed Elias–Fano representation of the values returned by the given iterable object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(long x) Returns true if the sequence contains the specified element.long
index()
Returns the index realizing the last value returned bysuccessor(long)
,successorUnsafe(long)
,strictSuccessor(long)
,strictSuccessorUnsafe(long)
,predecessor(long)
,predecessorUnsafe(long)
,weakPredecessor(long)
, andweakPredecessorUnsafe(long)
.long
indexOf
(long x) Returns the index of the first occurrence of the specified element in the sequence, or −1 if the element does not belong to the sequence.long
indexOfUnsafe
(long x) Returns the index of the first occurrence of the specified element in the sequence, or −1 if the element does not belong to the sequence.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
.long
predecessor
(long upperBound) Returns the last element of the sequence that is less than the provided bound.long
predecessorIndex
(long upperBound) Returns the index of the last element of the sequence that is less than the provided bound.long
predecessorIndexUnsafe
(long upperBound) Returns the index of the last element of the sequence that is less than the provided bound.long
predecessorUnsafe
(long upperBound) Returns the last element of the sequence that is less than the provided bound.long
strictSuccessor
(long lowerBound) Returns the first element of the sequence that is greater than the provided bound.long
strictSuccessorIndex
(long lowerBound) Returns the index of first element of the sequence that is greater than the provided bound.long
strictSuccessorIndexUnsafe
(long lowerBound) Returns the index of first element of the sequence that is greater than the provided bound.long
strictSuccessorUnsafe
(long lowerBound) Returns the first element of the sequence that is greater than the provided bound.long
successor
(long lowerBound) Returns the first element of the sequence that is greater than or equal to the provided bound.long
successorIndex
(long lowerBound) Returns the index of first element of the sequence that is greater than or equal to the provided bound.long
successorIndexUnsafe
(long lowerBound) Returns the index of first element of the sequence that is greater than or equal to the provided bound.long
successorUnsafe
(long lowerBound) Returns the first element of the sequence that is greater than or equal to the provided bound.long
weakPredecessor
(long upperBound) Returns the last element of the sequence that is less than or equal to the provided bound.long
weakPredecessorIndex
(long upperBound) Returns the index of the last element of the sequence that is less than or equal to the provided bound.long
weakPredecessorIndexUnsafe
(long upperBound) Returns the index of the last element of the sequence that is less than or equal to the provided bound.long
weakPredecessorUnsafe
(long upperBound) Returns the last element of the sequence that is less than or equal to the provided bound.Methods inherited from class it.unimi.dsi.sux4j.util.EliasFanoMonotoneLongBigList
dump, dump, fits, get, get, getDelta, getLong, numBits, size64
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongBigList
add, add, add, addAll, addAll, addAll, addAll, addElements, addElements, clear, compareTo, ensureIndex, ensureRestrictedIndex, equals, forEach, get, getElements, hashCode, indexOf, lastIndexOf, lastIndexOf, peek, peekLong, pop, popLong, push, push, rem, remove, removeElements, removeLong, set, set, setElements, size, size, subList, top, topLong, toString
Methods inherited from class it.unimi.dsi.fastutil.longs.AbstractLongCollection
add, contains, containsAll, containsAll, forEach, remove, removeAll, removeAll, removeIf, retainAll, retainAll, toArray, toLongArray, toLongArray
Methods inherited from class java.util.AbstractCollection
isEmpty, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toArray
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongBigList
addAll, addAll, addAll, addAll, getElements, setElements, setElements, spliterator
Methods 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, toLongArray
Methods inherited from interface it.unimi.dsi.fastutil.longs.LongIterable
forEach, forEach
-
Field Details
-
selectUpperZero
The select structure used to extract the upper bits.
-
-
Constructor Details
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list
- an iterable object returning nondecreasing natural numbers.
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list
- an iterable object returning nondecreasing natural numbers.
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list
- an iterable object returning nondecreasing natural numbers.
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed Elias–Fano representation of the values returned by the given iterable object.- Parameters:
list
- an iterable object returning nondecreasing natural numbers.
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed 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
- an upper bound to the values returned byiterator
.iterator
- an iterator returning nondecreasing natural numbers.
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed 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
- an upper bound to the values returned byiterator
.iterator
- an iterator returning nondecreasing natural numbers.
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed 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
- an upper bound to the values returned byiterator
.iterator
- an iterator returning nondecreasing natural numbers.
-
EliasFanoIndexedMonotoneLongBigList
Creates an indexed 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
- an upper bound to the values returned byiterator
.iterator
- an iterator returning nondecreasing natural numbers.
-
-
Method Details
-
successor
public long successor(long lowerBound) Returns the first element of the sequence that is greater than or equal to the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.- Parameters:
lowerBound
- a lower bound on the returned value.- Returns:
- the first element of the sequence that is greater than or equal to
lowerBound
, orLong.MAX_VALUE
if no such element exists, in which caseindex()
will return the list length. - See Also:
-
successorUnsafe
public long successorUnsafe(long lowerBound) Returns the first element of the sequence that is greater than or equal to the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.This method is slightly faster than
successor(long)
, but it has a restricted argument range and it does perform bound checks.- Parameters:
lowerBound
- a nonnegative lower bound on the returned value; must be smaller than or equal to the upper bound provided at construction time.- Returns:
- the first element of the sequence that is greater than or equal to
lowerBound
; iflowerBound
is greater than the last element of the sequence, this method returns the upper bound provided at construction time andindex()
is set to the length of this list; iflowerBound
is out of bounds, behavior is undefined. - See Also:
-
successorIndex
public long successorIndex(long lowerBound) Returns the index of first element of the sequence that is greater than or equal to the provided bound.This method is significantly faster than
successor(long)
, as it does not have to compute the actual successor; moreover, it does not change the return value ofindex()
.- Parameters:
lowerBound
- a lower bound on the returned value.- Returns:
- the index of the first element of the sequence that is greater than or equal to
lowerBound
, or the length of this list if no such element exists. - See Also:
-
successorIndexUnsafe
public long successorIndexUnsafe(long lowerBound) Returns the index of first element of the sequence that is greater than or equal to the provided bound.This method is slightly faster than
successorIndexUnsafe(long)
, but it has a restricted argument range and it does perform bound checks.This method is significantly faster than
successorUnsafe(long)
, as it does not have to compute the actual successor; moreover, it does not change the return value ofindex()
.- Parameters:
lowerBound
- a nonnegative lower bound on the returned value; must be smaller than or equal to the upper bound provided at construction time.- Returns:
- the index of the first element of the sequence that is greater than or equal to
lowerBound
; iflowerBound
is greater than the last element of the sequence, this method the length of this list; iflowerBound
is out of bounds, behavior is undefined. - See Also:
-
strictSuccessor
public long strictSuccessor(long lowerBound) Returns the first element of the sequence that is greater than the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.If such an element exists, its position in the sequence can be retrieved using
index()
.- Parameters:
lowerBound
- a lower bound on the returned value.- Returns:
- the first element of the sequence that is greater than
lowerBound
, orLong.MAX_VALUE
if no such element exists, in which caseindex()
will return the list length. - See Also:
-
strictSuccessorUnsafe
public long strictSuccessorUnsafe(long lowerBound) Returns the first element of the sequence that is greater than the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.This method is slightly faster than
strictSuccessor(long)
, but it has a restricted argument range and it does perform bound checks.- Parameters:
lowerBound
- a nonnegative lower bound on the returned value; must be smaller than the upper bound provided at construction time.- Returns:
- the first element of the sequence that is greater than
lowerBound
, or the upper bound provided at construction timeif no such element exists; in that case,index()
is set to the length of the sequence; iflowerBound
is out of bounds, behavior is undefined. - See Also:
-
strictSuccessorIndex
public long strictSuccessorIndex(long lowerBound) Returns the index of first element of the sequence that is greater than the provided bound.This method is significantly faster than
strictSuccessor(long)
, as it does not have to compute the actual strict successor; moreover, it does not change the return value ofindex()
.- Parameters:
lowerBound
- a lower bound on the returned value.- Returns:
- the index of the first element of the sequence that is greater than
lowerBound
, or the length of the sequence if no such element exists. - See Also:
-
strictSuccessorIndexUnsafe
public long strictSuccessorIndexUnsafe(long lowerBound) Returns the index of first element of the sequence that is greater than the provided bound.This method is slightly faster than
strictSuccessorIndex(long)
, but it has a restricted argument range and it does perform bound checks.This method is significantly faster than
strictSuccessorUnsafe(long)
, as it does not have to compute the actual strict successor; moreover, it does not change the return value ofindex()
.- Parameters:
lowerBound
- a nonnegative lower bound on the returned value; must be smaller than the upper bound provided at construction time.- Returns:
- the index of first element of the sequence that is greater than
lowerBound
, or the length of the sequence if no such element exists; iflowerBound
is out of bounds, behavior is undefined. - See Also:
-
predecessor
public long predecessor(long upperBound) Returns the last element of the sequence that is less than the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.- Parameters:
upperBound
- a strict upper bound on the returned value.- Returns:
- the last element of the sequence that is less than
upperBound
, or −1 if no such element exists, in which caseindex()
will return −1. - See Also:
-
predecessorUnsafe
public long predecessorUnsafe(long upperBound) Returns the last element of the sequence that is less than the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.This method is slightly faster than
predecessor(long)
, but it has a restricted argument range and it does perform bound checks.- Parameters:
upperBound
- a nonnegative strict upper bound on the returned value, greater than the first element of the sequence and smaller than or equal to the upper bound provided at construction time.- Returns:
- the last element of the sequence that is less than
upperBound
; ifupperBound
is out of bounds, behavior is undefined. - See Also:
-
predecessorIndex
public long predecessorIndex(long upperBound) Returns the index of the last element of the sequence that is less than the provided bound.This method is significantly faster than
predecessor(long)
, as it does not have to compute the actual predecessor; moreover, it does not change the return value ofindex()
.- Parameters:
upperBound
- an upper bound on the returned value.- Returns:
- the index of the last element of the sequence that is less than
upperBound
, or −1 if no such element exists. - See Also:
-
predecessorIndexUnsafe
public long predecessorIndexUnsafe(long upperBound) Returns the index of the last element of the sequence that is less than the provided bound.This method is slightly faster than
predecessorIndex(long)
, but it has a restricted argument range and it does perform bound checks.This method is significantly faster than
predecessorUnsafe(long)
, as it does not have to compute the actual predecessor; moreover, it does not change the return value ofindex()
.- Parameters:
upperBound
- a nonnegative strict upper bound on the returned value, greater than the first element of the sequence and smaller than or equal to the upper bound provided at construction time.- Returns:
- the index of the last element of the sequence that is less than
upperBound
; ifupperBound
is out of bounds, behavior is undefined. - See Also:
-
weakPredecessor
public long weakPredecessor(long upperBound) Returns the last element of the sequence that is less than or equal to the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.- Parameters:
upperBound
- an upper bound on the returned value.- Returns:
- the last element of the sequence that is less than or equal to
upperBound
, orLong.MIN_VALUE
if no such element exists, in which caseindex()
will return −1. - See Also:
-
weakPredecessorUnsafe
public long weakPredecessorUnsafe(long upperBound) Returns the last element of the sequence that is less than or equal to the provided bound. If such an element exists, its position in the sequence can be retrieved usingindex()
.This method is slightly faster than
weakPredecessor(long)
, but it has a restricted argument range and it does perform bound checks.- Parameters:
upperBound
- a nonnegative strict upper bound on the returned value, greater than or equal to the first element of the sequence and smaller than the upper bound provided at construction time.- Returns:
- the last element of the sequence that is less than or equal to
upperBound
; ifupperBound
is out of bounds, behavior is undefined. - See Also:
-
weakPredecessorIndex
public long weakPredecessorIndex(long upperBound) Returns the index of the last element of the sequence that is less than or equal to the provided bound.This method is significantly faster than
weakPredecessor(long)
, as it does not have to compute the actual weak predecessor; moreover, it does not change the return value ofindex()
.- Parameters:
upperBound
- an upper bound on the returned value.- Returns:
- the index of the last element of the sequence that is less than or equal to
upperBound
, or −1 if no such element exists, in which caseindex()
will return −1. - See Also:
-
weakPredecessorIndexUnsafe
public long weakPredecessorIndexUnsafe(long upperBound) Returns the index of the last element of the sequence that is less than or equal to the provided bound.This method is slightly faster than
weakPredecessorIndex(long)
, but it has a restricted argument range and it does perform bound checks.This method is significantly faster than
weakPredecessorUnsafe(long)
, as it does not have to compute the actual weak predecessor; moreover, it does not change the return value ofindex()
.- Parameters:
upperBound
- a nonnegative strict upper bound on the returned value, greater than or equal to the first element of the sequence and smaller than the upper bound provided at construction time.- Returns:
- the index of the last element of the sequence that is less than or equal to
upperBound
; ifupperBound
is out of bounds, behavior is undefined. - See Also:
-
indexOf
public long indexOf(long x) Returns the index of the first occurrence of the specified element in the sequence, or −1 if the element does not belong to the sequence.This method does not change the value returned by
index()
.- Specified by:
indexOf
in interfaceLongBigList
- Overrides:
indexOf
in classAbstractLongBigList
- Parameters:
x
- a long.- Returns:
- the position of
x
in the sequence, or −1 ifx
does not belong to the sequence. - See Also:
-
indexOfUnsafe
public long indexOfUnsafe(long x) Returns the index of the first occurrence of the specified element in the sequence, or −1 if the element does not belong to the sequence.This method is slightly faster than
indexOf(long)
, but it has a restricted argument range and it does perform bound checks.- Parameters:
x
- a nonnegative long smaller than the upper bound provided at construction time.- Returns:
- the position of
x
in the sequence, or −1 ifx
does not belong to the sequence; ifx
is out of bounds, behavior is undefined. - See Also:
-
contains
public boolean contains(long x) Returns true if the sequence contains the specified element.This method does not change the value returned by
index()
. UseindexOf(long)
if you need to retrieve the position of an element.- Specified by:
contains
in interfaceLongCollection
- Overrides:
contains
in classAbstractLongBigList
- Parameters:
x
- a long.- Returns:
- true if the sequence contains
x
.
-
index
public long index()Returns the index realizing the last value returned bysuccessor(long)
,successorUnsafe(long)
,strictSuccessor(long)
,strictSuccessorUnsafe(long)
,predecessor(long)
,predecessorUnsafe(long)
,weakPredecessor(long)
, andweakPredecessorUnsafe(long)
.Usage of this method makes instances of this class not thread safe, as the return value is cached internally.
- Returns:
- the index of the element realizing the last value returned by
successor(long)
,successorUnsafe(long)
,strictSuccessor(long)
,strictSuccessorUnsafe(long)
,predecessor(long)
,predecessorUnsafe(long)
,weakPredecessor(long)
, andweakPredecessorUnsafe(long)
, or −1 if no such method has ever been called.
-
listIterator
public EliasFanoIndexedMonotoneLongBigList.EliasFanoIndexedMonotoneLongBigListIterator listIterator(long from) Description copied from class:EliasFanoMonotoneLongBigList
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:
listIterator
in interfaceBigList<Long>
- Specified by:
listIterator
in interfaceLongBigList
- Overrides:
listIterator
in classEliasFanoMonotoneLongBigList
- Parameters:
from
- the starting position in the sequence.- Returns:
- a list iterator over the values of this
EliasFanoMonotoneLongBigList
. - See Also:
-
listIterator
public EliasFanoIndexedMonotoneLongBigList.EliasFanoIndexedMonotoneLongBigListIterator listIterator()Description copied from class:EliasFanoMonotoneLongBigList
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:
listIterator
in interfaceBigList<Long>
- Specified by:
listIterator
in interfaceLongBigList
- Overrides:
listIterator
in classEliasFanoMonotoneLongBigList
- Returns:
- a list iterator over the values of this
EliasFanoMonotoneLongBigList
. - See Also:
-
iterator
Description copied from class:EliasFanoMonotoneLongBigList
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:
iterator
in interfaceCollection<Long>
- Specified by:
iterator
in interfaceIterable<Long>
- Specified by:
iterator
in interfaceLongBigList
- Specified by:
iterator
in interfaceLongCollection
- Specified by:
iterator
in interfaceLongIterable
- Overrides:
iterator
in classEliasFanoMonotoneLongBigList
- Returns:
- a list iterator over the values of this
EliasFanoMonotoneLongBigList
. - See Also:
-