1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef KFILEITEMMODELSORTALGORITHM_H
21 #define KFILEITEMMODELSORTALGORITHM_H
23 #include <libdolphin_export.h>
25 #include <kitemviews/kfileitemmodel.h>
28 * @brief Sort algorithm for sorting items of KFileItemModel.
30 * Sorts the items by using KFileItemModel::lessThan() as comparison criteria.
31 * The merge sort algorithm is used to assure a worst-case
32 * of O(n * log(n)) and to keep the number of comparisons low.
34 * The implementation is based on qStableSortHelper() from qalgorithms.h
35 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
36 * The sorting implementations of qAlgorithms could not be used as they
37 * don't support having a member-function as comparison criteria.
39 class LIBDOLPHINPRIVATE_EXPORT KFileItemModelSortAlgorithm
42 static void sort(KFileItemModel
* model
,
43 QList
<KFileItemModel::ItemData
*>::iterator begin
,
44 QList
<KFileItemModel::ItemData
*>::iterator end
);
47 template <typename RandomAccessIterator
, typename LessThan
>
48 static void sequentialSort(RandomAccessIterator begin
,
49 RandomAccessIterator end
,
52 template <typename RandomAccessIterator
, typename LessThan
>
53 static void parallelSort(RandomAccessIterator begin
,
54 RandomAccessIterator end
,
57 int parallelSortingThreshold
= 100);
59 template <typename RandomAccessIterator
, typename LessThan
>
60 static void merge(RandomAccessIterator begin
,
61 RandomAccessIterator pivot
,
62 RandomAccessIterator end
,