Esempio n. 1
0
void RealLocalGarbage::collectBag(Bag &bag) {
    for (auto f : bag) {
        f();
    }
    // XXX: should we shrink capacity?
    bag.clear();
}
Esempio n. 2
0
int main()
{
	model = new Wrapper(new SimpleModel());
	Simulator<External*>* sim = new Simulator<External*>(model);
	Listener* l = new Listener();
	sim->addEventListener(l);
	// First input/output series. Internal event test.
	l->setExpected(1.0,FAST,1);
	Event<External*> e;
	e.model = model;
	e.value = new External(FAST,1);
	Bag<Event<External*> > x;
	x.insert(e);
	sim->computeNextState(x,0.0);
	assert(sim->nextEventTime() == 1.0);
	sim->execNextEvent();
	assert(output_happened);
	output_happened = false;
	// Second input/output series. External event test.
	l->setExpected(3.5,SLOW,1);
	x.clear();
	e.value = new External(SLOW,1);
	x.insert(e);
	sim->computeNextState(x,1.5);
	assert(!output_happened);
	assert(sim->nextEventTime() == 3.5);
	sim->execNextEvent();
	assert(output_happened);
	output_happened = false;
	// Third input/output series. Confluent event test
	l->setExpected(5.5,SLOW,2);
	x.clear();
	e.value = new External(STOP,1);
	x.insert(e);
	assert(sim->nextEventTime() == 5.5);
	sim->computeNextState(x,sim->nextEventTime());
	assert(output_happened);
	assert(sim->nextEventTime() == DBL_MAX);
	// Done. Try to clean up.
	assert(External::num_existing == 3);
	delete model;
	delete l;
	delete sim;
	assert(Internal::num_existing == 0);
	return 0;
}
Esempio n. 3
0
int main()
{
    Bag b;
//  Bag a(10); //*
    bag_type value;
    
    cout << "Let's create a bag with only one element: " << endl;
    b.insert(5); //inserts one element into the bag
    cout << b.size() << " element(s) in bag the bag." << endl;
    b.clear();
    cout << b.size() << " element(s) in the bag after b.clear()." << endl;
    
    do {
        value = rand() % 6 + 1;
    } while(b.insert(value));
    cout << b.size() << " element(s) in the bag." << endl;
    b.clear();
    cout << b.size() << " element(s) in the bag after b.clear()." << endl;
}
Esempio n. 4
0
Bag Board::tilesOnBoard() const
{
	Bag ret;
	ret.clear();

	for (int row = 0; row < m_height; row++)
	{
		for (int col = 0; col < m_width; col++)
		{
			if (m_letters[row][col] != QUACKLE_NULL_MARK)
			{
				LetterString letters;
				letters += m_isBlank[row][col]? QUACKLE_BLANK_MARK : m_letters[row][col];
				ret.toss(letters);
			}
		}
	}

	return ret;
}