bool addRecursive(CuckooMap* map, uint64_t key, uint64_t value, int depth)
{
	if(depth > MAX_LOOP)
	{
		return false;
	}
	//if its empty in the first table, add it there
	if(getKey1(map, key) == NONE)
	{
		set1(map, key, value);
	}
	//if its empty in the second table, add it there
	else if(getKey2(map, key) == NONE)
	{
		set2(map, key, value);
	}
	//if both are occupied, randomly displace one and re-add the displaced one
	else if((xorshf96() & 1) == 0)
	{
		uint64_t pushedKey = getKey1(map, key);
		uint64_t pushedValue = getValue1(map, key);
		set1(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	else
	{
		uint64_t pushedKey = getKey2(map, key);
		uint64_t pushedValue = getValue2(map, key);
		set2(map, key, value);
		return addRecursive(map, pushedKey, pushedValue, depth + 1);
	}
	return true;
}
Example #2
0
Move OpenBook::nextMove(const Board & board)
{
  MovesLine valid_moves;

  for (size_t i = 0; i < mtable_.size(); ++i)
  {
    MovesLine & mline = mtable_[i];
    size_t j = 0;
    for ( ; j < board.halfmovesCount() && j < mline.size(); ++j)
    {
      Move mv = board.undoInfo((int)j);
      if ( mv != mline[j] )
        j = mline.size();
    }

    if ( j < mline.size() )
    {
      const Move & m = mline[j];
      valid_moves.push_back(m);
    }
  }

  Move mres;
  mres.clear();

  if ( valid_moves.empty() )
    return mres;

  size_t n = xorshf96() % valid_moves.size();
  mres = valid_moves[n];

  return mres;
}
Example #3
0
inline void wait(unsigned long time_in_us){
#ifdef NB_WAIT_RANDOM
  time_in_us=xorshf96()%time_in_us;
#endif
  unsigned long long before_time, after_time;
  before_time=getusec();
  do{
    after_time=getusec();
  } while (after_time-before_time<time_in_us);
}
Example #4
0
File: share.c Project: coron/htable
void refresh(byte a[],int n)
{
  int i;
  for(i=1;i<n;i++)
  {
    byte tmp=xorshf96(); //rand();
    a[0]=a[0] ^ tmp;
    a[i]=a[i] ^ tmp;
  }
}
Example #5
0
void refreshword(word a[],int n)
{
  int i;
  word tmp;
  for(i=1;i<n;i++)
  {
    tmp=xorshf96(); //rand();
    a[0]=a[0] ^ tmp;
    a[i]=a[i] ^ tmp;
  }
}
Example #6
0
int drand(void) {
    return (xorshf96() % 7) + 2;
}
Example #7
0
int rand(void) {
    return (xorshf96() % mod) + 1;
}