Package org.apache.sis.math
Class PackedVector
java.lang.Object
- All Implemented Interfaces:
Serializable,Iterable<Number>,Collection<Number>,List<Number>,RandomAccess,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 IntegerListThe compressed list of integer values.private final long(package private) static final intMinimal length for creating a packed vector.private final longThe offset to add to thedatain order to get the values to return.private static final longFor cross-version compatibility.Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePackedVector(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 PackedVectorCreates a new compressed vector initialized to a copy of the data provided by the given vector.doubledoubleValue(int index) Returns the value at the given index as adoubleprimitive type.booleanOptimization ofequals(…)method for the case where the other object is anotherPackedVector.floatfloatValue(int index) Returns the value at the given index as afloatprimitive type.get(int index) Returns the value at the given index wrapped in aLonginstance.Type of elements fixed toLongeven if the actual storage used by this class is more compact.booleanLong values are not guaranteed to be convertible to single-precision floating point type.longlongValue(int index) Returns the value at the given index as alongprimitive type.Sets the value at the given index and returns the previous value.intsize()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, verifyTypeMethods 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, warningMethods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRangeMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, streamMethods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, 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 todeltainclusive. -
increment
private final long increment -
offset
private final long offsetThe offset to add to thedatain 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 minusoffsetdivided 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 thelongtype (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
nullif the vector cannot or should not be compressed.
-
getElementType
Type of elements fixed toLongeven if the actual storage used by this class is more compact. The reason for theLongtype is that this class can return any value in theLongrange, because of theoffset.- Specified by:
getElementTypein interfaceCheckedContainer<Long>- Specified by:
getElementTypein 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:
isSinglePrecisionin classVector- Returns:
- whether values in this vector can be casted to
floatprimitive 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 adoubleprimitive type.- Specified by:
doubleValuein 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 afloatprimitive type.- Overrides:
floatValuein 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 alongprimitive type. -
stringValue
Returns the string representation of the value at the given index.- Specified by:
stringValuein 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 aLonginstance. -
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.
-