Package org.ddogleg.struct
Class DogArray_F32
java.lang.Object
org.ddogleg.struct.DogArray_F32
- All Implemented Interfaces:
DogArrayPrimitive<DogArray_F32>
Growable array composed of floats.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interfacestatic interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(float val) voidaddAll(float[] array, int startIndex, int endIndex) voidaddAll(DogArray_F32 queue) voidstatic DogArray_F32array(float... values) booleancontains(float value) copy()intcount(float value) Counts the number of times the specified value occurs in the listintcount(DogArray_F32.Filter filter) voidextend(int size) Changes the array to the specified size.voidfill(float value) voidfill(int idx0, int idx1, float value) voidflip()Flips the elements such that a[i] = a[N-i-1] where N is the number of elements.voidvoidfloatget(int index) voidget(int offset, float[] dst, int dstOffset, int length) Copies a sequence of values into the specified arrayfloatgetFraction(double fraction) Gets the value at the index which corresponds to the specified fractionfloatgetTail()floatgetTail(int index) Returns an element starting from the end of the list.intindexOf(float value) Returns the index of the first element with the specified 'value'.intintvoidinsert(int index, float value) Inserts the value at the specified index and shifts all the other values down.booleanisEquals(float... values) Sees is the primitive array is equal to the values in this arraybooleanisEquals(DogArray_F32 values) booleanisEquals(DogArray_F32 values, float tol) Checks for equality within the specified tolerancefloatpop()voidpush(float val) static DogArray_F32range(int idx0, int idx1) Returns a new array with values containing range of integer numbers from idx0 to idx1-1.voidremove(int index) voidremove(int first, int last) Removes elements from the list starting at 'first' and ending at 'last'floatremoveSwap(int index) Removes the specified index from the array by swapping it with last element.floatreserve(int amount) Ensures that the internal array's length is at least this size.reset()Sets the size to zero.voidresetResize(int size, float value) Deprecated.resize(int size) Ensures that the internal array is at least this size.resize(int size, float value) Resizes the array and assigns the default value to every new element.resize(int size, DogLambdas.AssignIdx_F32 op) Resizes and assigns the new elements (if any) to the value specified by the lambdavoidset(int index, float value) voidsetTail(int index, float value) setTo(float... src) Set's the value of this array to the passed in raw array.setTo(float[] array, int offset, int length) Sets this array to be equal to the array segmentsetTo(DogArray_F32 original) Turns 'this' into a copy of 'original'voidShuffle elements by randomly swapping themintsize()Number of elements in the queuevoidsort()Sorts the data from smallest to largestvoidsort(QuickSort_F32 sorter) Sort but with a re-usable sorter to avoid declaring new memoryfloat[]toArray()Creates a new primitive array which is a copy.floatunsafe_get(int index) voidzero()Sets all elements to 0 or False for binary queuesstatic DogArray_F32zeros(int length) Creates a queue with the specified length as its size filled with all zerosMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.ddogleg.struct.DogArrayPrimitive
isEmpty, isIndexOutOfBounds, isNotEmpty, reserveIncrease
-
Field Details
-
data
public float[] data -
size
public int size
-
-
Constructor Details
-
DogArray_F32
public DogArray_F32(int reserve) -
DogArray_F32
public DogArray_F32()
-
-
Method Details
-
zeros
Creates a queue with the specified length as its size filled with all zeros -
array
-
range
Returns a new array with values containing range of integer numbers from idx0 to idx1-1.- Parameters:
idx0- Lower extent, inclusive.idx1- Upper extent, exclusive.- Returns:
- new array.
-
count
public int count(float value) Counts the number of times the specified value occurs in the list -
isEquals
public boolean isEquals(float... values) Sees is the primitive array is equal to the values in this array- Parameters:
values- primitive array- Returns:
- true if equal or false if not
-
isEquals
-
isEquals
Checks for equality within the specified tolerance -
reset
Description copied from interface:DogArrayPrimitiveSets the size to zero.- Specified by:
resetin interfaceDogArrayPrimitive<DogArray_F32>- Returns:
- Returns 'this' to allow chaining of operations.
-
addAll
-
addAll
public void addAll(float[] array, int startIndex, int endIndex) -
add
public void add(float val) -
push
public void push(float val) -
setTo
Sets this array to be equal to the array segment- Parameters:
array- (Input) source arrayoffset- first indexlength- number of elements to copy
-
setTo
Set's the value of this array to the passed in raw array.- Parameters:
src- (Input) The input array- Returns:
- A reference to "this" to allow chaining of commands
-
toArray
public float[] toArray()Creates a new primitive array which is a copy. -
remove
public void remove(int index) -
remove
public void remove(int first, int last) Removes elements from the list starting at 'first' and ending at 'last'- Parameters:
first- First index you wish to remove. Inclusive.last- Last index you wish to remove. Inclusive.
-
insert
public void insert(int index, float value) Inserts the value at the specified index and shifts all the other values down. -
removeSwap
public float removeSwap(int index) Removes the specified index from the array by swapping it with last element. Does not preserve order but has a runtime of O(1).- Parameters:
index- The index to be removed.- Returns:
- The removed object
-
removeTail
public float removeTail() -
get
public float get(int index) -
get
public void get(int offset, float[] dst, int dstOffset, int length) Copies a sequence of values into the specified array- Parameters:
offset- First index it will read fromdst- Array it will copy the values intodstOffset- First index in dst array that it will write tolength- Number of elements it will copy
-
getTail
public float getTail() -
getTail
public float getTail(int index) Returns an element starting from the end of the list. 0 = size -1 -
setTail
public void setTail(int index, float value) -
getFraction
public float getFraction(double fraction) Gets the value at the index which corresponds to the specified fraction- Parameters:
fraction- 0 to 1 inclusive- Returns:
- value at fraction
-
unsafe_get
public float unsafe_get(int index) -
set
public void set(int index, float value) -
setTo
Description copied from interface:DogArrayPrimitiveTurns 'this' into a copy of 'original'- Specified by:
setToin interfaceDogArrayPrimitive<DogArray_F32>- Parameters:
original- queue that is to be copied- Returns:
- Returns 'this' to allow chaining of operations.
-
resize
Description copied from interface:DogArrayPrimitiveEnsures that the internal array is at least this size. Value of elements previously in the array will not be changed. If the size is increased then the value of new elements in undefined.
If you wish to resize the array and avoid copying over past values for performance reasons, then you must either resize(0) or callDogArrayPrimitive.reset()first.- Specified by:
resizein interfaceDogArrayPrimitive<DogArray_F32>- Parameters:
size- desired new size- Returns:
- Returns 'this' to allow chaining of operations.
-
resize
Resizes the array and assigns the default value to every new element.- Parameters:
size- New sizevalue- Default value
-
resetResize
Deprecated.Convenience function that will first callreset()thenresize(int, float), ensuring that every element in the array will have the specified value- Parameters:
size- New sizevalue- New value of every element
-
resize
Resizes and assigns the new elements (if any) to the value specified by the lambda- Parameters:
size- New sieop- Assigns default values
-
fill
public void fill(float value) -
fill
public void fill(int idx0, int idx1, float value) -
contains
public boolean contains(float value) -
extend
public void extend(int size) Description copied from interface:DogArrayPrimitiveChanges the array to the specified size. If there is not enough storage, a new internal array is created and the elements copied over. This is the same as: a.reserve(size);a.size = size;- Specified by:
extendin interfaceDogArrayPrimitive<DogArray_F32>- Parameters:
size- desired new size
-
reserve
Description copied from interface:DogArrayPrimitiveEnsures that the internal array's length is at least this size. Size is left unchanged. If the array is not empty and it needs to grow then the existing array is copied into the new array.- Specified by:
reservein interfaceDogArrayPrimitive<DogArray_F32>- Parameters:
amount- minimum size of internal array- Returns:
- Returns 'this' to allow chaining of operations.
-
size
public int size()Description copied from interface:DogArrayPrimitiveNumber of elements in the queue- Specified by:
sizein interfaceDogArrayPrimitive<DogArray_F32>- Returns:
- size of queue
-
zero
public void zero()Description copied from interface:DogArrayPrimitiveSets all elements to 0 or False for binary queues- Specified by:
zeroin interfaceDogArrayPrimitive<DogArray_F32>
-
copy
- Specified by:
copyin interfaceDogArrayPrimitive<DogArray_F32>
-
flip
public void flip()Description copied from interface:DogArrayPrimitiveFlips the elements such that a[i] = a[N-i-1] where N is the number of elements.- Specified by:
flipin interfaceDogArrayPrimitive<DogArray_F32>
-
pop
public float pop() -
indexOf
public int indexOf(float value) Returns the index of the first element with the specified 'value'. return -1 if it wasn't found- Parameters:
value- Value to search for- Returns:
- index or -1 if it's not in the list
-
indexOfGreatest
public int indexOfGreatest() -
indexOfLeast
public int indexOfLeast() -
sort
public void sort()Description copied from interface:DogArrayPrimitiveSorts the data from smallest to largest- Specified by:
sortin interfaceDogArrayPrimitive<DogArray_F32>
-
sort
Sort but with a re-usable sorter to avoid declaring new memory -
shuffle
Shuffle elements by randomly swapping them -
forIdx
-
forEach
-
applyIdx
-
count
-