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 static void sequentialSort(KFileItemModel
* model
,
48 QList
<KFileItemModel::ItemData
*>::iterator begin
,
49 QList
<KFileItemModel::ItemData
*>::iterator end
);
51 static void parallelSort(KFileItemModel
* model
,
52 QList
<KFileItemModel::ItemData
*>::iterator begin
,
53 QList
<KFileItemModel::ItemData
*>::iterator end
,
54 const int numberOfThreads
);
56 static void merge(KFileItemModel
* model
,
57 QList
<KFileItemModel::ItemData
*>::iterator begin
,
58 QList
<KFileItemModel::ItemData
*>::iterator pivot
,
59 QList
<KFileItemModel::ItemData
*>::iterator end
);
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
);
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
);