Refactor Permutations in EnumerableExtensions by extracting RotateIndices method to simplify and reuse index rotation logic

This commit is contained in:
Sebastian Lindemeier
2025-12-16 08:00:03 +01:00
parent 9d4051ece1
commit d878ab186e
@@ -117,12 +117,7 @@ public static class EnumerableExtensions
cycles[i] -= 1;
if (cycles[i] == 0)
{
var tmp = indices[i];
for (var j = i; j < indices.Length - 1; j++)
{
indices[j] = indices[j + 1];
}
indices[^1] = tmp;
RotateIndices(indices, i);
cycles[i] = poolLength - i;
}
else
@@ -135,6 +130,18 @@ public static class EnumerableExtensions
}
}
}
yield break;
static void RotateIndices(int[] indices, int from)
{
var tmp = indices[from];
for (var j = from; j < indices.Length - 1; j++)
{
indices[j] = indices[j + 1];
}
indices[^1] = tmp;
}
}
private static TValue[] GetCombination<TValue>(int[] innerIndices, TValue[] innerPool) =>