|
@@ -135,15 +135,14 @@ namespace ShakerApp.Tools
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public unsafe static List<(int Index,T Value)> FindPeaks<T>(ref T value,uint len,bool isrisingedge = true) where T :unmanaged
|
|
|
+ public static List<(int Index,T Value)> FindPeaks<T>(ref T value,uint len,bool isrisingedge = true) where T :unmanaged
|
|
|
{
|
|
|
List<(int Index,T Value)> result = new List<(int Index,T Value)>();
|
|
|
if (len <= 1) return result;
|
|
|
int[] diff_v = new int[len - 1];
|
|
|
- T* first = (T*)Unsafe.AsPointer(ref value);
|
|
|
for(int i=0;i<len-1;i++)
|
|
|
{
|
|
|
- diff_v[i] = Comparer<T>.Default.Compare(first[i], first[i + 1]);
|
|
|
+ diff_v[i] = Comparer<T>.Default.Compare(Unsafe.Add(ref value,i),Unsafe.Add(ref value,i+1));
|
|
|
}
|
|
|
for (int i = diff_v.Length - 1; i >= 0; i--)
|
|
|
{
|
|
@@ -158,7 +157,7 @@ namespace ShakerApp.Tools
|
|
|
{
|
|
|
if (diff_v[i + 1] - diff_v[i] == (isrisingedge ?2: -2))
|
|
|
{
|
|
|
- result.Add((i + 1, first[i + 1]));
|
|
|
+ result.Add((i + 1, Unsafe.Add(ref value,i+1)));
|
|
|
}
|
|
|
}
|
|
|
return result;
|