示例#1
0
treeLink insertRandom (treeLink currTree, Item item) {
    Key currKey = key (currTree->item);
    if (currTree == emptyTree) {
        return NEW (item, emptyTree, emptyTree, 1);
    }
    if (rand () < RAND_MAX/(currTree->size+1)) {
        return (insertRoot (currTree, item));
    } else if (less (key (item), currKey)) {
        insertRandom (currTree->left, item);
    } else {
        insertRandom (currTree->right, item);
    }
    currTree->size++;
    return currTree;
} 
示例#2
0
void ParticleSystem::addParticle(float t)
{
	if (isFull())
		return;

	// Gets a free particle and updates the allocation pointer.
	Particle *p = pFree++;
	initParticle(p, t);

	switch (insertMode)
	{
	default:
	case INSERT_MODE_TOP:
		insertTop(p);
		break;
	case INSERT_MODE_BOTTOM:
		insertBottom(p);
		break;
	case INSERT_MODE_RANDOM:
		insertRandom(p);
		break;
	}

	activeParticles++;
}
void gMatrixSparse::set(int row, int col, double value)
{
    int i;
    if (getIndex(row, col, i)) {
        insertRandom(row, col, value, i);
    } else {
        if (fabs(value) < eps) {
            removeRandom(col, i);
        } else {
            vals[i] = value;
        }
    }
}
示例#4
0
static void addParticle(graphics_ParticleSystem *ps, float t) {
  graphics_Particle *p = ps->pFree++;
  initParticle(ps, p, t);

  switch(ps->insertMode) {
  case graphics_ParticleInsertMode_top:
    insertTop(ps, p);
    break;
  case graphics_ParticleInsertMode_bottom:
    insertBottom(ps, p);
    break;
  case graphics_ParticleInsertMode_random:
    insertRandom(ps, p);
    break;
  }

  ++ps->activeParticles;
}