Is there an efficient way to remove a string as a duplicate based on a match of a substring?
Consider a vector (combinedvect) containing a number of CSV strings of the same form:
'QWERTY, PROTMD, PEDKF, 12345.15454'
'ASDFGH, LDMEMA, PWEMDE, 23456.938984'
'ZXCVBN, NMDFN, MNMWNS, 34567.903'
'ASDFGH, LDMEMA, PWEMDE, 23444.624'
'QWERTY, PROTMD, PEDKF, 15654.15454'
A reverse sort using:
std::sort (combinedvect.begin(), combinedvect.end(), std::greater<>());
results in:
'ZXCVBN, NMDFN, MNMWNS, 34567.903'
'QWERTY, PROTMD, PEDKF, 15654.15454'
'QWERTY, PROTMD, PEDKF, 12345.15454'
'ASDFGH, LDMEMA, PWEMDE, 23456.938984'
'ASDFGH, LDMEMA, PWEMDE, 23444.624'
The reverse sort is used to list duplicates in order from highest numerical substring to lowest, as in:
'QWERTY, PROTMD, PEDKF, 15654.15454'
'QWERTY, PROTMD, PEDKF, 12345.15454'
The goal is to remove any entire string whose first 3 substrings match the previous 3 substrings then sort the resulting output in ascending order of the numerical substring.
The output should look like this:
'QWERTY, PROTMD, PEDKF, 15654.15454'
'ASDFGH, LDMEMA, PWEMDE, 23456.938984'
'ZXCVBN, NMDFN, MNMWNS, 34567.903'
Split and map functions, like:
void splitsort(const std::string &s, double &selectedLPLSQLDate, std::string &mycombinedtext) {
size_t idx = s.find(',');
mycombinedtext= s.substr(0, idx+2);
selectedLPLSQLDate = std::stod(s.substr(idx+3));
}
bool mapFunc(const std::string &a, const std::string &b) {
double selectedLPLSQLDate1, selectedLPLSQLDate2;
std::string mycombinedtext1, mycombinedtext2;
splitsort(a, selectedLPLSQLDate1, mycombinedtext1);
splitsort(b, selectedLPLSQLDate2, mycombinedtext2);
return selectedLPLSQLDate1 < selectedLPLSQLDate2;
}
Did not work with
std::sort (combinedvect.begin(), combinedvect.end(), mapFunc);