From e8132308247091618299e55da49c52a14e54f743 Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 17 Jun 2020 01:36:39 +0200 Subject: [PATCH] Fix: re-insert at same position if last row --- main/Common Classes/FilterPipeline.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main/Common Classes/FilterPipeline.swift b/main/Common Classes/FilterPipeline.swift index 7a1631e..b036975 100644 --- a/main/Common Classes/FilterPipeline.swift +++ b/main/Common Classes/FilterPipeline.swift @@ -375,8 +375,9 @@ class PipelineSorting { /// - Returns: Index in the projection /// - Complexity: O(log *n*), where *n* is the length of the `projection`. @discardableResult fileprivate func insertNew(_ index: Int, previousIndex prev: Int = -1) -> Int { - if prev >= 0, prev < projection.count { - if (prev == 0 || !comperator(index, projection[prev - 1])), !comperator(projection[prev], index) { + if prev >= 0, prev <= projection.count { // '<=' because previous delete removed one element + if (prev == 0 || !comperator(index, projection[prev - 1])), + (prev == projection.count || !comperator(projection[prev], index)) { // If element can be inserted at the same position without resorting, do that projection.insert(index, at: prev) return prev