Package org.ddogleg.struct
Class FastArray<T>
java.lang.Object
org.ddogleg.struct.FastAccess<T>
org.ddogleg.struct.FastArray<T>
- All Implemented Interfaces:
Serializable
A growable array which provides access to the raw array but does not own the elements inside of the array. When
it is inexpensive to do so (O(1) operation) it will discard references to data when they are no longer needed.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.ddogleg.struct.FastAccess
FastAccess.FunctionEach<T>, FastAccess.FunctionEachIdx<T>, FastAccess.FunctionMatches<T>
-
Field Summary
Fields inherited from class org.ddogleg.struct.FastAccess
data, size, type
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
void
addAll
(FastAccess<T> list) void
clear()
Sets the size of the list to zero and removes all internal references inside the current array.remove
(int index) Removes an element from the queue and preserves the order of all elements.boolean
Searches for the object and removes it if it's contained in the list.removeSwap
(int index) Removes the specified index from the array by swapping it with last element.void
reserve
(int length) Ensures that the internal array has at least `length` elements.void
reserve
(int length, boolean copy) void
reset()
Sets the size of the list to zero.void
resetReserve
(int length) Convenience function which resets the array and reserves memoryvoid
resize
(int length) Changes the size to the specified length.void
Changes the size and fills each element with this valuevoid
void
toList()
Returns a wrapper around FastQueue that allows it to act as a read only list.
-
Constructor Details
-
FastArray
-
FastArray
-
-
Method Details
-
set
-
add
-
remove
Description copied from class:FastAccess
Removes an element from the queue and preserves the order of all elements. This is done by shifting elements in the array down one and placing the removed element at the old end of the list. O(N) runtime.- Specified by:
remove
in classFastAccess<T>
- Parameters:
index
- Index of the element being removed- Returns:
- The object removed.
-
removeSwap
Description copied from class:FastAccess
Removes the specified index from the array by swapping it with last element. Does not preserve order but has a runtime of O(1).- Specified by:
removeSwap
in classFastAccess<T>
- Parameters:
index
- The index to be removed.- Returns:
- The removed object
-
remove
Searches for the object and removes it if it's contained in the list. O(N) operation.- Parameters:
target
- Object to be removed- Returns:
- true if it was removed or false if it was not found
-
removeTail
-
reset
public void reset()Sets the size of the list to zero. External references are not modified. -
resetReserve
public void resetReserve(int length) Convenience function which resets the array and reserves memory -
clear
public void clear()Sets the size of the list to zero and removes all internal references inside the current array. -
reserve
public void reserve(int length) Ensures that the internal array has at least `length` elements. If it does not then a new internal array is created with the specified length and elements from the old are copied into the new. The `size` does not change.- Parameters:
length
- Requested minimum internal array length
-
reserve
public void reserve(int length, boolean copy) -
resize
public void resize(int length) Changes the size to the specified length. Equivalent to callingreserve(int)
and this.size = N.- Parameters:
length
- The new size of the queue
-
resize
Changes the size and fills each element with this value -
addAll
-
add
-
setTail
-
addAll
-
toList
Returns a wrapper around FastQueue that allows it to act as a read only list. There is little overhead in using this interface. NOTE: The same instead of a list is returned each time. Be careful when writing concurrent code and create a copy.- Specified by:
toList
in classFastAccess<T>
- Returns:
- List wrapper.
-