]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kfileitemmodelsortalgorithm.h
Change the sort and merge functions to a more generic form.
[dolphin.git] / src / kitemviews / private / kfileitemmodelsortalgorithm.h
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef KFILEITEMMODELSORTALGORITHM_H
21 #define KFILEITEMMODELSORTALGORITHM_H
22
23 #include <libdolphin_export.h>
24
25 #include <kitemviews/kfileitemmodel.h>
26
27 /**
28 * @brief Sort algorithm for sorting items of KFileItemModel.
29 *
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.
33 *
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.
38 */
39 class LIBDOLPHINPRIVATE_EXPORT KFileItemModelSortAlgorithm
40 {
41 public:
42 static void sort(KFileItemModel* model,
43 QList<KFileItemModel::ItemData*>::iterator begin,
44 QList<KFileItemModel::ItemData*>::iterator end);
45 };
46
47 template <typename RandomAccessIterator, typename LessThan>
48 static void sequentialSort(RandomAccessIterator begin,
49 RandomAccessIterator end,
50 LessThan lessThan);
51
52 template <typename RandomAccessIterator, typename LessThan>
53 static void parallelSort(RandomAccessIterator begin,
54 RandomAccessIterator end,
55 LessThan lessThan,
56 int numberOfThreads,
57 int parallelSortingThreshold = 100);
58
59 template <typename RandomAccessIterator, typename LessThan>
60 static void merge(RandomAccessIterator begin,
61 RandomAccessIterator pivot,
62 RandomAccessIterator end,
63 LessThan lessThan);
64
65 #endif
66
67