/*
 * Copyright (C) 2008 The Trustees of Columbia University in the City of New York. 
 * All rights reserved.
 *
 * See the file LICENSE included in this distribution for details.
 */

#include "kaddist.h"
#include <math.h>

KadDist::KadDist() {
  
}


KadDist::~KadDist () {
  
}

/*
inline int32 pow(int32 base, int32 exp) {
  int32 result=1;
  for(int i=0; i<exp;i++) {
    result = base * result;
  }
  return result;
}
*/

int32 KadDist::getKeyAt(uint32 iPos, BigInt& objKey) {
  
  BigInt temp, pow, max;
  uint32 bit, base;


  if(iPos >= m_uiKeyLen) {
    objKey = m_objKey;
    return 0;
  }

  //the key
  objKey = m_objKey;

  //base
  base= (uint32) ((float)log((float)m_uiBase) / (float)log((float)2));

  objKey.getBitAt(iPos*base, bit);
  if(0 == bit) bit =1; else bit=0;

  objKey.setBitAt(iPos*base, bit);
  
  return 0;
  
}//getKeyAt


int32 KadDist::getDistance( BigInt& src,  BigInt& dst, BigInt& result) {
  result = src ^ dst;  
  return 1;  
}//getDistance
