Morwenn / cpp-sort

Sorting algorithms & related tools for C++14
MIT License
621 stars 57 forks source link

Error with quick_merge_sort, dist::alternating and as_long_string #192

Closed Morwenn closed 3 years ago

Morwenn commented 3 years ago

The assertion in the following piece of code fires:

std::list<int> collection;
auto distribution = dist::alternating{};
distribution(std::back_inserter(collection), 10'000);

cppsort::quick_merge_sort(collection, dist::as_long_string{});
assert(std::is_sorted(collection.begin(), collection.end()));

Additional information:

The third bullet above means that the issue most likely doesn't come from the introselect implementation. Instinctively I would blame the handling of projections in the main body of quick_merge_sort.

Morwenn commented 3 years ago

Not an algorithmic issue but a brain fart: dist::alternating generates negative numbers, which obviously don't compare properly when converted to strings since the character - wrecks havoc.