Package org.basex.util.list
Class IntList
java.lang.Object
org.basex.util.list.ElementList
org.basex.util.list.IntList
Resizable-array implementation for native int values.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Field Summary
FieldsFields inherited from class org.basex.util.list.ElementList
factor, size -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal IntListadd(int element) Adds an element to the array.final IntListadd(int... elements) Adds elements to the array.final booleancontains(int element) Checks if the specified element is found in the list.final int[]createOrder(boolean asc) Sorts the data and returns an array with offsets to the sorted array.final IntListddo()Sorts the data and removes distinct values.booleanfinal int[]finish()Returns an array with all elements and invalidates the internal array.final intget(int index) Returns the element at the specified position.final voidincFrom(int diff, int index) Adds a difference to all elements starting from the specified index.final voidinsert(int index, int... elements) Inserts elements at the specified index position.final intpeek()Returns the uppermost element from the stack.final intpop()Pops the uppermost element from the stack.final voidpush(int element) Pushes an element onto the stack.final intremove(int index) Removes the element at the specified position.final voidremoveAll(int element) Removes all occurrences of the specified element from the list.reverse()Reverses the order of the elements.final voidset(int index, int element) Stores an element at the specified position.sort()Sorts the data.final voidsort(byte[][] values, boolean asc, boolean num) Sorts the data in the order of the specified token array.final voidsort(double[] values, boolean asc) Sorts the data in the order of the specified numeric array.final voidsort(int[] values, boolean asc) Sorts the data in the order of the specified numeric array.final voidsort(long[] values, boolean asc) Sorts the data in the order of the specified numeric array.final intsortedIndexOf(int element) Searches the specified element via binary search.final int[]toArray()Returns an array with all elements.toString()Methods inherited from class org.basex.util.list.ElementList
isEmpty, newCapacity, newCapacity, reset, size, size
-
Field Details
-
list
protected int[] listElement container.
-
-
Constructor Details
-
IntList
public IntList()Default constructor. -
IntList
public IntList(long capacity) Constructor with initial capacity.- Parameters:
capacity- array capacity
-
IntList
public IntList(double factor) Constructor, specifying a resize factor. Smaller values are more memory-saving, while larger values will provide better performance.- Parameters:
factor- resize factor
-
IntList
public IntList(int[] elements) Lightweight constructor, adopting the specified elements.- Parameters:
elements- initial array
-
-
Method Details
-
add
Adds an element to the array.- Parameters:
element- element to be added- Returns:
- self reference
-
add
Adds elements to the array.- Parameters:
elements- elements to be added- Returns:
- self reference
-
get
public final int get(int index) Returns the element at the specified position.- Parameters:
index- index of the element to return- Returns:
- element
-
set
public final void set(int index, int element) Stores an element at the specified position.- Parameters:
index- index of the element to replaceelement- element to be stored
-
contains
public final boolean contains(int element) Checks if the specified element is found in the list.- Parameters:
element- element to be found- Returns:
- result of check
-
insert
public final void insert(int index, int... elements) Inserts elements at the specified index position.- Parameters:
index- inserting positionelements- elements to be inserted
-
removeAll
public final void removeAll(int element) Removes all occurrences of the specified element from the list.- Parameters:
element- element to be removed
-
remove
public final int remove(int index) Removes the element at the specified position.- Parameters:
index- index of the element to remove- Returns:
- removed element
-
incFrom
public final void incFrom(int diff, int index) Adds a difference to all elements starting from the specified index.- Parameters:
diff- differenceindex- index of the first element
-
peek
public final int peek()Returns the uppermost element from the stack.- Returns:
- the uppermost element
-
pop
public final int pop()Pops the uppermost element from the stack.- Returns:
- the popped element
-
push
public final void push(int element) Pushes an element onto the stack.- Parameters:
element- element
-
sortedIndexOf
public final int sortedIndexOf(int element) Searches the specified element via binary search. Note that all elements must be sorted.- Parameters:
element- element to be found- Returns:
- index of the search key, or the negative insertion point - 1
-
toArray
public final int[] toArray()Returns an array with all elements.- Returns:
- array
-
finish
public final int[] finish()Returns an array with all elements and invalidates the internal array. Warning: the function must only be called if the list is discarded afterwards.- Returns:
- array (internal representation!)
-
ddo
Sorts the data and removes distinct values.- Returns:
- self reference
-
reverse
Reverses the order of the elements.- Returns:
- self reference
-
createOrder
public final int[] createOrder(boolean asc) Sorts the data and returns an array with offsets to the sorted array. SeeArray.createOrder(int[], boolean)- Parameters:
asc- ascending order- Returns:
- array with new order
-
sort
Sorts the data.- Returns:
- self reference
-
sort
public final void sort(byte[][] values, boolean asc, boolean num) Sorts the data in the order of the specified token array. Note that the input array will be resorted as well. The algorithm is derived fromArrays.sort(int[]).- Parameters:
values- values to sort byasc- ascending ordernum- numeric sort
-
sort
public final void sort(double[] values, boolean asc) Sorts the data in the order of the specified numeric array. Note that the input array will be resorted as well. The algorithm is derived fromArrays.sort(int[]).- Parameters:
values- values to sort byasc- ascending order
-
sort
public final void sort(int[] values, boolean asc) Sorts the data in the order of the specified numeric array. Note that the input array will be resorted as well. The algorithm is derived fromArrays.sort(int[]).- Parameters:
values- values to sort byasc- ascending order
-
sort
public final void sort(long[] values, boolean asc) Sorts the data in the order of the specified numeric array. Note that the input array will be resorted as well. The algorithm is derived fromArrays.sort(int[]).- Parameters:
values- values to sort byasc- ascending order
-
equals
-
toString
-