Refactor `Permutations` in `EnumerableExtensions` by extracting `RotateIndices` method to simplify and reuse index rotation logic
This commit is contained in:
parent
9d4051ece1
commit
d878ab186e
|
|
@ -117,12 +117,7 @@ public static class EnumerableExtensions
|
||||||
cycles[i] -= 1;
|
cycles[i] -= 1;
|
||||||
if (cycles[i] == 0)
|
if (cycles[i] == 0)
|
||||||
{
|
{
|
||||||
var tmp = indices[i];
|
RotateIndices(indices, i);
|
||||||
for (var j = i; j < indices.Length - 1; j++)
|
|
||||||
{
|
|
||||||
indices[j] = indices[j + 1];
|
|
||||||
}
|
|
||||||
indices[^1] = tmp;
|
|
||||||
cycles[i] = poolLength - i;
|
cycles[i] = poolLength - i;
|
||||||
}
|
}
|
||||||
else
|
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) =>
|
private static TValue[] GetCombination<TValue>(int[] innerIndices, TValue[] innerPool) =>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue