예제 #1
0
파일: match.c 프로젝트: pombredanne/nmergec
/**
 * Find deepest level of the match that has a queue
 * @param m the first in a chain of matches
 * @return the topmost match with a queue
 */
static match *match_deepest_queued( match *m )
{
    int i;
    if ( m->next != NULL )
    {
        dyn_array *da = dyn_array_create( 5 );
        if ( da != NULL )
        {
            match *temp = m;
            while ( temp != NULL )
            {
                dyn_array_add( da, temp );
                temp = temp->next;
            }
            for ( i=dyn_array_size(da)-1;i>=0;i-- )
            {
                match *n = dyn_array_get(da,i);
                if ( n->queue != NULL )
                {
                    m = n;
                    // clean up any non-queued matches
                    if ( m->next != NULL )
                        match_dispose( m->next );
                    m->next = NULL;
                    break;
                }
            }
            dyn_array_dispose( da );
        }
    }
    return m;
}
예제 #2
0
파일: card.c 프로젝트: pombredanne/nmergec
/**
 * Convert a list of cards to a standard pair array
 * @param c the head of the card list
 * @return an allocated dynamic array of pairs or NULL
 */
dyn_array *card_to_pairs( card *c )
{
    int npairs = card_list_len(c);
    dyn_array *da = dyn_array_create( npairs );
    if ( da != NULL )
    {
        while ( c != NULL )
        {
            dyn_array_add( da, c->p );
            c = c->right;
        }
    }
    return da;
}
예제 #3
0
// Creates a dynamic array from a standard array
dyn_array_t *dyn_array_import(const void *const data, const size_t count, const size_t data_type_size, void (*destruct_func)(void *)) {
    // Oh boy I'm going to be lazy with this
    dyn_array_t *dyn_array = NULL;
    // literally could not give us an overlapping pointer unless they guessed it
    // I'd just do a memcpy here instead of dyn_shift, but the dyn_shift branch for this is
    // short. DYN_SHIFT CANNOT fail if create worked properly, but we'll cleanup if it did anyway
    if (data && (dyn_array = dyn_array_create(count, data_type_size, destruct_func))) {
        if (count && !dyn_shift(dyn_array, 0, count, CREATE_GAP, (void *const) data)) {
            dyn_array_destroy(dyn_array);
            dyn_array = NULL;
        }
    }
    return dyn_array;
}