mikera.indexz
Class Index
- java.lang.Object
-
- mikera.indexz.AIndex
-
- mikera.indexz.Index
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<AIndex>, java.lang.Iterable<java.lang.Integer>
public final class Index extends AIndex
Class to represent a mutable list of integer indexes, typically used for indexing into vectors or matrices. Backed by an int[] array.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Index(int length)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanallInRange(int start, int end)Checks that all values in this index are within the specified range of start (inclusive) to end (exclusive)AVectorasVector()Indexclone()Indexcompose(AIndex a)Composes this index with a second index, returning a new index.Indexcompose(Index a)booleancontainsSorted(int index)Returns true if the index contains a specific value.static Indexcreate(AIndex index)static Indexcreate(java.util.ArrayList<java.lang.Integer> v)Creates an Index using the values from the given ArrayList.static Indexcreate(AVector v)Creates an Index using the values from the given AVector.static Indexcreate(int[] indices)static Indexcreate(java.util.List<java.lang.Integer> v)Creates an Index using the values from the given List.static IndexcreateLength(int len)Create a new zero-filled Index with the specified lengthstatic IndexcreateSorted(java.util.Set<java.lang.Integer> keySet)static IndexcreateSorted(java.util.SortedSet<java.lang.Integer> keySet)booleanequals(Index o)booleanequals(java.lang.Object o)IndexexactClone()intfind(int value)Finds a value in this Index and return's it's position, or -1 if not foundintfindMissing()Finds the first missing index value, assuming the index is sorted and distinct.intget(int i)Gets the index value at position iint[]getData()int[]getShape()IndexincludeSorted(Index ind)IndexincludeSorted(java.util.Set<java.lang.Integer> is)intindexPosition(int x)Looks up an index value in the index, returning its position or -1 if not found Index must be both sorted and distinct.Indexinsert(int position, int value)Returns a new Index with a value inserted at the specified positionIndexinvert()Inverts the permutation represented by this IndexbooleanisDistinctSorted()Returns true if this index is distinct and sorted (in strictly increasing order)booleanisEvenPermutation()booleanisFullyMutable()booleanisOddPermutation()booleanisPermutation()Returns true if this index represents a permutation of positions 0..length-1booleanisSorted()Returns true if this index is sorted (in increasing order)intlast()Gets the last index value in this index.intlength()Returns the length of this index listvoidlookupWith(Index source)static Indexof(int... indexes)Creates a new Index, using the specified index valuesvoidpermute(Index permutationIndex)Permutes this vector according to a given permutation indexvoidreverse()Reverses an indexintseekPosition(int i)Returns the position at which an index value exists or should be inserted at in an index Index must be both sorted and distinct.voidset(int i, int value)voidsort()Sorts the Index (in-place)voidswap(int i, int j)Swaps (in-place) the indexes at two positionsintswapCount()Counts the number of swaps required to create this permutation.int[]toArray()java.util.Set<java.lang.Integer>toSet()java.util.SortedSet<java.lang.Integer>toSortedSet()intunsafeGet(int i)static Indexwrap(int[] indexes)Creates a new Index, wrapping the provided index array
-
-
-
Field Detail
-
EMPTY
public static final Index EMPTY
-
data
public final int[] data
-
-
Method Detail
-
create
public static Index create(java.util.ArrayList<java.lang.Integer> v)
Creates an Index using the values from the given ArrayList. Values are cast to integers as needed, according to the semantics of (int)value- Parameters:
v-- Returns:
-
create
public static Index create(java.util.List<java.lang.Integer> v)
Creates an Index using the values from the given List. Values are cast to integers as needed, according to the semantics of (int)value- Parameters:
v-- Returns:
-
create
public static Index create(int[] indices)
-
createSorted
public static Index createSorted(java.util.Set<java.lang.Integer> keySet)
-
createSorted
public static Index createSorted(java.util.SortedSet<java.lang.Integer> keySet)
-
create
public static Index create(AVector v)
Creates an Index using the values from the given AVector. Values are cast to integers as needed, according to the semantics of (int)value- Parameters:
v-- Returns:
-
wrap
public static Index wrap(int[] indexes)
Creates a new Index, wrapping the provided index array
-
of
public static Index of(int... indexes)
Creates a new Index, using the specified index values
-
createLength
public static Index createLength(int len)
Create a new zero-filled Index with the specified length
-
swap
public void swap(int i, int j)Swaps (in-place) the indexes at two positions
-
isDistinctSorted
public boolean isDistinctSorted()
Description copied from class:AIndexReturns true if this index is distinct and sorted (in strictly increasing order)- Overrides:
isDistinctSortedin classAIndex- Returns:
-
isSorted
public boolean isSorted()
Description copied from class:AIndexReturns true if this index is sorted (in increasing order)
-
isPermutation
public boolean isPermutation()
Description copied from class:AIndexReturns true if this index represents a permutation of positions 0..length-1- Overrides:
isPermutationin classAIndex- Returns:
-
includeSorted
public Index includeSorted(java.util.Set<java.lang.Integer> is)
-
toSet
public java.util.Set<java.lang.Integer> toSet()
-
toSortedSet
public java.util.SortedSet<java.lang.Integer> toSortedSet()
-
swapCount
public int swapCount()
Counts the number of swaps required to create this permutation. The index must represent a permutation, or the behaviour is undefined.- Returns:
-
isOddPermutation
public boolean isOddPermutation()
-
isEvenPermutation
public boolean isEvenPermutation()
-
get
public int get(int i)
Description copied from class:AIndexGets the index value at position i
-
unsafeGet
public int unsafeGet(int i)
-
length
public int length()
Description copied from class:AIndexReturns the length of this index list
-
permute
public void permute(Index permutationIndex)
Permutes this vector according to a given permutation index- Parameters:
permutationIndex-
-
asVector
public AVector asVector()
-
equals
public boolean equals(Index o)
-
getData
public int[] getData()
-
isFullyMutable
public boolean isFullyMutable()
- Overrides:
isFullyMutablein classAIndex
-
lookupWith
public void lookupWith(Index source)
-
compose
public Index compose(AIndex a)
Description copied from class:AIndexComposes this index with a second index, returning a new index. New index satisfies index.get(i) == a.get(this.get(i));
-
indexPosition
public int indexPosition(int x)
Looks up an index value in the index, returning its position or -1 if not found Index must be both sorted and distinct.- Specified by:
indexPositionin classAIndex- Parameters:
x-- Returns:
-
seekPosition
public int seekPosition(int i)
Description copied from class:AIndexReturns the position at which an index value exists or should be inserted at in an index Index must be both sorted and distinct.- Overrides:
seekPositionin classAIndex- Returns:
- The target position in the index, which will satisfy 0 <= position <= this.length()
-
findMissing
public int findMissing()
Finds the first missing index value, assuming the index is sorted and distinct. If the index is a complete range, returns -1- Returns:
-
containsSorted
public boolean containsSorted(int index)
Description copied from class:AIndexReturns true if the index contains a specific value. Assumes the index is in sorted order.- Overrides:
containsSortedin classAIndex- Returns:
-
insert
public Index insert(int position, int value)
Returns a new Index with a value inserted at the specified position
-
find
public int find(int value)
Finds a value in this Index and return's it's position, or -1 if not found- Parameters:
value-- Returns:
-
invert
public Index invert()
Inverts the permutation represented by this Index- Returns:
-
allInRange
public boolean allInRange(int start, int end)Checks that all values in this index are within the specified range of start (inclusive) to end (exclusive)- Parameters:
start-end-- Returns:
-
getShape
public int[] getShape()
-
exactClone
public Index exactClone()
- Specified by:
exactClonein classAIndex
-
-
DMelt 3.0 © DataMelt by jWork.ORG