Package org.yamcs.utils
Class SortedIntArray
java.lang.Object
org.yamcs.utils.SortedIntArray
- All Implemented Interfaces:
Serializable
sorted int array
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates a sorted int array with a default initial capacitySortedIntArray
(int capacity) Creates a sorted int array with a given initial capacitySortedIntArray
(int... array) Creates the SortedIntArray by copying all values from the input array and sorting themSortedIntArray
(IntArray pids) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIfGreaterThan
(int v, int x) Add x to the elements of the array whose value is greater than vvoid
addToAll
(int x) Change the elements of the array by adding x to each elementboolean
contains
(int x) Performs a binary search and returns true if this array contains the value.static SortedIntArray
decodeFromVarIntArray
(byte[] buf) boolean
void
forEach
(IntConsumer action) int
get
(int pos) get element at positionint[]
getArray()
getAscendingIterator
(int startFrom) Constructs an ascending iterator starting from a specified value (inclusive)getDescendingIterator
(int startFrom) Constructs an descending iterator starting from a specified value (exclusive)int
hashCode()
int
insert
(int x) Inserts value to the array and return the position on which has been inserted.boolean
isEmpty()
int
search
(int x) performs a binary search in the array.int
size()
toString()
-
Field Details
-
DEFAULT_CAPACITY
public static int DEFAULT_CAPACITY
-
-
Constructor Details
-
SortedIntArray
public SortedIntArray()Creates a sorted int array with a default initial capacity -
SortedIntArray
public SortedIntArray(int capacity) Creates a sorted int array with a given initial capacity- Parameters:
capacity
-
-
SortedIntArray
public SortedIntArray(int... array) Creates the SortedIntArray by copying all values from the input array and sorting them- Parameters:
array
-
-
SortedIntArray
-
-
Method Details
-
insert
public int insert(int x) Inserts value to the array and return the position on which has been inserted.In case
x
is already present in the array, this function inserts the new value at a position after the values already present- Parameters:
x
- - value to be inserted- Returns:
- the position on which the value has been inserted
-
search
public int search(int x) performs a binary search in the array.- Parameters:
x
-- Returns:
- result of the binarySearch, @see java.util.Arrays#binarySearch(int[], int)
- See Also:
-
get
public int get(int pos) get element at position- Parameters:
pos
-- Returns:
- the element at position
-
isEmpty
public boolean isEmpty() -
getArray
public int[] getArray() -
size
public int size() -
getAscendingIterator
Constructs an ascending iterator starting from a specified value (inclusive)- Parameters:
startFrom
-- Returns:
- an iterator starting from the specified value
-
getDescendingIterator
Constructs an descending iterator starting from a specified value (exclusive)- Parameters:
startFrom
-- Returns:
- an descending iterator starting from the specified value
-
forEach
-
contains
public boolean contains(int x) Performs a binary search and returns true if this array contains the value.- Parameters:
x
- - value to check- Returns:
- true of the array contains the specified value
-
decodeFromVarIntArray
-
equals
-
addToAll
public void addToAll(int x) Change the elements of the array by adding x to each element -
addIfGreaterThan
public void addIfGreaterThan(int v, int x) Add x to the elements of the array whose value is greater than v -
toString
-
hashCode
public int hashCode()
-