|
|
|
@ -94,7 +94,7 @@ public:
|
|
|
|
|
|
|
|
|
|
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
|
|
|
|
{
|
|
|
|
|
// Note that both branches here are equivalent in the sense that they give always give the same answer.
|
|
|
|
|
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
|
|
|
|
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
|
|
|
|
// getSortKey() so many times.
|
|
|
|
|
if (isSortingSpecificColumns())
|
|
|
|
@ -130,6 +130,49 @@ public:
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Implementation of lexicographic sorting of lines, ignoring character casing
|
|
|
|
|
class LexicographicCaseInsensitiveSorter : public ISorter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LexicographicCaseInsensitiveSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) { };
|
|
|
|
|
|
|
|
|
|
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
|
|
|
|
{
|
|
|
|
|
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
|
|
|
|
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
|
|
|
|
// getSortKey() so many times.
|
|
|
|
|
if (isSortingSpecificColumns())
|
|
|
|
|
{
|
|
|
|
|
std::sort(lines.begin(), lines.end(), [this](generic_string a, generic_string b)
|
|
|
|
|
{
|
|
|
|
|
if (isDescending())
|
|
|
|
|
{
|
|
|
|
|
return OrdinalIgnoreCaseCompareStrings(getSortKey(a).c_str(), getSortKey(b).c_str()) > 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return OrdinalIgnoreCaseCompareStrings(getSortKey(a).c_str(), getSortKey(b).c_str()) < 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::sort(lines.begin(), lines.end(), [this](generic_string a, generic_string b)
|
|
|
|
|
{
|
|
|
|
|
if (isDescending())
|
|
|
|
|
{
|
|
|
|
|
return OrdinalIgnoreCaseCompareStrings(a.c_str(), b.c_str()) > 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return OrdinalIgnoreCaseCompareStrings(a.c_str(), b.c_str()) < 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Treat consecutive numerals as one number
|
|
|
|
|
// Otherwise it is a lexicographic sort
|
|
|
|
|
class NaturalSorter : public ISorter
|
|
|
|
@ -139,7 +182,7 @@ public:
|
|
|
|
|
|
|
|
|
|
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
|
|
|
|
{
|
|
|
|
|
// Note that both branches here are equivalent in the sense that they give always give the same answer.
|
|
|
|
|
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
|
|
|
|
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
|
|
|
|
// getSortKey() so many times.
|
|
|
|
|
if (isSortingSpecificColumns())
|
|
|
|
|