third_party/inchi/INCHI_BASE/src/ichican2.c
int SetInitialRanks2( int num_atoms,
                      ATOM_INVARIANT2* pAtomInvariant2,
                      AT_RANK *nNewRank,
                      AT_RANK *nAtomNumber,
                      CANON_GLOBALS *pCG )
{
    int i, nNumDiffRanks;
    AT_RANK nCurrentRank;

    for (i = 0; i < num_atoms; i++)
    {
        nAtomNumber[i] = (AT_RANK) i;
    }

    /* global for qsort */
    pCG->m_pAtomInvariant2ForSort = pAtomInvariant2;

    inchi_qsort( pCG, nAtomNumber, num_atoms, sizeof( nAtomNumber[0] ), CompAtomInvariants2 );

    /* nNewRank[i]: non-decreading order; do not increment nCurrentRank */
    /*           if consecutive sorted atom invariants are identical */

    for (i = num_atoms - 1, nCurrentRank = nNewRank[nAtomNumber[i]] = (AT_RANK) num_atoms, nNumDiffRanks = 1; 0 < i; i--)
    {
        /* Note: CompAtomInvariants2Only() in following line implicitly reads pAtomInvariant2 pointed by pAtomInvariant2ForSort */
        if (CompAtomInvariants2Only( &nAtomNumber[i - 1], &nAtomNumber[i], pCG ))
        {
            nNumDiffRanks++;
            nCurrentRank = (AT_RANK) i;
        }
        nNewRank[nAtomNumber[i - 1]] = nCurrentRank;
    }

    return nNumDiffRanks;
}
/* Upon exit: */
/* nAtomNumber[i]: number (from 0) of an atom in the ith (from 0) position of the sorted order */
/* nNewRank[i]:    initial rank of the atom[i] based on atom invariants; from 1 to num_atoms */
/* Return value:   Number of different ranks */
Upon exit:
nAtomNumber[i]: number (from 0) of an atom in the ith (from 0) position of the sorted order
nNewRank[i]:    initial rank of the atom[i] based on atom invariants; from 1 to num_atoms
Return value:   Number of different ranks
Upon exit : nAtomNumber [ i ] : number ( from 0 ) of an atom in the ith ( from 0 ) position of the sorted order nNewRank [ i ] : initial rank of the atom [ i ] based on atom invariants ; from 1 to num_atoms Return value : Number of different ranks
int SetInitialRanks2( int num_atoms,
                      ATOM_INVARIANT2* pAtomInvariant2,
                      AT_RANK *nNewRank,
                      AT_RANK *nAtomNumber,
                      CANON_GLOBALS *pCG )
{
    int i, nNumDiffRanks;
    AT_RANK nCurrentRank;
    for (i = 0; i < num_atoms; i++)
    {
        nAtomNumber[i] = (AT_RANK) i;
    }
    pCG->m_pAtomInvariant2ForSort = pAtomInvariant2;
    inchi_qsort( pCG, nAtomNumber, num_atoms, sizeof( nAtomNumber[0] ), CompAtomInvariants2 );
    for (i = num_atoms - 1, nCurrentRank = nNewRank[nAtomNumber[i]] = (AT_RANK) num_atoms, nNumDiffRanks = 1; 0 < i; i--)
    {
        if (CompAtomInvariants2Only( &nAtomNumber[i - 1], &nAtomNumber[i], pCG ))
        {
            nNumDiffRanks++;
            nCurrentRank = (AT_RANK) i;
        }
        nNewRank[nAtomNumber[i - 1]] = nCurrentRank;
    }
    return nNumDiffRanks;
}
int SetInitialRanks2 ( int num_atoms , ATOM_INVARIANT2 * pAtomInvariant2 , AT_RANK * nNewRank , AT_RANK * nAtomNumber , CANON_GLOBALS * pCG ) { int i , nNumDiffRanks ; AT_RANK nCurrentRank ; for ( i = 0 ; i < num_atoms ; i ++ ) { nAtomNumber [ i ] = ( AT_RANK ) i ; } pCG -> m_pAtomInvariant2ForSort = pAtomInvariant2 ; inchi_qsort ( pCG , nAtomNumber , num_atoms , sizeof ( nAtomNumber [ 0 ] ) , CompAtomInvariants2 ) ; for ( i = num_atoms - 1 , nCurrentRank = nNewRank [ nAtomNumber [ i ] ] = ( AT_RANK ) num_atoms , nNumDiffRanks = 1 ; 0 < i ; i -- ) { if ( CompAtomInvariants2Only ( & nAtomNumber [ i - 1 ] , & nAtomNumber [ i ] , pCG ) ) { nNumDiffRanks ++ ; nCurrentRank = ( AT_RANK ) i ; } nNewRank [ nAtomNumber [ i - 1 ] ] = nCurrentRank ; } return nNumDiffRanks ; }
Upon exit:
nAtomNumber[i]: number (from 0) of an atom in the ith (from 0) position of the sorted order
nNewRank[i]:    initial rank of the atom[i] based on atom invariants; from 1 to num_atoms
Return value:   Number of different ranks
Upon exit : nAtomNumber [ i ] : number ( from 0 ) of an atom in the ith ( from 0 ) position of the sorted order nNewRank [ i ] : initial rank of the atom [ i ] based on atom invariants ; from 1 to num_atoms Return value : Number of different ranks
/* global for qsort */ /* nNewRank[i]: non-decreading order; do not increment nCurrentRank */ /*           if consecutive sorted atom invariants are identical */ /* Note: CompAtomInvariants2Only() in following line implicitly reads pAtomInvariant2 pointed by pAtomInvariant2ForSort */