Package arc.struct
Class BoolSeq
java.lang.Object
arc.struct.BoolSeq
A resizable, ordered or unordered boolean array. Avoids the boxing that occurs with ArrayList. It is less memory
efficient than
BitSet
, except for very small sizes. It more CPU efficient than BitSet
, except for very large
sizes or if BitSet functionality such as and, or, xor, etc are needed. If unordered, this class avoids a memory copy when
removing elements (the last element is moved to the removed element's position).-
Field Summary
-
Constructor Summary
ConstructorDescriptionBoolSeq()
Creates an ordered array with a capacity of 16.BoolSeq
(boolean[] array) Creates a new ordered array containing the elements in the specified array.BoolSeq
(boolean ordered, boolean[] array, int startIndex, int count) Creates a new array containing the elements in the specified array.BoolSeq
(boolean ordered, int capacity) BoolSeq
(int capacity) Creates an ordered array with the specified capacity.Creates a new array containing the elements in the specific array. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(boolean value) void
add
(boolean value1, boolean value2) void
add
(boolean value1, boolean value2, boolean value3) void
add
(boolean value1, boolean value2, boolean value3, boolean value4) void
addAll
(boolean... array) void
addAll
(boolean[] array, int offset, int length) void
void
void
clear()
boolean[]
ensureCapacity
(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items.boolean
boolean
first()
Returns the first item.boolean
get
(int index) int
hashCode()
void
insert
(int index, boolean value) boolean
isEmpty()
Returns true if the array is empty.boolean
peek()
Returns the last item.boolean
pop()
Removes and returns the last item.boolean
random()
Returns a random item from the array, or false if the array is empty.boolean
Removes from this array all of elements contained in the specified array.boolean
removeIndex
(int index) Removes and returns the item at the specified index.void
removeRange
(int start, int end) Removes the items between the specified indices, inclusive.protected boolean[]
resize
(int newSize) void
reverse()
void
set
(int index, boolean value) boolean[]
setSize
(int newSize) Sets the array size, leaving any values beyond the current size undefined.boolean[]
shrink()
Reduces the size of the backing array to the size of the actual items.void
shuffle()
void
swap
(int first, int second) boolean[]
toArray()
toString()
void
truncate
(int newSize) Reduces the size of the array to the specified size.static BoolSeq
with
(boolean... array)
-
Field Details
-
items
public boolean[] items -
size
public int size -
ordered
public boolean ordered
-
-
Constructor Details
-
BoolSeq
public BoolSeq()Creates an ordered array with a capacity of 16. -
BoolSeq
public BoolSeq(int capacity) Creates an ordered array with the specified capacity. -
BoolSeq
public BoolSeq(boolean ordered, int capacity) - Parameters:
ordered
- If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.capacity
- Any elements added beyond this will cause the backing array to be grown.
-
BoolSeq
Creates a new array containing the elements in the specific array. The new array will be ordered if the specific array is ordered. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown. -
BoolSeq
public BoolSeq(boolean[] array) Creates a new ordered array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown. -
BoolSeq
public BoolSeq(boolean ordered, boolean[] array, int startIndex, int count) Creates a new array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
ordered
- If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
-
-
Method Details
-
with
- See Also:
-
add
public void add(boolean value) -
add
public void add(boolean value1, boolean value2) -
add
public void add(boolean value1, boolean value2, boolean value3) -
add
public void add(boolean value1, boolean value2, boolean value3, boolean value4) -
addAll
-
addAll
-
addAll
public void addAll(boolean... array) -
addAll
public void addAll(boolean[] array, int offset, int length) -
get
public boolean get(int index) -
set
public void set(int index, boolean value) -
insert
public void insert(int index, boolean value) -
swap
public void swap(int first, int second) -
removeIndex
public boolean removeIndex(int index) Removes and returns the item at the specified index. -
removeRange
public void removeRange(int start, int end) Removes the items between the specified indices, inclusive. -
removeAll
Removes from this array all of elements contained in the specified array.- Returns:
- true if this array was modified.
-
pop
public boolean pop()Removes and returns the last item. -
peek
public boolean peek()Returns the last item. -
first
public boolean first()Returns the first item. -
isEmpty
public boolean isEmpty()Returns true if the array is empty. -
clear
public void clear() -
shrink
public boolean[] shrink()Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added.- Returns:
items
-
ensureCapacity
public boolean[] ensureCapacity(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.- Returns:
items
-
setSize
public boolean[] setSize(int newSize) Sets the array size, leaving any values beyond the current size undefined.- Returns:
items
-
resize
protected boolean[] resize(int newSize) -
reverse
public void reverse() -
shuffle
public void shuffle() -
truncate
public void truncate(int newSize) Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken. -
random
public boolean random()Returns a random item from the array, or false if the array is empty. -
toArray
public boolean[] toArray() -
hashCode
public int hashCode() -
equals
-
toString
-
toString
-