Package org.apache.sis.math
Class PackedVector
java.lang.Object
- All Implemented Interfaces:
Serializable
,Iterable<Number>
,Collection<Number>
,List<Number>
,RandomAccess
,SequencedCollection<Number>
,CheckedContainer<Long>
A vector of integer values backed by an
IntegerList
.
This offers a compressed storage using only the minimal amount of bits per value.- Since:
- 0.8
- Version:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.math.ArrayVector
ArrayVector.Decimal, ArrayVector.Doubles
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IntegerList
The compressed list of integer values.private final long
(package private) static final int
Minimal length for creating a packed vector.private final long
The offset to add to thedata
in order to get the values to return.private static final long
For cross-version compatibility.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
PackedVector
(Vector source, long increment, long offset, int delta) Creates a new compressed vector initialized to a copy of the data provided by the given vector. -
Method Summary
Modifier and TypeMethodDescription(package private) static PackedVector
Creates a new compressed vector initialized to a copy of the data provided by the given vector.double
doubleValue
(int index) Returns the value at the given index as adouble
primitive type.boolean
Optimization ofequals(…)
method for the case where the other object is anotherPackedVector
.float
floatValue
(int index) Returns the value at the given index as afloat
primitive type.get
(int index) Returns the value at the given index wrapped in aLong
instance.Type of elements fixed toLong
even if the actual storage used by this class is more compact.boolean
Long values are not guaranteed to be convertible to single-precision floating point type.long
longValue
(int index) Returns the value at the given index as along
primitive type.Sets the value at the given index and returns the previous value.int
size()
Returns the number of elements in this vector.stringValue
(int index) Returns the string representation of the value at the given index.Methods inherited from class org.apache.sis.math.ArrayVector
compress, isNaN, newInstance, verifyType
Methods inherited from class org.apache.sis.math.Vector
backingVector, buffer, byteValue, compress, concatenate, copy, create, create, createConcatenate, createForDecimal, createSequence, createSequence, createSubSampling, createTransform, doubleValues, equals, fill, floatValues, hashCode, increment, indexOf, intValue, isEmptyOrNaN, isInteger, isUnsigned, pick, range, range, repeat, repetitions, reverse, shortValue, subList, subSampling, subtract, toBacking, toString, transform, warning
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
MINIMAL_SIZE
static final int MINIMAL_SIZEMinimal length for creating a packed vector. This is an arbitrary value that may change in any future version.- See Also:
-
data
The compressed list of integer values. This list can store values from 0 todelta
inclusive. -
increment
private final long increment -
offset
private final long offsetThe offset to add to thedata
in order to get the values to return.
-
-
Constructor Details
-
PackedVector
Creates a new compressed vector initialized to a copy of the data provided by the given vector.- Parameters:
source
- the vector to copy.increment
- the common divisor of all (sample minus offset) values.offset
- the minimal value in the source vector.delta
- the maximal value in the source vector minusoffset
divided byincrement
.
-
-
Method Details
-
compress
Creates a new compressed vector initialized to a copy of the data provided by the given vector. All values in the given vector shall be assignable to thelong
type (this is not verified).- Parameters:
source
- the vector to copy.min
- the minimal value in the given vector, inclusive.max
- the maximal value in the given vector, inclusive.- Returns:
- the compressed vector, or
null
if the vector cannot or should not be compressed.
-
getElementType
Type of elements fixed toLong
even if the actual storage used by this class is more compact. The reason for theLong
type is that this class can return any value in theLong
range, because of theoffset
.- Specified by:
getElementType
in interfaceCheckedContainer<Long>
- Specified by:
getElementType
in classVector
- Returns:
- the type of elements in this vector.
- See Also:
-
isSinglePrecision
public boolean isSinglePrecision()Long values are not guaranteed to be convertible to single-precision floating point type.- Overrides:
isSinglePrecision
in classVector
- Returns:
- whether values in this vector can be casted to
float
primitive type. - See Also:
-
size
public int size()Returns the number of elements in this vector. -
doubleValue
public double doubleValue(int index) Returns the value at the given index as adouble
primitive type.- Specified by:
doubleValue
in classVector
- Parameters:
index
- the index in the [0 … size-1] range.- Returns:
- the value at the given index.
- See Also:
-
floatValue
public float floatValue(int index) Returns the value at the given index as afloat
primitive type.- Overrides:
floatValue
in classVector
- Parameters:
index
- the index in the [0 … size-1] range.- Returns:
- the value at the given index.
- See Also:
-
longValue
public long longValue(int index) Returns the value at the given index as along
primitive type. -
stringValue
Returns the string representation of the value at the given index.- Specified by:
stringValue
in classVector
- Parameters:
index
- the index in the [0 … size-1] range.- Returns:
- a string representation of the value at the given index (may be
null
). - See Also:
-
get
Returns the value at the given index wrapped in aLong
instance. -
set
Sets the value at the given index and returns the previous value. -
equals
Optimization ofequals(…)
method for the case where the other object is anotherPackedVector
.
-