X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a06ee3399bece608790e419054f95807a017a020..38c34eeca315c7be58e65d4d3fb72aaf7b866719:/src/kitemviews/private/kfileitemmodelsortalgorithm.h diff --git a/src/kitemviews/private/kfileitemmodelsortalgorithm.h b/src/kitemviews/private/kfileitemmodelsortalgorithm.h index 3c875ce5a..29c1fe5ac 100644 --- a/src/kitemviews/private/kfileitemmodelsortalgorithm.h +++ b/src/kitemviews/private/kfileitemmodelsortalgorithm.h @@ -1,29 +1,15 @@ -/***************************************************************************** - * Copyright (C) 2012 by Peter Penz * - * Copyright (C) 2012 by Emmanuel Pescosta * - * Copyright (C) 2013 by Frank Reininghaus * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - *****************************************************************************/ +/* + * SPDX-FileCopyrightText: 2012 Peter Penz + * SPDX-FileCopyrightText: 2012 Emmanuel Pescosta + * SPDX-FileCopyrightText: 2013 Frank Reininghaus + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #ifndef KFILEITEMMODELSORTALGORITHM_H #define KFILEITEMMODELSORTALGORITHM_H -#include -#include +#include #include @@ -32,16 +18,14 @@ * worst-case of O(n * log(n)) and to keep the number of comparisons low. * * The implementation is based on qStableSortHelper() from qalgorithms.h - * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). */ -template -static void mergeSort(RandomAccessIterator begin, - RandomAccessIterator end, - LessThan lessThan) +template +static void mergeSort(RandomAccessIterator begin, RandomAccessIterator end, const LessThan &lessThan) { // The implementation is based on qStableSortHelper() from qalgorithms.h - // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). const int span = end - begin; if (span < 2) { @@ -63,12 +47,9 @@ static void mergeSort(RandomAccessIterator begin, * The comparison function \a lessThan must be reentrant. */ -template -static void parallelMergeSort(RandomAccessIterator begin, - RandomAccessIterator end, - LessThan lessThan, - int numberOfThreads, - int parallelMergeSortingThreshold = 100) +template +static void +parallelMergeSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan, int numberOfThreads, int parallelMergeSortingThreshold = 100) { const int span = end - begin; @@ -76,7 +57,8 @@ static void parallelMergeSort(RandomAccessIterator begin, const int newNumberOfThreads = numberOfThreads / 2; const RandomAccessIterator middle = begin + span / 2; - QFuture future = QtConcurrent::run(parallelMergeSort, begin, middle, lessThan, newNumberOfThreads, parallelMergeSortingThreshold); + QFuture future = + QtConcurrent::run(parallelMergeSort, begin, middle, lessThan, newNumberOfThreads, parallelMergeSortingThreshold); parallelMergeSort(middle, end, lessThan, newNumberOfThreads, parallelMergeSortingThreshold); future.waitForFinished(); @@ -93,17 +75,14 @@ static void parallelMergeSort(RandomAccessIterator begin, * \a begin and \a end. * * The implementation is based on qMerge() from qalgorithms.h - * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). */ -template -static void merge(RandomAccessIterator begin, - RandomAccessIterator pivot, - RandomAccessIterator end, - LessThan lessThan) +template +static void merge(RandomAccessIterator begin, RandomAccessIterator pivot, RandomAccessIterator end, const LessThan &lessThan) { // The implementation is based on qMerge() from qalgorithms.h - // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). const int len1 = pivot - begin; const int len2 = end - pivot; @@ -114,7 +93,7 @@ static void merge(RandomAccessIterator begin, if (len1 + len2 == 2) { if (lessThan(*(begin + 1), *(begin))) { - qSwap(*begin, *(begin + 1)); + std::swap(*begin, *(begin + 1)); } return; } @@ -125,12 +104,12 @@ static void merge(RandomAccessIterator begin, if (len1 > len2) { const int len1Half = len1 / 2; firstCut = begin + len1Half; - secondCut = std::lower_bound(pivot, end, *firstCut, lessThan); + secondCut = std::lower_bound(pivot, end, *firstCut, lessThan); len2Half = secondCut - pivot; } else { len2Half = len2 / 2; secondCut = pivot + len2Half; - firstCut = std::upper_bound(begin, pivot, *secondCut, lessThan); + firstCut = std::upper_bound(begin, pivot, *secondCut, lessThan); } std::rotate(firstCut, pivot, secondCut); @@ -141,4 +120,3 @@ static void merge(RandomAccessIterator begin, } #endif -