Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51505 - trunk/libs/unordered/test/helpers
From: daniel_james_at_[hidden]
Date: 2009-03-01 09:15:40


Author: danieljames
Date: 2009-03-01 09:15:39 EST (Sun, 01 Mar 2009)
New Revision: 51505
URL: http://svn.boost.org/trac/boost/changeset/51505

Log:
Make the sort stable.

Doesn't really matter, but it might as well be.
Text files modified:
   trunk/libs/unordered/test/helpers/list.hpp | 28 +++++++++++++++++++++-------
   1 files changed, 21 insertions(+), 7 deletions(-)

Modified: trunk/libs/unordered/test/helpers/list.hpp
==============================================================================
--- trunk/libs/unordered/test/helpers/list.hpp (original)
+++ trunk/libs/unordered/test/helpers/list.hpp 2009-03-01 09:15:39 EST (Sun, 01 Mar 2009)
@@ -243,14 +243,28 @@
         node** merge_adjacent_ranges(node** first, node** second,
                 node** third, Less less)
         {
- while(first != second) {
- if(less((*second)->value_, (*first)->value_)) {
- swap_adjacent_ranges(first, second, third);
- std::swap(second, third);
- }
- first = &(*first)->next_;
+ while(true) {
+ while(true) {
+ if(first == second) return 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_;
             }
- return third;
         }
         
         void swap_adjacent_ranges(node** first, node** second, node** third)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk