Package org.ddogleg.struct
Class DogArray_B
java.lang.Object
org.ddogleg.struct.DogArray_B
- All Implemented Interfaces:
DogArrayPrimitive<DogArray_B>
Growable array composed of booleans.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(boolean val) void
addAll
(boolean[] array, int startIndex, int endIndex) void
addAll
(DogArray_B queue) void
static DogArray_B
array
(boolean... values) static DogArray_B
array
(int... values) Non-zero values are set to trueboolean
contains
(boolean value) copy()
int
count
(boolean value) Counts the number of times the specified value occurs in the listvoid
extend
(int size) Changes the array to the specified size.void
fill
(boolean value) void
fill
(int idx0, int idx1, boolean value) void
flip()
Flips the elements such that a[i] = a[N-i-1] where N is the number of elements.void
void
boolean
get
(int index) boolean
getTail()
boolean
getTail
(int index) Returns an element starting from the end of the list.int
indexOf
(boolean value) Returns the index of the first element with the specified 'value'.void
insert
(int index, boolean value) Inserts the value at the specified index and shifts all the other values down.boolean
isEquals
(boolean... values) boolean
isEquals
(int... values) Sees is the primitive array is equal to the values in this arrayboolean
isEquals
(DogArray_B values) boolean
pop()
void
push
(boolean val) void
remove
(int index) void
remove
(int first, int last) Removes elements from the list starting at 'first' and ending at 'last'boolean
removeSwap
(int index) Removes the specified index from the array by swapping it with last element.boolean
void
reserve
(int amount) Ensures that the internal array's length is at least this size.reset()
Sets the size to zero.void
resetResize
(int size, boolean value) Deprecated.resize
(int size) Ensures that the internal array is at least this size.resize
(int size, boolean value) Resizes the array and assigns the default value to every new element.resize
(int size, DogLambdas.AssignIdx_B op) Resizes and assigns the new elements (if any) to the value specified by the lambdavoid
set
(int index, boolean value) void
setTail
(int index, boolean value) setTo
(boolean... src) Set's the value of this array to the passed in raw array.setTo
(boolean[] array, int offset, int length) Sets this array to be equal to the array segmentsetTo
(DogArray_B original) Turns 'this' into a copy of 'original'void
Shuffle elements by randomly swapping themint
size()
Number of elements in the queuevoid
sort()
Sorts the data from smallest to largestboolean[]
toArray()
Creates a new primitive array which is a copy.boolean
unsafe_get
(int index) void
zero()
Sets all elements to 0 or False for binary queuesstatic DogArray_B
zeros
(int length) Creates a queue with the specified length as its size filled with falseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.ddogleg.struct.DogArrayPrimitive
isEmpty, isIndexOutOfBounds
-
Field Details
-
data
public boolean[] data -
size
public int size
-
-
Constructor Details
-
DogArray_B
public DogArray_B(int reserve) -
DogArray_B
public DogArray_B()
-
-
Method Details
-
zeros
Creates a queue with the specified length as its size filled with false -
array
-
array
Non-zero values are set to true -
count
public int count(boolean value) Counts the number of times the specified value occurs in the list -
isEquals
public boolean isEquals(int... 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
public boolean isEquals(boolean... values) -
isEquals
-
reset
Description copied from interface:DogArrayPrimitive
Sets the size to zero.- Specified by:
reset
in interfaceDogArrayPrimitive<DogArray_B>
- Returns:
- Returns 'this' to allow chaining of operations.
-
addAll
-
addAll
public void addAll(boolean[] array, int startIndex, int endIndex) -
add
public void add(boolean val) -
push
public void push(boolean 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 boolean[] 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, boolean value) Inserts the value at the specified index and shifts all the other values down. -
removeSwap
public boolean 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 boolean removeTail() -
get
public boolean get(int index) -
getTail
public boolean getTail() -
getTail
public boolean getTail(int index) Returns an element starting from the end of the list. 0 = size -1 -
setTail
public void setTail(int index, boolean value) -
unsafe_get
public boolean unsafe_get(int index) -
set
public void set(int index, boolean value) -
setTo
Description copied from interface:DogArrayPrimitive
Turns 'this' into a copy of 'original'- Specified by:
setTo
in interfaceDogArrayPrimitive<DogArray_B>
- Parameters:
original
- queue that is to be copied- Returns:
- Returns 'this' to allow chaining of operations.
-
resize
Description copied from interface:DogArrayPrimitive
Ensures 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:
resize
in interfaceDogArrayPrimitive<DogArray_B>
- Parameters:
size
- desired new size
-
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, boolean)
, 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(boolean value) -
fill
public void fill(int idx0, int idx1, boolean value) -
contains
public boolean contains(boolean value) -
extend
public void extend(int size) Description copied from interface:DogArrayPrimitive
Changes 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:
extend
in interfaceDogArrayPrimitive<DogArray_B>
- Parameters:
size
- desired new size
-
reserve
public void reserve(int amount) Description copied from interface:DogArrayPrimitive
Ensures 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:
reserve
in interfaceDogArrayPrimitive<DogArray_B>
- Parameters:
amount
- minimum size of internal array
-
size
public int size()Description copied from interface:DogArrayPrimitive
Number of elements in the queue- Specified by:
size
in interfaceDogArrayPrimitive<DogArray_B>
- Returns:
- size of queue
-
zero
public void zero()Description copied from interface:DogArrayPrimitive
Sets all elements to 0 or False for binary queues- Specified by:
zero
in interfaceDogArrayPrimitive<DogArray_B>
-
copy
- Specified by:
copy
in interfaceDogArrayPrimitive<DogArray_B>
-
flip
public void flip()Description copied from interface:DogArrayPrimitive
Flips the elements such that a[i] = a[N-i-1] where N is the number of elements.- Specified by:
flip
in interfaceDogArrayPrimitive<DogArray_B>
-
pop
public boolean pop() -
indexOf
public int indexOf(boolean 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
-
sort
public void sort()Description copied from interface:DogArrayPrimitive
Sorts the data from smallest to largest- Specified by:
sort
in interfaceDogArrayPrimitive<DogArray_B>
-
shuffle
Shuffle elements by randomly swapping them -
forIdx
-
forEach
-
applyIdx
-