]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kfileitemmodelsortalgorithm.h
Merge remote-tracking branch 'origin/KDE/4.9'
[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 private:
47 static void sequentialSort(KFileItemModel* model,
48 QList<KFileItemModel::ItemData*>::iterator begin,
49 QList<KFileItemModel::ItemData*>::iterator end);
50
51 static void parallelSort(KFileItemModel* model,
52 QList<KFileItemModel::ItemData*>::iterator begin,
53 QList<KFileItemModel::ItemData*>::iterator end,
54 const int numberOfThreads);
55
56 static void merge(KFileItemModel* model,
57 QList<KFileItemModel::ItemData*>::iterator begin,
58 QList<KFileItemModel::ItemData*>::iterator pivot,
59 QList<KFileItemModel::ItemData*>::iterator end);
60
61 static QList<KFileItemModel::ItemData*>::iterator
62 lowerBound(KFileItemModel* model,
63 QList<KFileItemModel::ItemData*>::iterator begin,
64 QList<KFileItemModel::ItemData*>::iterator end,
65 const KFileItemModel::ItemData* value);
66
67 static QList<KFileItemModel::ItemData*>::iterator
68 upperBound(KFileItemModel* model,
69 QList<KFileItemModel::ItemData*>::iterator begin,
70 QList<KFileItemModel::ItemData*>::iterator end,
71 const KFileItemModel::ItemData* value);
72
73 static void reverse(QList<KFileItemModel::ItemData*>::iterator begin,
74 QList<KFileItemModel::ItemData*>::iterator end);
75 };
76
77 #endif
78
79