Documentation of 'cc.redberry.core.indices.IndicesUtils' Java class
IndicesUtils
cc.redberry.core.indices

Class IndicesUtils



  • public final class IndicesUtils
    extends java.lang.Object
    This 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
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static boolean areContracted(int index0, int index1)
      Indicates whether two indices are contracted (has the same type & name but different states).
      static boolean containsNonMetric(Indices indices)
      Returns true if specified indices contain any index with non metric type.
      static int createIndex(int name, byte type, boolean state)
      Creates single index with specified name, type and state.
      static int createIndex(int name, IndexType type, boolean state)
      Creates single index with specified name, type and state.
      static boolean equalsRegardlessOrder(Indices indices1, int[] indices2) 
      static boolean equalsRegardlessOrder(int[] indices1, int[] indices2) 
      static int[] getFree(int[] indices)
      Returns an array of free indices only
      static int[] getIndicesNames(Indices indices)
      Returns an array of indices names (with types), presented in specified Indices object 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 int getNameWithoutType(int index)
      Returns index name (code) without type.
      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).
      static int getRawStateInt(int index)
      Returns only state (31-th) bit of index without shift.
      static int getRawTypeInt(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 the Indices object.
      static boolean getState(int index)
      Returns state (31-th) bit of index.
      static int getStateInt(int index)
      Returns state (31-th) bit of index shifted to 0-th position.
      static byte getType(int index)
      Returns index type.
      static IndexType getTypeEnum(int index)
      Returns index type enum value.
      static int getTypeInt(int index)
      Returns index type in form 0000000000000000000000000xxxxxxx, where x - type bits.
      static byte getTypeWithState(int index)
      Returns index type with state bit.
      static boolean hasEqualTypeAndName(int index0, int index1)
      Indicates whether two indices has the same type and name.
      static boolean hasEqualTypes(int index0, int index1)
      Indicates whether two indices has the same type.
      static boolean hasEqualTypesAndStates(int index0, int index1)
      Indicates whether two indices has the same type and state.
      static boolean haveEqualStates(int index1, int index2) 
      static boolean haveIntersections(Indices u, Indices v)
      Returns true if at least one free index of u is contracted with some free index of v.
      static int inverseIndexState(int index)
      Returns index with inverse index state.
      static boolean isPermutationConsistentWithIndices(int[] indices, int[] permutation)
      This method checks whether specified permutation is consistent with specified indices.
      static boolean isPermutationConsistentWithIndices(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 int parseIndex(java.lang.String string)
      Parse single index.
      static int setRawState(int rawState, int index)
      Changes index state to specified state of the form 0b1(0)000000.....
      static int setState(boolean state, int index)
      Changes index state to specified state (true - upper, false - lower).
      static int setType(byte type, int index)
      Changes index type to specified, represented by byte.
      static int setType(IndexType type, int index)
      Changes index type to specified, represented by byte.
      static java.lang.String toString(int index) 
      static java.lang.String toString(int[] indices) 
      static java.lang.String toString(int[] indices, OutputFormat mode) 
      static java.lang.String toString(int index, OutputFormat mode) 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 name
        type - index type
        state - 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 name
        type - index type
        state - 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 - type
        index - 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 - IndexType
        index - 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 state
        index - 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 index
        index1 - 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 index
        index1 - 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 index
        index1 - 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 index
        index1 - 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 the Indices object.
        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 specified Indices object 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 checked
        permutation - permutation in one-line notation
        Returns:
        false if 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 checked
        permutation - permutation in one-line notation
        Returns:
        false if 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 of u is contracted with some free index of v.
        Parameters:
        u - indices
        v - indices
        Returns:
        true if at least one free index of u is contracted with some free index of v
      • getIntersections

        public static int[] getIntersections(int[] freeIndices1,
                                             int[] freeIndices2)
        Returns an array of contracted indices between specified free indices.
        Parameters:
        freeIndices1 - free indices
        freeIndices2 - 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 - indices
        v - indices
        Returns:
        an array of contracted indices
      • containsNonMetric

        public static boolean containsNonMetric(Indices indices)
        Returns true if specified indices contain any index with non metric type.
        Parameters:
        indices - indices
        Returns:
        true if specified indices contain any index with non metric type
      • nonMetricTypes

        public static java.util.EnumSet<IndexType> nonMetricTypes(Indices indices)
        Returns all non metric types that present in specified indices.
        Parameters:
        indices - indices
        Returns:
        all non metric types that present in specified indices

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.