Currently when the number of unique elements of the left sequence is limited:
//Not the minimum number of keys is not available on the first range, so fallback to rotations
if(collected != to_collect && collected < 4){
merge_bufferless(first, first + len1, first + len1 + len2, comp);
}
but this logic is invalid as the first sequence has been mutated when extracting elements. Instead, the extracted elements must be merged back to the sequence before merging with the second sequence:
//Not the minimum number of keys is not available on the first range, so fallback to rotations
if(collected != to_collect && collected < 4){
merge_bufferless(first, first+collected, first+len1, comp);
merge_bufferless(first, first + len1, first + len1 + len2, comp);
return;
}
Currently when the number of unique elements of the left sequence is limited:
but this logic is invalid as the first sequence has been mutated when extracting elements. Instead, the extracted elements must be merged back to the sequence before merging with the second sequence: