From f642e25bb3e280e5be9fbe3da141f17e1f98a283 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Thu, 6 Apr 2017 12:45:50 +0300 Subject: [PATCH] Microoptimization --- dotnet/WhiteRabbit/PermutationsGenerator.cs | 4 +--- dotnet/WhiteRabbit/PhraseSet.cs | 2 +- dotnet/WhiteRabbit/PrecomputedPermutationsGenerator.cs | 10 ++++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dotnet/WhiteRabbit/PermutationsGenerator.cs b/dotnet/WhiteRabbit/PermutationsGenerator.cs index aec4610..3d3a1c1 100644 --- a/dotnet/WhiteRabbit/PermutationsGenerator.cs +++ b/dotnet/WhiteRabbit/PermutationsGenerator.cs @@ -34,9 +34,7 @@ public static Permutation Empty { get; } = new Permutation(new int[] { }); - private int[] PermutationData { get; } - - public int this[int index] => this.PermutationData[index]; + public int[] PermutationData { get; } public static IEnumerable HamiltonianPermutationsIterator(int n) { diff --git a/dotnet/WhiteRabbit/PhraseSet.cs b/dotnet/WhiteRabbit/PhraseSet.cs index d8c58b3..6bed70a 100644 --- a/dotnet/WhiteRabbit/PhraseSet.cs +++ b/dotnet/WhiteRabbit/PhraseSet.cs @@ -5,7 +5,7 @@ { 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) { diff --git a/dotnet/WhiteRabbit/PrecomputedPermutationsGenerator.cs b/dotnet/WhiteRabbit/PrecomputedPermutationsGenerator.cs index 90757be..3389a32 100644 --- a/dotnet/WhiteRabbit/PrecomputedPermutationsGenerator.cs +++ b/dotnet/WhiteRabbit/PrecomputedPermutationsGenerator.cs @@ -5,17 +5,19 @@ 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(); - 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]; - 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) { return result;