forked from boostorg/unordered
Make the sort stable.
Doesn't really matter, but it might as well be. [SVN r51505]
This commit is contained in:
@@ -243,14 +243,28 @@ namespace test
|
|||||||
node** merge_adjacent_ranges(node** first, node** second,
|
node** merge_adjacent_ranges(node** first, node** second,
|
||||||
node** third, Less less)
|
node** third, Less less)
|
||||||
{
|
{
|
||||||
while(first != second) {
|
while(true) {
|
||||||
if(less((*second)->value_, (*first)->value_)) {
|
while(true) {
|
||||||
swap_adjacent_ranges(first, second, third);
|
if(first == second) return third;
|
||||||
std::swap(second, third);
|
if(less((*second)->value_, (*first)->value_)) break;
|
||||||
}
|
first = &(*first)->next_;
|
||||||
|
}
|
||||||
|
|
||||||
|
swap_adjacent_ranges(first, second, third);
|
||||||
|
first = &(*first)->next_;
|
||||||
|
|
||||||
|
// Since the two ranges we just swapped, the order is now:
|
||||||
|
// first...third...second
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
if(first == third) return second;
|
||||||
|
if(!less((*first)->value_, (*third)->value_)) break;
|
||||||
|
first = &(*first)->next_;
|
||||||
|
}
|
||||||
|
|
||||||
|
swap_adjacent_ranges(first, third, second);
|
||||||
first = &(*first)->next_;
|
first = &(*first)->next_;
|
||||||
}
|
}
|
||||||
return third;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap_adjacent_ranges(node** first, node** second, node** third)
|
void swap_adjacent_ranges(node** first, node** second, node** third)
|
||||||
|
Reference in New Issue
Block a user