vectorbase::FindDuplicates

Description

It produces the information about duplicates in the vector.

Syntax

int FindDuplicates( vector<int> & vnMapIndices, vector<uint> & vnR1s, BOOL bCaseSensitive = false, vector<uint>& vnOccurences = NULL, DWORD dwCntrl = 0 )

Parameters

vnMapIndices
[output] It has the same size as the source vector. For each element it holds:
-1 if the corresponding value appears only once;
the 0-offset index into the array vnR1s of group indices.
vnR1s
[output] The group ("repeat") indices of the first occurence in the source array of every value that is repeated at least once.
bCaseSensitive
[input] make string testing case sensitive (it will not be case insensitive by default).
vnOccurences
[output] The number of occurences of each group. It has the same size as vnR1s.
dwCntrl
[input] Control options enumerated as VECTOR_FINDDUPLICATES__*.

Return

the size of vnR1s if success, otherwise a negative number.

Examples

EX1

/*
If the source vector is: {4, 2, 1, 3, 1, 2, 1}
then:
        vnMapIndices = {-1, 1, 0, -1, 0, 1, 0}
        vnR1s = {2, 1}
        vnOccurences = {3, 2}
*/
void vector_FindDuplicates_ex1()
{
        vector<string> strVec = {"4","2","1","3","1","2","1"};
        vector<int> vnMapIndices;
        vector<uint> vnR1s;
        BOOL bCaseSensitive = false;
         
        vector<uint> vnOccurences;
        int nRet = strVec.FindDuplicates(vnMapIndices, vnR1s, bCaseSensitive, vnOccurences);
         
        int ii;
        printf("Source");
        for (ii = 0; ii < strVec.GetSize(); ++ii)
        {
                printf("%c %s", 0 == ii ? '=' : ',', strVec[ii]);
        }
         
        printf("\nnRet = %d\n", nRet);
         
        printf("vnMapIndices");
        for (ii = 0; ii < vnMapIndices.GetSize(); ++ii)
        {
                printf("%c %d", 0 == ii ? '=' : ',', vnMapIndices[ii]);
        }
         
        printf("\nvnR1s ");
        for (ii = 0; ii < vnR1s.GetSize(); ++ii)
        {
                printf("%c %d", 0 == ii ? '=' : ',', vnR1s[ii]);
        }
         
        printf("\nvnOccurences ");
        for (ii = 0; ii < vnOccurences.GetSize(); ++ii)
        {
                printf("%c %d", 0 == ii ? '=' : ',', vnOccurences[ii]);
        }
}

Remark

This method only worked for string type vector. For numeric type vector, need to convert to string type firstly, like convert_double_vector_to_string_vector.

See Also

vectorbase::Find

Header to Include

origin.h