Package arc.struct
Class ByteSeq
java.lang.Object
arc.struct.ByteSeq
A resizable, ordered or unordered byte array. Avoids the boxing that occurs with ArrayList. 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
ConstructorDescriptionByteSeq()
Creates an ordered array with a capacity of 16.ByteSeq
(boolean ordered, byte[] array, int startIndex, int count) Creates a new array containing the elements in the specified array.ByteSeq
(boolean ordered, int capacity) ByteSeq
(byte[] array) Creates a new ordered array containing the elements in the specified array.ByteSeq
(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
(byte value) void
add
(byte value1, byte value2) void
add
(byte value1, byte value2, byte value3) void
add
(byte value1, byte value2, byte value3, byte value4) void
addAll
(byte... array) void
addAll
(byte[] array, int offset, int length) void
void
void
clear()
boolean
contains
(byte value) byte[]
ensureCapacity
(int additionalCapacity) Increases the size of the backing array to accommodate the specified number of additional items.boolean
byte
first()
Returns the first item.byte
get
(int index) int
hashCode()
void
incr
(int index, byte value) int
indexOf
(byte value) void
insert
(int index, byte value) boolean
isEmpty()
Returns true if the array is empty.int
lastIndexOf
(byte value) void
mul
(int index, byte value) byte
peek()
Returns the last item.byte
pop()
Removes and returns the last item.byte
random()
Returns a random item from the array, or zero if the array is empty.boolean
Removes from this array all of elements contained in the specified array.int
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.boolean
removeValue
(byte value) protected byte[]
resize
(int newSize) void
reverse()
void
set
(int index, byte value) byte[]
setSize
(int newSize) Sets the array size, leaving any values beyond the current size undefined.byte[]
shrink()
Reduces the size of the backing array to the size of the actual items.void
shuffle()
void
sort()
void
swap
(int first, int second) byte[]
toArray()
toString()
void
truncate
(int newSize) Reduces the size of the array to the specified size.static ByteSeq
with
(byte... array)
-
Field Details
-
items
public byte[] items -
size
public int size -
ordered
public boolean ordered
-
-
Constructor Details
-
ByteSeq
public ByteSeq()Creates an ordered array with a capacity of 16. -
ByteSeq
public ByteSeq(int capacity) Creates an ordered array with the specified capacity. -
ByteSeq
public ByteSeq(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.
-
ByteSeq
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. -
ByteSeq
public ByteSeq(byte[] 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. -
ByteSeq
public ByteSeq(boolean ordered, byte[] 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(byte value) -
add
public void add(byte value1, byte value2) -
add
public void add(byte value1, byte value2, byte value3) -
add
public void add(byte value1, byte value2, byte value3, byte value4) -
addAll
-
addAll
-
addAll
public void addAll(byte... array) -
addAll
public void addAll(byte[] array, int offset, int length) -
get
public byte get(int index) -
set
public void set(int index, byte value) -
incr
public void incr(int index, byte value) -
mul
public void mul(int index, byte value) -
insert
public void insert(int index, byte value) -
swap
public void swap(int first, int second) -
contains
public boolean contains(byte value) -
indexOf
public int indexOf(byte value) -
lastIndexOf
public int lastIndexOf(byte value) -
removeValue
public boolean removeValue(byte value) -
removeIndex
public int 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 byte pop()Removes and returns the last item. -
peek
public byte peek()Returns the last item. -
first
public byte first()Returns the first item. -
isEmpty
public boolean isEmpty()Returns true if the array is empty. -
clear
public void clear() -
shrink
public byte[] 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 byte[] 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 byte[] setSize(int newSize) Sets the array size, leaving any values beyond the current size undefined.- Returns:
items
-
resize
protected byte[] resize(int newSize) -
sort
public void sort() -
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 byte random()Returns a random item from the array, or zero if the array is empty. -
toArray
public byte[] toArray() -
hashCode
public int hashCode() -
equals
-
toString
-
toString
-