Once again bug fix in significant bit calculation
authordeba
Fri, 28 Sep 2007 12:42:14 +0000
changeset 2479221cfaf118a6
parent 2478 bf783151bc92
child 2480 eecaeab41472
Once again bug fix in significant bit calculation
lemon/radix_sort.h
     1.1 --- a/lemon/radix_sort.h	Fri Sep 28 12:15:10 2007 +0000
     1.2 +++ b/lemon/radix_sort.h	Fri Sep 28 12:42:14 2007 +0000
     1.3 @@ -137,21 +137,20 @@
     1.4      int max_digit;
     1.5      Iterator it;
     1.6  
     1.7 -    mask = 0; max_digit = 0;
     1.8 +    mask = ~0; max_digit = 0;
     1.9      for (it = first; it != cut; ++it) {
    1.10 -      while ((mask | functor(*it)) != ~0) {
    1.11 +      while ((mask & functor(*it)) != mask) {
    1.12  	++max_digit;
    1.13 -	mask <<= 1; 
    1.14 -	mask |= 1;
    1.15 +	mask <<= 1;
    1.16        }
    1.17      }
    1.18      radixIntroSort(first, cut, functor, 1 << max_digit);
    1.19  
    1.20 -    mask = ~0; max_digit = 0;
    1.21 +    mask = 0; max_digit = 0;
    1.22      for (it = cut; it != last; ++it) {
    1.23 -      while (mask & functor(*it)) {
    1.24 +      while ((mask | functor(*it)) != mask) {
    1.25  	++max_digit;
    1.26 -	mask <<= 1;
    1.27 +	mask <<= 1; mask |= 1;
    1.28        }
    1.29      }
    1.30      radixIntroSort(cut, last, functor, 1 << max_digit);
    1.31 @@ -160,14 +159,14 @@
    1.32    template <typename Value, typename Iterator, typename Functor>
    1.33    void radixUnsignedSort(Iterator first, Iterator last, Functor functor) {
    1.34  
    1.35 -    Value mask = ~0;
    1.36 +    Value mask = 0;
    1.37      int max_digit = 0;
    1.38  
    1.39      Iterator it;
    1.40      for (it = first; it != last; ++it) {
    1.41 -      while (mask & functor(*it)) {
    1.42 +      while ((mask | functor(*it)) != mask) {
    1.43  	++max_digit;
    1.44 -	mask <<= 1;
    1.45 +	mask <<= 1; mask |= 1;
    1.46        }
    1.47      }
    1.48      radixIntroSort(first, last, functor, 1 << max_digit);