Microoptimization

unmanaged
Inga 🏳‍🌈 8 years ago
parent 55d721ffae
commit f642e25bb3
  1. 4
      dotnet/WhiteRabbit/PermutationsGenerator.cs
  2. 2
      dotnet/WhiteRabbit/PhraseSet.cs
  3. 10
      dotnet/WhiteRabbit/PrecomputedPermutationsGenerator.cs

@ -34,9 +34,7 @@
public static Permutation Empty { get; } = new Permutation(new int[] { }); public static Permutation Empty { get; } = new Permutation(new int[] { });
private int[] PermutationData { get; } public int[] PermutationData { get; }
public int this[int index] => this.PermutationData[index];
public static IEnumerable<Permutation> HamiltonianPermutationsIterator(int n) public static IEnumerable<Permutation> HamiltonianPermutationsIterator(int n)
{ {

@ -5,7 +5,7 @@
{ {
public fixed uint Buffer[8 * Constants.PhrasesPerSet]; public fixed uint Buffer[8 * Constants.PhrasesPerSet];
public PhraseSet(byte[][] words, PermutationsGenerator.Permutation[] permutations, int offset, int numberOfCharacters) public PhraseSet(byte[][] words, int[][] permutations, int offset, int numberOfCharacters)
{ {
fixed (uint* bufferPointer = this.Buffer) fixed (uint* bufferPointer = this.Buffer)
{ {

@ -5,17 +5,19 @@
internal static class PrecomputedPermutationsGenerator internal static class PrecomputedPermutationsGenerator
{ {
private static PermutationsGenerator.Permutation[][] Permutations { get; } = Enumerable.Range(0, 8).Select(GeneratePermutations).ToArray(); private static int[][][] Permutations { get; } = Enumerable.Range(0, 8).Select(GeneratePermutations).ToArray();
private static long[] PermutationsNumbers { get; } = GeneratePermutationsNumbers().Take(19).ToArray(); private static long[] PermutationsNumbers { get; } = GeneratePermutationsNumbers().Take(19).ToArray();
public static PermutationsGenerator.Permutation[] HamiltonianPermutations(int n) => Permutations[n]; public static int[][] HamiltonianPermutations(int n) => Permutations[n];
public static long GetPermutationsNumber(int n) => PermutationsNumbers[n]; public static long GetPermutationsNumber(int n) => PermutationsNumbers[n];
private static PermutationsGenerator.Permutation[] GeneratePermutations(int n) private static int[][] GeneratePermutations(int n)
{ {
var result = PermutationsGenerator.HamiltonianPermutations(n).ToArray(); var result = PermutationsGenerator.HamiltonianPermutations(n)
.Select(permutation => permutation.PermutationData)
.ToArray();
if (result.Length % Constants.PhrasesPerSet == 0) if (result.Length % Constants.PhrasesPerSet == 0)
{ {
return result; return result;

Loading…
Cancel
Save