third_party/inchi/INCHI_BASE/src/ichican2.c
int bCanonIsFinerThanEquitablePartition( int num_atoms,
                                         sp_ATOM* at,
                                         AT_RANK *nSymmRank )
{
    AT_RANK *nRank = NULL;
    AT_RANK *nAtomNumber = NULL;
    AT_RANK *nTempRank = NULL;
    AT_RANK nCurSymm, nCurRank;
    ATOM_INVARIANT2 *pAtomInvariant = NULL;
    NEIGH_LIST      *NeighList = NULL;

    int              nNumCurrRanks, i, is, ir, j;
    long             lCount;
    int              bIsNotSame = 0;

    if (at && nSymmRank)
    {
        if (!( nRank = (AT_RANK*) inchi_calloc( num_atoms, sizeof( nRank[0] ) ) ) ||
             !( nAtomNumber = (AT_RANK*) inchi_calloc( num_atoms, sizeof( nAtomNumber[0] ) ) ) ||
             !( nTempRank = (AT_RANK*) inchi_calloc( num_atoms, sizeof( nTempRank[0] ) ) ) ||
             !( pAtomInvariant = (ATOM_INVARIANT2 *) inchi_calloc( num_atoms, sizeof( pAtomInvariant[0] ) ) )
            )
        {
            goto exit_err;
        }
        if (!( NeighList = CreateNeighList( num_atoms, num_atoms, at, 0, NULL ) ))
        {
            goto exit_err;
        }

        FillOutAtomInvariant2( at,
                               num_atoms,
                               num_atoms,
                               pAtomInvariant,
                               1 /*bIgnoreIsotopic*/,
                               1 /*bHydrogensInRanks*/,
                               1 /*bHydrogensFixedInRanks*/,
                               0 /*bTaut=bDigraph*/,
                               0 /* bTautGroupsOnly */,
                               NULL /*t_group_info*/ );

        /* initial partitioning of a hydrogenless skeleton: create equitable partition (assign initial ranks) */
        nNumCurrRanks = SetInitialRanks2( num_atoms, pAtomInvariant, nRank, nAtomNumber, pCG );

        lCount = 0;
        /* make equitable partition in pBCN->pRankStack[0,1] */
        nNumCurrRanks = DifferentiateRanks2( pCG, num_atoms, NeighList,
                                            nNumCurrRanks, nRank,
                                            nTempRank, nAtomNumber, &lCount, 0 /* 0 means use qsort */ );


        /* at this point the equitable partition is in nRank; the order of atoms is in nAtomNumber*/
        /* compare */
        nCurSymm = nCurRank = 0;
        for (i = 0; i < num_atoms; i++)
        {
            j = (int) nAtomNumber[i];
            if (nCurSymm != nSymmRank[j])
            {
                nCurSymm = nSymmRank[j];
                is = i;
            }
            if (nCurRank != nRank[j])
            {
                nCurRank = nRank[j];
                ir = i;
            }
            if (is != ir)
            {
                bIsNotSame = 1;
                break;
            }
        }
    }

exit_err:
    if (nRank)
        inchi_free( nRank );
    if (nAtomNumber)
        inchi_free( nAtomNumber );
    if (nTempRank)
        inchi_free( nTempRank );
    if (pAtomInvariant)
        inchi_free( pAtomInvariant );
    if (NeighList)
        FreeNeighList( NeighList );

    return bIsNotSame;
}
/****************************************************************************
 debug: find whether canonical equivalence is
 different from equitable partition
****************************************************************************/
find whether canonical equivalence is
different from equitable partition
find whether canonical equivalence is different from equitable partition
int bCanonIsFinerThanEquitablePartition( int num_atoms,
                                         sp_ATOM* at,
                                         AT_RANK *nSymmRank )
{
    AT_RANK *nRank = NULL;
    AT_RANK *nAtomNumber = NULL;
    AT_RANK *nTempRank = NULL;
    AT_RANK nCurSymm, nCurRank;
    ATOM_INVARIANT2 *pAtomInvariant = NULL;
    NEIGH_LIST      *NeighList = NULL;
    int              nNumCurrRanks, i, is, ir, j;
    long             lCount;
    int              bIsNotSame = 0;
    if (at && nSymmRank)
    {
        if (!( nRank = (AT_RANK*) inchi_calloc( num_atoms, sizeof( nRank[0] ) ) ) ||
             !( nAtomNumber = (AT_RANK*) inchi_calloc( num_atoms, sizeof( nAtomNumber[0] ) ) ) ||
             !( nTempRank = (AT_RANK*) inchi_calloc( num_atoms, sizeof( nTempRank[0] ) ) ) ||
             !( pAtomInvariant = (ATOM_INVARIANT2 *) inchi_calloc( num_atoms, sizeof( pAtomInvariant[0] ) ) )
            )
        {
            goto exit_err;
        }
        if (!( NeighList = CreateNeighList( num_atoms, num_atoms, at, 0, NULL ) ))
        {
            goto exit_err;
        }
        FillOutAtomInvariant2( at,
                               num_atoms,
                               num_atoms,
                               pAtomInvariant,
                               1 ,
                               1 ,
                               1 ,
                               0 ,
                               0 ,
                               NULL  );
        nNumCurrRanks = SetInitialRanks2( num_atoms, pAtomInvariant, nRank, nAtomNumber, pCG );
        lCount = 0;
        nNumCurrRanks = DifferentiateRanks2( pCG, num_atoms, NeighList,
                                            nNumCurrRanks, nRank,
                                            nTempRank, nAtomNumber, &lCount, 0  );
        nCurSymm = nCurRank = 0;
        for (i = 0; i < num_atoms; i++)
        {
            j = (int) nAtomNumber[i];
            if (nCurSymm != nSymmRank[j])
            {
                nCurSymm = nSymmRank[j];
                is = i;
            }
            if (nCurRank != nRank[j])
            {
                nCurRank = nRank[j];
                ir = i;
            }
            if (is != ir)
            {
                bIsNotSame = 1;
                break;
            }
        }
    }
exit_err:
    if (nRank)
        inchi_free( nRank );
    if (nAtomNumber)
        inchi_free( nAtomNumber );
    if (nTempRank)
        inchi_free( nTempRank );
    if (pAtomInvariant)
        inchi_free( pAtomInvariant );
    if (NeighList)
        FreeNeighList( NeighList );
    return bIsNotSame;
}
int bCanonIsFinerThanEquitablePartition ( int num_atoms , sp_ATOM * at , AT_RANK * nSymmRank ) { AT_RANK * nRank = NULL ; AT_RANK * nAtomNumber = NULL ; AT_RANK * nTempRank = NULL ; AT_RANK nCurSymm , nCurRank ; ATOM_INVARIANT2 * pAtomInvariant = NULL ; NEIGH_LIST * NeighList = NULL ; int nNumCurrRanks , i , is , ir , j ; long lCount ; int bIsNotSame = 0 ; if ( at && nSymmRank ) { if ( ! ( nRank = ( AT_RANK * ) inchi_calloc ( num_atoms , sizeof ( nRank [ 0 ] ) ) ) || ! ( nAtomNumber = ( AT_RANK * ) inchi_calloc ( num_atoms , sizeof ( nAtomNumber [ 0 ] ) ) ) || ! ( nTempRank = ( AT_RANK * ) inchi_calloc ( num_atoms , sizeof ( nTempRank [ 0 ] ) ) ) || ! ( pAtomInvariant = ( ATOM_INVARIANT2 * ) inchi_calloc ( num_atoms , sizeof ( pAtomInvariant [ 0 ] ) ) ) ) { goto exit_err ; } if ( ! ( NeighList = CreateNeighList ( num_atoms , num_atoms , at , 0 , NULL ) ) ) { goto exit_err ; } FillOutAtomInvariant2 ( at , num_atoms , num_atoms , pAtomInvariant , 1 , 1 , 1 , 0 , 0 , NULL ) ; nNumCurrRanks = SetInitialRanks2 ( num_atoms , pAtomInvariant , nRank , nAtomNumber , pCG ) ; lCount = 0 ; nNumCurrRanks = DifferentiateRanks2 ( pCG , num_atoms , NeighList , nNumCurrRanks , nRank , nTempRank , nAtomNumber , & lCount , 0 ) ; nCurSymm = nCurRank = 0 ; for ( i = 0 ; i < num_atoms ; i ++ ) { j = ( int ) nAtomNumber [ i ] ; if ( nCurSymm != nSymmRank [ j ] ) { nCurSymm = nSymmRank [ j ] ; is = i ; } if ( nCurRank != nRank [ j ] ) { nCurRank = nRank [ j ] ; ir = i ; } if ( is != ir ) { bIsNotSame = 1 ; break ; } } } exit_err : if ( nRank ) inchi_free ( nRank ) ; if ( nAtomNumber ) inchi_free ( nAtomNumber ) ; if ( nTempRank ) inchi_free ( nTempRank ) ; if ( pAtomInvariant ) inchi_free ( pAtomInvariant ) ; if ( NeighList ) FreeNeighList ( NeighList ) ; return bIsNotSame ; }
debug: find whether canonical equivalence is
different from equitable partition
debug : find whether canonical equivalence is different from equitable partition
/*bIgnoreIsotopic*/ /*bHydrogensInRanks*/ /*bHydrogensFixedInRanks*/ /*bTaut=bDigraph*/ /* bTautGroupsOnly */ /*t_group_info*/ /* initial partitioning of a hydrogenless skeleton: create equitable partition (assign initial ranks) */ /* make equitable partition in pBCN->pRankStack[0,1] */ /* 0 means use qsort */ /* at this point the equitable partition is in nRank; the order of atoms is in nAtomNumber*/ /* compare */