Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multimap not sorting

I have this multimap built to map the hamming distance of a string to its corresponding string.

Since the hamming distance of two strings could be the same, I want them to be sorted in ascending order. However when I print it out, it is not sorted. The hamdistArray is declared as an unsigned type.

typedef multimap<unsigned, string, less<unsigned> > Check;
            Check pairs; 

            pairs.insert(Check::value_type(hamdistArray[j], d.sortedWordDatabase[j]));

            for(Check::const_iterator iter = pairs.begin(); iter != pairs.end(); ++iter)
            {
                cout << iter->first << '\t' << iter->second<< endl;
            }
like image 374
Xann Avatar asked Oct 11 '22 15:10

Xann


1 Answers

Elements in a multimap are sorted by the key (in this case the unsigned hamming distance). Elements with the same key are not sorted by the value (in this case the string), they are usually kept in the order in which they were inserted.

like image 64
kbjorklu Avatar answered Oct 18 '22 02:10

kbjorklu