Esempio n. 1
0
void UnitCollection::UnitIterator::moveBefore( UnitCollection &otherlist )
{
    if ( col && it != col->u.end() ) {
        otherlist.prepend( *it );
        col->erase( it );
    }
}
int main()
{
    Unit  *unit;
    srand( time( NULL ) );
    UnitCollection *c = new UnitCollection;
    Unit  *u[SIZE];
    time_t seconds;
    for (int i = 0; i < SIZE; ++i)
        u[i] = createUnit();
    seconds = time( NULL );
    for (int i = 0; i < (SIZE/2); ++i)
        c->prepend( u[i] );
    seconds = time( NULL )-seconds;
    printf( "constructed list of size : %d  in %d seconds using prepend\n", SIZE/2, seconds );
    printf( "Randomnly inserting %d \n", SIZE/2 );
    int ii = SIZE/2;
    seconds = time( NULL );
    while (ii < SIZE)
        for (un_iter iter = c->createIterator(); !iter.isDone() && ii < SIZE; ++iter) {
            int rnd = rand();
            if (rnd < RAND_MAX/200) {
                iter.postinsert( u[ii] );
                ++ii;
            } else if (rnd < RAND_MAX/100) {
                iter.preinsert( u[ii] );
                ++ii;
            }
        }
    seconds = time( NULL )-seconds;
    printf( ".... took %d seconds \n", seconds );
    for (int i = 0; i < SIZE/32; ++i)
        if (rand() < RAND_MAX/20)
            u[i]->Kill();
    printf( "randomly killed SIZE/32 to start off with \n" );

    printf( "beginning unitCollection removal/advance operations\n" );
    seconds = time( NULL );
    int passes = 0;
    int levels = 0;
    while ( !c->empty() ) {
        ++passes;
        Iteration( c, &levels );
#if !oldtest
    }
#else
        UnitCollection::FreeUnusedNodes();
    }
void UnitCollection::UnitIterator::moveBefore( UnitCollection &otherList )
{
    if (pos->next->unit) {
        UnitListNode *tmp = pos->next->next;
        otherList.prepend( pos->next );
        pos->next = tmp;
    } else {
        assert( 0 );
    }
}