third_party/inchi/INCHI_BASE/src/strutil.c
int ExtractConnectedComponent( inp_ATOM *at,
                               int num_at,
                               int component_number,
                               inp_ATOM *component_at )
{
    int i, j, num_component_at;
    AT_NUMB *number;

    if (NULL == ( number = (AT_NUMB*) inchi_calloc( num_at, sizeof( AT_NUMB ) ) ))
    {
        return CT_OUT_OF_RAM; /* out of memory */  /*   <BRKPT> */
    }

    /* copy atoms */
    for (i = 0, num_component_at = 0; i < num_at; i++)
    {
        if (at[i].component == component_number)
        {
            number[i] = num_component_at;
            component_at[num_component_at++] = at[i];
        }
    }

    /* renumber neighbors */
    for (i = 0; i < num_component_at; i++)
    {
        component_at[i].orig_compt_at_numb = (AT_NUMB) ( i + 1 );
        for (j = 0; j < component_at[i].valence; j++)
        {
            component_at[i].neighbor[j] = number[(int) component_at[i].neighbor[j]];
        }
    }

    inchi_free( number );

    return num_component_at;
}
/****************************************************************************
Extract one (connected) component
****************************************************************************/
Extract one (connected) component
Extract one ( connected ) component
int ExtractConnectedComponent( inp_ATOM *at,
                               int num_at,
                               int component_number,
                               inp_ATOM *component_at )
{
    int i, j, num_component_at;
    AT_NUMB *number;
    if (NULL == ( number = (AT_NUMB*) inchi_calloc( num_at, sizeof( AT_NUMB ) ) ))
    {
        return CT_OUT_OF_RAM;   
    }
    for (i = 0, num_component_at = 0; i < num_at; i++)
    {
        if (at[i].component == component_number)
        {
            number[i] = num_component_at;
            component_at[num_component_at++] = at[i];
        }
    }
    for (i = 0; i < num_component_at; i++)
    {
        component_at[i].orig_compt_at_numb = (AT_NUMB) ( i + 1 );
        for (j = 0; j < component_at[i].valence; j++)
        {
            component_at[i].neighbor[j] = number[(int) component_at[i].neighbor[j]];
        }
    }
    inchi_free( number );
    return num_component_at;
}
int ExtractConnectedComponent ( inp_ATOM * at , int num_at , int component_number , inp_ATOM * component_at ) { int i , j , num_component_at ; AT_NUMB * number ; if ( NULL == ( number = ( AT_NUMB * ) inchi_calloc ( num_at , sizeof ( AT_NUMB ) ) ) ) { return CT_OUT_OF_RAM ; } for ( i = 0 , num_component_at = 0 ; i < num_at ; i ++ ) { if ( at [ i ] . component == component_number ) { number [ i ] = num_component_at ; component_at [ num_component_at ++ ] = at [ i ] ; } } for ( i = 0 ; i < num_component_at ; i ++ ) { component_at [ i ] . orig_compt_at_numb = ( AT_NUMB ) ( i + 1 ) ; for ( j = 0 ; j < component_at [ i ] . valence ; j ++ ) { component_at [ i ] . neighbor [ j ] = number [ ( int ) component_at [ i ] . neighbor [ j ] ] ; } } inchi_free ( number ) ; return num_component_at ; }
Extract one (connected) component
Extract one ( connected ) component
/* out of memory */ /*   <BRKPT> */ /* copy atoms */ /* renumber neighbors */