boostorg / move

Boost.org move module
http://boost.org/libs/move
Boost Software License 1.0
19 stars 55 forks source link

Incorrect merge in adaptive_merge when the number of unique items is limited #15

Closed igaztanaga closed 6 years ago

igaztanaga commented 6 years ago

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;
  }
igaztanaga commented 6 years ago

Fixed in commit:

https://github.com/boostorg/move/commit/fcf217b8ec4e3817b1f9f7ec637fd590e089c358

vinniefalco commented 6 years ago

Well, I'm glad I tried to diagnose it but to be honest, I would have never figured this out :)