lemon/radix_sort.h
changeset 1184 3c00344f49c9
parent 1092 dceba191c00d
     1.1 --- a/lemon/radix_sort.h	Mon Jul 16 16:21:40 2018 +0200
     1.2 +++ b/lemon/radix_sort.h	Wed Oct 17 19:14:07 2018 +0200
     1.3 @@ -2,7 +2,7 @@
     1.4   *
     1.5   * This file is a part of LEMON, a generic C++ optimization library.
     1.6   *
     1.7 - * Copyright (C) 2003-2009
     1.8 + * Copyright (C) 2003-2013
     1.9   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10   * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11   *
    1.12 @@ -34,6 +34,12 @@
    1.13  
    1.14    namespace _radix_sort_bits {
    1.15  
    1.16 +    template <typename Iterator>
    1.17 +    bool unitRange(Iterator first, Iterator last) {
    1.18 +      ++first;
    1.19 +      return first == last;
    1.20 +    }
    1.21 +
    1.22      template <typename Value>
    1.23      struct Identity {
    1.24        const Value& operator()(const Value& val) {
    1.25 @@ -60,9 +66,6 @@
    1.26        }
    1.27        std::iter_swap(first, last);
    1.28        ++first;
    1.29 -      if (!(first < last)) {
    1.30 -        return first;
    1.31 -      }
    1.32        while (true) {
    1.33          while (!(functor(*first) & mask)) {
    1.34            ++first;
    1.35 @@ -71,7 +74,7 @@
    1.36          while (functor(*last) & mask) {
    1.37            --last;
    1.38          }
    1.39 -        if (!(first < last)) {
    1.40 +        if (unitRange(last, first)) {
    1.41            return first;
    1.42          }
    1.43          std::iter_swap(first, last);
    1.44 @@ -97,9 +100,6 @@
    1.45        }
    1.46        std::iter_swap(first, last);
    1.47        ++first;
    1.48 -      if (!(first < last)) {
    1.49 -        return first;
    1.50 -      }
    1.51        while (true) {
    1.52          while (functor(*first) < 0) {
    1.53            ++first;
    1.54 @@ -108,7 +108,7 @@
    1.55          while (functor(*last) >= 0) {
    1.56            --last;
    1.57          }
    1.58 -        if (!(first < last)) {
    1.59 +        if (unitRange(last, first)) {
    1.60            return first;
    1.61          }
    1.62          std::iter_swap(first, last);
    1.63 @@ -119,7 +119,7 @@
    1.64      template <typename Value, typename Iterator, typename Functor>
    1.65      void radixIntroSort(Iterator first, Iterator last,
    1.66                          Functor functor, Value mask) {
    1.67 -      while (mask != 0 && last - first > 1) {
    1.68 +      while (mask != 0 && first != last && !unitRange(first, last)) {
    1.69          Iterator cut = radixSortPartition(first, last, functor, mask);
    1.70          mask >>= 1;
    1.71          radixIntroSort(first, cut, functor, mask);
    1.72 @@ -328,7 +328,7 @@
    1.73        typedef std::allocator<Key> Allocator;
    1.74        Allocator allocator;
    1.75  
    1.76 -      int length = std::distance(first, last);
    1.77 +      int length = static_cast<int>(std::distance(first, last));
    1.78        Key* buffer = allocator.allocate(2 * length);
    1.79        try {
    1.80          bool dir = true;