content: /*
   * Tencent is pleased to support the open source community by making Angel available.
   *
   * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in 
   * compliance with the License. You may obtain a copy of the License at
   *
   * https://opensource.org/licenses/Apache-2.0
   *
   * Unless required by applicable law or agreed to in writing, software distributed under the License
   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
   * or implied. See the License for the specific language governing permissions and limitations under
   * the License.
   *
   */
  
  
  package com.tencent.angel.ml.matrix;
  
  /**
   * Model row type
   */
  public enum RowType {
  
    T_DOUBLE_DENSE(0, RowType.T_DOUBLE_DENSE_VALUE), T_DOUBLE_DENSE_COMPONENT(1,
        RowType.T_DOUBLE_DENSE_COMPONENT_VALUE), T_DOUBLE_DENSE_LONGKEY_COMPONENT(2,
        RowType.T_DOUBLE_DENSE_LONGKEY_COMPONENT_VALUE), T_DOUBLE_SPARSE(3,
        RowType.T_DOUBLE_SPARSE_VALUE), T_DOUBLE_SPARSE_COMPONENT(4,
        RowType.T_DOUBLE_SPARSE_COMPONENT_VALUE), T_DOUBLE_SPARSE_LONGKEY(5,
        RowType.T_DOUBLE_SPARSE_LONGKEY_VALUE), T_DOUBLE_SPARSE_LONGKEY_COMPONENT(6,
        RowType.T_DOUBLE_SPARSE_LONGKEY_COMPONENT_VALUE),
  
    T_FLOAT_DENSE(7, RowType.T_FLOAT_DENSE_VALUE), T_FLOAT_DENSE_COMPONENT(8,
        RowType.T_FLOAT_DENSE_COMPONENT_VALUE), T_FLOAT_DENSE_LONGKEY_COMPONENT(9,
        RowType.T_FLOAT_DENSE_LONGKEY_COMPONENT_VALUE), T_FLOAT_SPARSE(10,
        RowType.T_FLOAT_SPARSE_VALUE), T_FLOAT_SPARSE_COMPONENT(11,
        RowType.T_FLOAT_SPARSE_COMPONENT_VALUE), T_FLOAT_SPARSE_LONGKEY(12,
        RowType.T_FLOAT_SPARSE_LONGKEY_VALUE), T_FLOAT_SPARSE_LONGKEY_COMPONENT(13,
        RowType.T_FLOAT_SPARSE_LONGKEY_COMPONENT_VALUE),
  
    T_LONG_DENSE(14, RowType.T_LONG_DENSE_VALUE), T_LONG_DENSE_COMPONENT(15,
        RowType.T_LONG_DENSE_COMPONENT_VALUE), T_LONG_DENSE_LONGKEY_COMPONENT(16,
        RowType.T_LONG_DENSE_LONGKEY_COMPONENT_VALUE), T_LONG_SPARSE(17,
        RowType.T_LONG_SPARSE_VALUE), T_LONG_SPARSE_COMPONENT(18,
        RowType.T_LONG_SPARSE_COMPONENT_VALUE), T_LONG_SPARSE_LONGKEY(19,
        RowType.T_LONG_SPARSE_LONGKEY_VALUE), T_LONG_SPARSE_LONGKEY_COMPONENT(20,
        RowType.T_LONG_SPARSE_LONGKEY_COMPONENT_VALUE),
  
    T_INT_DENSE(21, RowType.T_INT_DENSE_VALUE), T_INT_DENSE_COMPONENT(22,
        RowType.T_INT_DENSE_COMPONENT_VALUE), T_INT_DENSE_LONGKEY_COMPONENT(23,
        RowType.T_INT_DENSE_LONGKEY_COMPONENT_VALUE), T_INT_SPARSE(24,
        RowType.T_INT_SPARSE_VALUE), T_INT_SPARSE_COMPONENT(25,
        RowType.T_INT_SPARSE_COMPONENT_VALUE), T_INT_SPARSE_LONGKEY(26,
        RowType.T_INT_SPARSE_LONGKEY_VALUE), T_INT_SPARSE_LONGKEY_COMPONENT(27,
        RowType.T_INT_SPARSE_LONGKEY_COMPONENT_VALUE),
  
    T_ANY_INTKEY_DENSE(28, RowType.T_ANY_INTKEY_DENSE_VALUE),
    T_ANY_INTKEY_SPARSE(29, RowType.T_ANY_INTKEY_SPARSE_VALUE),
    T_ANY_LONGKEY_SPARSE(30, RowType.T_ANY_LONGKEY_SPARSE_VALUE),
    T_ANY_STRINGKEY_SPARSE(31, RowType.T_ANY_STRINGKEY_SPARSE_VALUE),
    T_ANY_ANYKEY_SPARSE(32, RowType.T_ANY_ANYKEY_SPARSE_VALUE);
  
  
    public static final int T_DOUBLE_DENSE_VALUE = 0;
    public static final int T_DOUBLE_DENSE_COMPONENT_VALUE = 1;
    public static final int T_DOUBLE_DENSE_LONGKEY_COMPONENT_VALUE = 2;
    public static final int T_DOUBLE_SPARSE_VALUE = 3;
    public static final int T_DOUBLE_SPARSE_COMPONENT_VALUE = 4;
    public static final int T_DOUBLE_SPARSE_LONGKEY_VALUE = 5;
    public static final int T_DOUBLE_SPARSE_LONGKEY_COMPONENT_VALUE = 6;
    public static final int T_FLOAT_DENSE_VALUE = 7;
    public static final int T_FLOAT_DENSE_COMPONENT_VALUE = 8;
    public static final int T_FLOAT_DENSE_LONGKEY_COMPONENT_VALUE = 9;
    public static final int T_FLOAT_SPARSE_VALUE = 10;
    public static final int T_FLOAT_SPARSE_COMPONENT_VALUE = 11;
    public static final int T_FLOAT_SPARSE_LONGKEY_VALUE = 12;
    public static final int T_FLOAT_SPARSE_LONGKEY_COMPONENT_VALUE = 13;
    public static final int T_LONG_DENSE_VALUE = 14;
    public static final int T_LONG_DENSE_COMPONENT_VALUE = 15;
    public static final int T_LONG_DENSE_LONGKEY_COMPONENT_VALUE = 16;
    public static final int T_LONG_SPARSE_VALUE = 17;
    public static final int T_LONG_SPARSE_COMPONENT_VALUE = 18;
    public static final int T_LONG_SPARSE_LONGKEY_VALUE = 19;
    public static final int T_LONG_SPARSE_LONGKEY_COMPONENT_VALUE = 20;
    public static final int T_INT_DENSE_VALUE = 21;
    public static final int T_INT_DENSE_COMPONENT_VALUE = 22;
    public static final int T_INT_DENSE_LONGKEY_COMPONENT_VALUE = 23;
    public static final int T_INT_SPARSE_VALUE = 24;
    public static final int T_INT_SPARSE_COMPONENT_VALUE = 25;
    public static final int T_INT_SPARSE_LONGKEY_VALUE = 26;
    public static final int T_INT_SPARSE_LONGKEY_COMPONENT_VALUE = 27;
    public static final int T_ANY_INTKEY_DENSE_VALUE = 28;
    public static final int T_ANY_INTKEY_SPARSE_VALUE = 29;
    public static final int T_ANY_LONGKEY_SPARSE_VALUE = 30;
    public static final int T_ANY_STRINGKEY_SPARSE_VALUE = 31;
    public static final int T_ANY_ANYKEY_SPARSE_VALUE = 32;
    //public static final int T_INT_ARBITRARY_VALUE = 28;
    //public static final int T_INVALID_VALUE = 29;
  
    public final int getNumber() {
      return value;
    }
  
    public final boolean isDouble() {
      return value / 7 == 0;
    }
  
    public final boolean isFloat() {
      return  value / 7 == 1;
    }
  
    public final boolean isLong() {
      return  value / 7 == 2;
    }
  
    public final boolean isInt() {
      return value / 7 == 3;
    }
  
    public final boolean isSparse() {
      return (value < 28 && value % 7 >= 3) || (value == 29) || (value == 30);
    }
  
    public final boolean isDense() {
      return (value < 28 && value % 7 < 3) || (value == 28);
    }
  
    public final boolean isComp() {
      return value == T_DOUBLE_DENSE_COMPONENT_VALUE ||
          value == T_DOUBLE_DENSE_LONGKEY_COMPONENT_VALUE ||
          value == T_DOUBLE_SPARSE_COMPONENT_VALUE ||
          value == T_DOUBLE_SPARSE_LONGKEY_COMPONENT_VALUE ||
          value == T_FLOAT_DENSE_COMPONENT_VALUE ||
          value == T_FLOAT_DENSE_LONGKEY_COMPONENT_VALUE ||
          value == T_FLOAT_SPARSE_COMPONENT_VALUE ||
          value == T_FLOAT_SPARSE_LONGKEY_COMPONENT_VALUE ||
          value == T_LONG_DENSE_COMPONENT_VALUE ||
          value == T_LONG_DENSE_LONGKEY_COMPONENT_VALUE ||
          value == T_LONG_SPARSE_COMPONENT_VALUE ||
          value == T_LONG_SPARSE_LONGKEY_COMPONENT_VALUE ||
          value == T_INT_DENSE_COMPONENT_VALUE ||
          value == T_INT_DENSE_LONGKEY_COMPONENT_VALUE ||
          value == T_INT_SPARSE_COMPONENT_VALUE ||
          value == T_INT_SPARSE_LONGKEY_COMPONENT_VALUE;
    }
  
    public final boolean isLongKey(){
      int r = value % 7;
      return (value < 28 && (r == 2 || r == 5 || r == 6)) || (value == 30);
    }
  
    public final boolean isIntKey() {
      int r = value % 7;
      return (value < 28 && r < 5 && r != 2) || (value == 28) || (value == 29);
    }
  
  
    public boolean isComplexValue() {
      return value >= 28;
    }
  
    public boolean isStringKey() {
      return value == 31;
    }
  
    public boolean isComplexKey() {
      return value == 32;
    }
  
    public final boolean narrowerThen(RowType other){
      return this.value / 7 <= other.value / 7 && other.value < 28;
    }
  
    public final boolean sameKeyType(RowType other) {
      return (this.isIntKey() && other.isIntKey()) || (this.isLongKey() && other.isLongKey());
    }
  
    public final boolean compatible(RowType other){
      return narrowerThen(other) && sameKeyType(other);
    }
  
  
  
    public static RowType valueOf(int value) {
      switch (value) {
        case T_DOUBLE_DENSE_VALUE:
          return T_DOUBLE_DENSE;
        case T_DOUBLE_DENSE_COMPONENT_VALUE:
          return T_DOUBLE_DENSE_COMPONENT;
        case T_DOUBLE_DENSE_LONGKEY_COMPONENT_VALUE:
          return T_DOUBLE_DENSE_LONGKEY_COMPONENT;
        case T_DOUBLE_SPARSE_VALUE:
          return T_DOUBLE_SPARSE;
        case T_DOUBLE_SPARSE_COMPONENT_VALUE:
          return T_DOUBLE_SPARSE_COMPONENT;
        case T_DOUBLE_SPARSE_LONGKEY_VALUE:
          return T_DOUBLE_SPARSE_LONGKEY;
        case T_DOUBLE_SPARSE_LONGKEY_COMPONENT_VALUE:
          return T_DOUBLE_SPARSE_LONGKEY_COMPONENT;
        case T_FLOAT_DENSE_VALUE:
          return T_FLOAT_DENSE;
        case T_FLOAT_DENSE_COMPONENT_VALUE:
          return T_FLOAT_DENSE_COMPONENT;
        case T_FLOAT_DENSE_LONGKEY_COMPONENT_VALUE:
          return T_FLOAT_DENSE_LONGKEY_COMPONENT;
        case T_FLOAT_SPARSE_VALUE:
          return T_FLOAT_SPARSE;
        case T_FLOAT_SPARSE_COMPONENT_VALUE:
          return T_FLOAT_SPARSE_COMPONENT;
        case T_FLOAT_SPARSE_LONGKEY_VALUE:
          return T_FLOAT_SPARSE_LONGKEY;
        case T_FLOAT_SPARSE_LONGKEY_COMPONENT_VALUE:
          return T_FLOAT_SPARSE_LONGKEY_COMPONENT;
        case T_LONG_DENSE_VALUE:
          return T_LONG_DENSE;
        case T_LONG_DENSE_COMPONENT_VALUE:
          return T_LONG_DENSE_COMPONENT;
        case T_LONG_DENSE_LONGKEY_COMPONENT_VALUE:
          return T_LONG_DENSE_LONGKEY_COMPONENT;
        case T_LONG_SPARSE_VALUE:
          return T_LONG_SPARSE;
        case T_LONG_SPARSE_COMPONENT_VALUE:
          return T_LONG_SPARSE_COMPONENT;
        case T_LONG_SPARSE_LONGKEY_VALUE:
          return T_LONG_SPARSE_LONGKEY;
        case T_LONG_SPARSE_LONGKEY_COMPONENT_VALUE:
          return T_LONG_SPARSE_LONGKEY_COMPONENT;
        case T_INT_DENSE_VALUE:
          return T_INT_DENSE;
        case T_INT_DENSE_COMPONENT_VALUE:
          return T_INT_DENSE_COMPONENT;
        case T_INT_DENSE_LONGKEY_COMPONENT_VALUE:
          return T_INT_DENSE_LONGKEY_COMPONENT;
        case T_INT_SPARSE_VALUE:
          return T_INT_SPARSE;
        case T_INT_SPARSE_COMPONENT_VALUE:
          return T_INT_SPARSE_COMPONENT;
        case T_INT_SPARSE_LONGKEY_VALUE:
          return T_INT_SPARSE_LONGKEY;
        case T_INT_SPARSE_LONGKEY_COMPONENT_VALUE:
          return T_INT_SPARSE_LONGKEY_COMPONENT;
        case T_ANY_INTKEY_DENSE_VALUE:
          return T_ANY_INTKEY_DENSE;
        case T_ANY_INTKEY_SPARSE_VALUE:
          return T_ANY_INTKEY_SPARSE;
        case T_ANY_LONGKEY_SPARSE_VALUE:
          return T_ANY_LONGKEY_SPARSE;
        case T_ANY_STRINGKEY_SPARSE_VALUE:
          return T_ANY_STRINGKEY_SPARSE;
        case T_ANY_ANYKEY_SPARSE_VALUE:
          return T_ANY_ANYKEY_SPARSE;
        default:
          return null;
      }
    }
  
    private final int index;
    private final int value;
  
    RowType(int index, int value) {
      this.index = index;
      this.value = value;
    }
  }
  