From d2e72413d31ed440998dde24980f2f9693d7213b Mon Sep 17 00:00:00 2001 From: WilliamQiufeng Date: Sun, 18 Aug 2024 15:32:46 +0800 Subject: [PATCH] Use fallback method (O(n^2)) when keycount != 4 to address bug #181 --- .../Rulesets/Keys/DifficultyProcessorKeys.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Quaver.API/Maps/Processors/Difficulty/Rulesets/Keys/DifficultyProcessorKeys.cs b/Quaver.API/Maps/Processors/Difficulty/Rulesets/Keys/DifficultyProcessorKeys.cs index 1a6c4af70..b846bb770 100644 --- a/Quaver.API/Maps/Processors/Difficulty/Rulesets/Keys/DifficultyProcessorKeys.cs +++ b/Quaver.API/Maps/Processors/Difficulty/Rulesets/Keys/DifficultyProcessorKeys.cs @@ -562,19 +562,30 @@ private float CalculateOverallDifficulty() var l = 0; var r = 0; + var useFallback = Map.GetKeyCount() != 4; while (l < StrainSolverData.Count && StrainSolverData[l].StartTime < mapStart) l++; for (var i = mapStart; i < mapEnd; i += binSize) { - while (r < StrainSolverData.Count - 1 && StrainSolverData[r + 1].StartTime < i + binSize) - r++; - if (l >= StrainSolverData.Count) + List valuesInBin; + if (useFallback) { - bins.Add(0); - continue; + valuesInBin = StrainSolverData.Where(s => s.StartTime >= i && s.StartTime < i + binSize) + .ToList(); + } + else + { + while (r < StrainSolverData.Count - 1 && StrainSolverData[r + 1].StartTime < i + binSize) + r++; + if (l >= StrainSolverData.Count) + { + bins.Add(0); + continue; + } + + valuesInBin = StrainSolverData.GetRange(l, r - l + 1); } - var valuesInBin = StrainSolverData.GetRange(l, r - l + 1); var averageRating = valuesInBin.Count > 0 ? valuesInBin.Average(s => s.TotalStrainValue) : 0; bins.Add(averageRating);