cc.redberry.core.indices
Class IndicesUtils
- java.lang.Object
-
- cc.redberry.core.indices.IndicesUtils
-
public final class IndicesUtils extends java.lang.ObjectThis class provides static methods to work with individual index and indices objects.Index representation
All information about single index is enclosed in 32-bit word (int). The following bit structure is used:Index: stttttttXXXXXXXXcccccccccccccccc - per-bit representetion | | | | | 31 23 15 7 0 - bit index
s - one bit representing index state (0 - lower; 1 - upper) t - 7-bits representing index type (lower latin, upper latin, etc...) [for concrete codes see below] c - code of concrete index (a - 0, b - 1, c - 2, etc...) [index name] X - reserved (always 0)Index types
By default there are four different index types:HexCode BitCode Description 0x00 00000000 Latin lower case symbols 0x01 00000001 Latin upper case symbols 0x02 00000010 Greek lower case symbols 0x03 00000011 Greek upper case symbols Examples
Here are some examples of how concrete indices are presented in Redberry.
Index Hex _a 0x00000000 _C 0x01000002 ^{\beta} 0x82000001 ^{\Chi} 0x83000015 - Since:
- 1.0
- See Also:
Indices
-
-
Field Summary
Fields Modifier and Type Field and Description static intLOWER_RAW_STATE_INTRaw state int for lower indicesstatic intUPPER_RAW_STATE_INTRaw state int for upper indices
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static booleanareContracted(int index0, int index1)Indicates whether two indices are contracted (has the same type & name but different states).static booleancontainsNonMetric(Indices indices)Returnstrueif specified indices contain any index with non metric type.static intcreateIndex(int name, byte type, boolean state)Creates single index with specified name, type and state.static intcreateIndex(int name, IndexType type, boolean state)Creates single index with specified name, type and state.static booleanequalsRegardlessOrder(Indices indices1, int[] indices2)static booleanequalsRegardlessOrder(int[] indices1, int[] indices2)static int[]getFree(int[] indices)Returns an array of free indices onlystatic int[]getIndicesNames(Indices indices)Returns an array of indices names (with types), presented in specifiedIndicesobject with the same ordering.static int[]getIndicesNames(int[] indices)Returns an array of indices names (with types)static int[]getIndicesNames(IntArray indices)Returns an array of indices names (with types)static int[]getIntersections(Indices u, Indices v)Returns an array of contracted indices between specified indices.static int[]getIntersections(int[] freeIndices1, int[] freeIndices2)Returns an array of contracted indices between specified free indices.static intgetNameWithoutType(int index)Returns index name (code) without type.static intgetNameWithType(int index)Returns index name (code) with type (first 30 bits), but without state bit (in other words with state bit set to zero).static intgetRawStateInt(int index)Returns only state (31-th) bit of index without shift.static intgetRawTypeInt(int index)Returns index type in form 0xxxxxxx000000000000000000000000, where x - type bits.static int[]getSortedDistinctIndicesNames(Indices indices)This method returns array of integers representing set of indices names present in theIndicesobject.static booleangetState(int index)Returns state (31-th) bit of index.static intgetStateInt(int index)Returns state (31-th) bit of index shifted to 0-th position.static bytegetType(int index)Returns index type.static IndexTypegetTypeEnum(int index)Returns index type enum value.static intgetTypeInt(int index)Returns index type in form 0000000000000000000000000xxxxxxx, where x - type bits.static bytegetTypeWithState(int index)Returns index type with state bit.static booleanhasEqualTypeAndName(int index0, int index1)Indicates whether two indices has the same type and name.static booleanhasEqualTypes(int index0, int index1)Indicates whether two indices has the same type.static booleanhasEqualTypesAndStates(int index0, int index1)Indicates whether two indices has the same type and state.static booleanhaveEqualStates(int index1, int index2)static booleanhaveIntersections(Indices u, Indices v)Returns true if at least one free index ofuis contracted with some free index ofv.static intinverseIndexState(int index)Returns index with inverse index state.static booleanisPermutationConsistentWithIndices(int[] indices, int[] permutation)This method checks whether specified permutation is consistent with specified indices.static booleanisPermutationConsistentWithIndices(int[] indices, Permutation permutation)This method checks whether specified permutation is consistent with specified indices.static java.util.EnumSet<IndexType>nonMetricTypes(Indices indices)Returns all non metric types that present in specified indices.static intparseIndex(java.lang.String string)Parse single index.static intsetRawState(int rawState, int index)Changes index state to specified state of the form 0b1(0)000000.....static intsetState(boolean state, int index)Changes index state to specified state (true - upper, false - lower).static intsetType(byte type, int index)Changes index type to specified, represented by byte.static intsetType(IndexType type, int index)Changes index type to specified, represented by byte.static java.lang.StringtoString(int index)static java.lang.StringtoString(int[] indices)static java.lang.StringtoString(int[] indices, OutputFormat mode)static java.lang.StringtoString(int index, OutputFormat mode)
-
-
-
Field Detail
-
UPPER_RAW_STATE_INT
public static final int UPPER_RAW_STATE_INT
Raw state int for upper indices- See Also:
- Constant Field Values
-
LOWER_RAW_STATE_INT
public static final int LOWER_RAW_STATE_INT
Raw state int for lower indices- See Also:
- Constant Field Values
-
-
Method Detail
-
createIndex
public static int createIndex(int name, IndexType type, boolean state)Creates single index with specified name, type and state.- Parameters:
name- index nametype- index typestate- index state- Returns:
- index
-
createIndex
public static int createIndex(int name, byte type, boolean state)Creates single index with specified name, type and state.- Parameters:
name- index nametype- index typestate- index state- Returns:
- index
-
getRawStateInt
public static int getRawStateInt(int index)
Returns only state (31-th) bit of index without shift.
Expression used by this method is:index & 0x80000000- Parameters:
index- index- Returns:
- (1 << 31) for upper index & 0 for lower index
-
getStateInt
public static int getStateInt(int index)
Returns state (31-th) bit of index shifted to 0-th position.
Expression used by this method is:(index & 0x80000000) >>> 31- Parameters:
index- index- Returns:
- 1 for upper index & 0 for lower index
-
getState
public static boolean getState(int index)
Returns state (31-th) bit of index.
Expression used by this method is:(index & 0x80000000) == 0x80000000- Parameters:
index- index- Returns:
- 1 for upper index & 0 for lower index
-
inverseIndexState
public static int inverseIndexState(int index)
Returns index with inverse index state. So it raising lower indices and lowering upper indices.
Expression used by this method is:0x80000000 ^ index- Parameters:
index- index- Returns:
- index with inverse state bit
-
getNameWithType
public static int getNameWithType(int index)
Returns index name (code) with type (first 30 bits), but without state bit (in other words with state bit set to zero).
Expression used by this method is:index & 0x7FFFFFFF- Parameters:
index- specified index- Returns:
- index name (code) with type (first 30 bits), but without state bit (in other words with state bit set to zero)
-
setType
public static int setType(byte type, int index)Changes index type to specified, represented by byte.
Expression used by this method is:(0x80FFFFFF & index) | ((0x7F & type) << 24)- Parameters:
type- typeindex- index to change type in- Returns:
- index with new type
-
setType
public static int setType(IndexType type, int index)
Changes index type to specified, represented by byte.
Expression used by this method is:(0x80FFFFFF & index) | ((0x7F & type) << 24)- Parameters:
type- IndexTypeindex- index to change type in- Returns:
- index with new type
-
setRawState
public static int setRawState(int rawState, int index)Changes index state to specified state of the form 0b1(0)000000.....
Expression used by this method is:rawState | index- Parameters:
rawState- raw stateindex- index- Returns:
- index with new state
-
setState
public static int setState(boolean state, int index)Changes index state to specified state (true - upper, false - lower).- Parameters:
state- index state: true - upper, false - lower)index- index to change type in- Returns:
- index with new state
-
getNameWithoutType
public static int getNameWithoutType(int index)
Returns index name (code) without type.
Expression used by this method is:index & 0xFFFF- Parameters:
index- index- Returns:
- index name
-
getType
public static byte getType(int index)
Returns index type.
Expression used by this method is:((byte) ((index & 0x7FFFFFFF) >>> 24))- Parameters:
index- index- Returns:
- index type
-
getTypeEnum
public static IndexType getTypeEnum(int index)
Returns index type enum value.- Parameters:
index- index- Returns:
- index type enum value
-
getTypeInt
public static int getTypeInt(int index)
Returns index type in form 0000000000000000000000000xxxxxxx, where x - type bits.
Expression used by this method is:(index & 0x7FFFFFFF) >>> 24- Parameters:
index- index- Returns:
- index type
-
getRawTypeInt
public static int getRawTypeInt(int index)
Returns index type in form 0xxxxxxx000000000000000000000000, where x - type bits.
Expression used by this method is:index & 0x7F000000- Parameters:
index- index- Returns:
- index type
-
getTypeWithState
public static byte getTypeWithState(int index)
Returns index type with state bit.
Expression used by this method is:((byte) (index >>> 24))- Parameters:
index- index- Returns:
- index type with state
-
hasEqualTypeAndName
public static boolean hasEqualTypeAndName(int index0, int index1)Indicates whether two indices has the same type and name.
Expression used by this method is:(index0 & 0x7FFFFFFF) == (index1 & 0x7FFFFFFF)- Parameters:
index0- first indexindex1- second index- Returns:
- whether all bits except state bit are equals
-
hasEqualTypes
public static boolean hasEqualTypes(int index0, int index1)Indicates whether two indices has the same type.
Expression used by this method is:(index0 & 0x7F000000) == (index1 & 0x7F000000)- Parameters:
index0- first indexindex1- second index- Returns:
- true if type bits in indices are the same
-
hasEqualTypesAndStates
public static boolean hasEqualTypesAndStates(int index0, int index1)Indicates whether two indices has the same type and state.
Expression used by this method is:(index0 & 0xFF000000) == (index1 & 0xFF000000)- Parameters:
index0- first indexindex1- second index- Returns:
- true if type and state bits in indices are the same
-
areContracted
public static boolean areContracted(int index0, int index1)Indicates whether two indices are contracted (has the same type & name but different states).
This method is very fast, because it performs only two operations: bitwise xor + testing for equality with 32-bit constant.
Expression used by this method is:(index0 ^ index1) == 0x80000000- Parameters:
index0- first indexindex1- second index- Returns:
- true if type and state bits in indices are the same
-
getSortedDistinctIndicesNames
public static int[] getSortedDistinctIndicesNames(Indices indices)
This method returns array of integers representing set of indices names present in theIndicesobject.- Parameters:
indices- object to process- Returns:
- see description
-
toString
public static java.lang.String toString(int index, OutputFormat mode)
-
toString
public static java.lang.String toString(int index)
-
toString
public static java.lang.String toString(int[] indices, OutputFormat mode)
-
toString
public static java.lang.String toString(int[] indices)
-
parseIndex
public static int parseIndex(java.lang.String string)
Parse single index.- Parameters:
string- string representation of index- Returns:
- integer representation of index
-
getIndicesNames
public static int[] getIndicesNames(Indices indices)
Returns an array of indices names (with types), presented in specifiedIndicesobject with the same ordering.- Parameters:
indices-- Returns:
- array of indices names (with types)
-
getIndicesNames
public static int[] getIndicesNames(int[] indices)
Returns an array of indices names (with types)- Parameters:
indices-- Returns:
- array of indices names (with types)
-
getIndicesNames
public static int[] getIndicesNames(IntArray indices)
Returns an array of indices names (with types)- Parameters:
indices-- Returns:
- array of indices names (with types)
-
getFree
public static int[] getFree(int[] indices)
Returns an array of free indices only- Parameters:
indices-- Returns:
- array of free indices only
-
haveEqualStates
public static boolean haveEqualStates(int index1, int index2)
-
isPermutationConsistentWithIndices
public static boolean isPermutationConsistentWithIndices(int[] indices, int[] permutation)This method checks whether specified permutation is consistent with specified indices. Permutation considered to be consistent if it has similar length and does not permutes indices with different types.- Parameters:
indices- indices array to be checkedpermutation- permutation in one-line notation- Returns:
falseif permutation permutes indices with different types or have different length and true in other case
-
isPermutationConsistentWithIndices
public static boolean isPermutationConsistentWithIndices(int[] indices, Permutation permutation)This method checks whether specified permutation is consistent with specified indices. Permutation considered to be consistent if it has similar length and does not permutes indices with different types.- Parameters:
indices- indices array to be checkedpermutation- permutation in one-line notation- Returns:
falseif permutation permutes indices with different types or have different length and true in other case
-
equalsRegardlessOrder
public static boolean equalsRegardlessOrder(Indices indices1, int[] indices2)
-
equalsRegardlessOrder
public static boolean equalsRegardlessOrder(int[] indices1, int[] indices2)
-
haveIntersections
public static boolean haveIntersections(Indices u, Indices v)
Returns true if at least one free index ofuis contracted with some free index ofv.- Parameters:
u- indicesv- indices- Returns:
- true if at least one free index of
uis contracted with some free index ofv
-
getIntersections
public static int[] getIntersections(int[] freeIndices1, int[] freeIndices2)Returns an array of contracted indices between specified free indices.- Parameters:
freeIndices1- free indicesfreeIndices2- free indices- Returns:
- an array of contracted indices
-
getIntersections
public static int[] getIntersections(Indices u, Indices v)
Returns an array of contracted indices between specified indices.- Parameters:
u- indicesv- indices- Returns:
- an array of contracted indices
-
containsNonMetric
public static boolean containsNonMetric(Indices indices)
Returnstrueif specified indices contain any index with non metric type.- Parameters:
indices- indices- Returns:
trueif specified indices contain any index with non metric type
-
-
DataMelt 3.0 © DataMelt by jWork.ORG