@Override public double eval(int id1,int id2,Instance inst1) throws Exception {
  double result=0;
  long key=-1;
  int location=-1;
  if ((id1 >= 0) && (m_cacheSize != -1)) {
    if (m_cacheSize == 0) {
      if (m_kernelMatrix == null) {
        m_kernelMatrix=new double[m_data.numInstances()][];
        for (int i=0; i < m_data.numInstances(); i++) {
          m_kernelMatrix[i]=new double[i + 1];
          for (int j=0; j <= i; j++) {
            m_kernelEvals++;
            m_kernelMatrix[i][j]=evaluate(i,j,m_data.instance(i));
          }
        }
      }
      m_cacheHits++;
      result=(id1 > id2) ? m_kernelMatrix[id1][id2] : m_kernelMatrix[id2][id1];
      return result;
    }
    if (id1 > id2) {
      key=(id1 + ((long)id2 * m_numInsts));
    }
 else {
      key=(id2 + ((long)id1 * m_numInsts));
    }
    location=(int)(key % m_cacheSize) * m_cacheSlots;
    int loc=location;
    for (int i=0; i < m_cacheSlots; i++) {
      long thiskey=m_keys[loc];
      if (thiskey == 0) {
        break;
      }
      if (thiskey == (key + 1)) {
        m_cacheHits++;
        if (i > 0) {
          double tmps=m_storage[loc];
          m_storage[loc]=m_storage[location];
          m_keys[loc]=m_keys[location];
          m_storage[location]=tmps;
          m_keys[location]=thiskey;
          return tmps;
        }
 else {
          return m_storage[loc];
        }
      }
      loc++;
    }
  }
  result=evaluate(id1,id2,inst1);
  m_kernelEvals++;
  if ((key != -1) && (m_cacheSize != -1)) {
    System.arraycopy(m_keys,location,m_keys,location + 1,m_cacheSlots - 1);
    System.arraycopy(m_storage,location,m_storage,location + 1,m_cacheSlots - 1);
    m_storage[location]=result;
    m_keys[location]=(key + 1);
  }
  return result;
}

@ Override public double eval ( int id1 , int id2 , Instance inst1 ) throws Exception { double result = 0 ; long key = - 1 ; int location = - 1 ; if ( ( id1 >= 0 ) && ( m_cacheSize != - 1 ) ) { if ( m_cacheSize == 0 ) { if ( m_kernelMatrix == null ) { m_kernelMatrix = new double [ m_data . numInstances ( ) ] [ ] ; for ( int i = 0 ; i < m_data . numInstances ( ) ; i ++ ) { m_kernelMatrix [ i ] = new double [ i + 1 ] ; for ( int j = 0 ; j <= i ; j ++ ) { m_kernelEvals ++ ; m_kernelMatrix [ i ] [ j ] = evaluate ( i , j , m_data . instance ( i ) ) ; } } } m_cacheHits ++ ; result = ( id1 > id2 ) ? m_kernelMatrix [ id1 ] [ id2 ] : m_kernelMatrix [ id2 ] [ id1 ] ; return result ; } if ( id1 > id2 ) { key = ( id1 + ( ( long ) id2 * m_numInsts ) ) ; } else { key = ( id2 + ( ( long ) id1 * m_numInsts ) ) ; } location = ( int ) ( key % m_cacheSize ) * m_cacheSlots ; int loc = location ; for ( int i = 0 ; i < m_cacheSlots ; i ++ ) { long thiskey = m_keys [ loc ] ; if ( thiskey == 0 ) { break ; } if ( thiskey == ( key + 1 ) ) { m_cacheHits ++ ; if ( i > 0 ) { double tmps = m_storage [ loc ] ; m_storage [ loc ] = m_storage [ location ] ; m_keys [ loc ] = m_keys [ location ] ; m_storage [ location ] = tmps ; m_keys [ location ] = thiskey ; return tmps ; } else { return m_storage [ loc ] ; } } loc ++ ; } } result = evaluate ( id1 , id2 , inst1 ) ; m_kernelEvals ++ ; if ( ( key != - 1 ) && ( m_cacheSize != - 1 ) ) { System . arraycopy ( m_keys , location , m_keys , location + 1 , m_cacheSlots - 1 ) ; System . arraycopy ( m_storage , location , m_storage , location + 1 , m_cacheSlots - 1 ) ; m_storage [ location ] = result ; m_keys [ location ] = ( key + 1 ) ; } return result ; }
implements the abstract function of kernel using the cache . this method uses the evaluate ( ) method to do the actual dot product .
