BWAPI
|
00001 // Copyright (c) 2007 INRIA Sophia-Antipolis (France). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation; version 2.1 of the License. 00007 // See the file LICENSE.LGPL distributed with CGAL. 00008 // 00009 // Licensees holding a valid commercial license may use this file in 00010 // accordance with the commercial license agreement provided with the software. 00011 // 00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 // 00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Spatial_sorting/include/CGAL/Multiscale_sort.h $ 00016 // $Id: Multiscale_sort.h 47102 2008-11-28 09:07:23Z spion $ 00017 // 00018 // Author(s) : Christophe Delage 00019 00020 #ifndef CGAL_MULTISCALE_SORT_H 00021 #define CGAL_MULTISCALE_SORT_H 00022 00023 #include <CGAL/basic.h> 00024 #include <iterator> 00025 #include <cstddef> 00026 00027 CGAL_BEGIN_NAMESPACE 00028 00029 template <class Sort> 00030 class Multiscale_sort 00031 { 00032 Sort _sort; 00033 std::ptrdiff_t _threshold; 00034 double _ratio; 00035 00036 public: 00037 Multiscale_sort (const Sort &sort = Sort(), std::ptrdiff_t threshold = 1, double ratio = 0.5) 00038 : _sort (sort), _threshold (threshold), _ratio (ratio) 00039 { 00040 CGAL_precondition (0. <= ratio && ratio <= 1.); 00041 } 00042 00043 template <class RandomAccessIterator> 00044 void operator() (RandomAccessIterator begin, RandomAccessIterator end) const 00045 { 00046 typedef typename std::iterator_traits<RandomAccessIterator>::difference_type difference_type; 00047 RandomAccessIterator middle = begin; 00048 if (end - begin >= _threshold) { 00049 middle = begin + difference_type ((end - begin) * _ratio); 00050 this->operator() (begin, middle); 00051 } 00052 _sort (middle, end); 00053 } 00054 }; 00055 00056 CGAL_END_NAMESPACE 00057 00058 #endif // CGAL_MULTISCALE_SORT_H