Improved debugging

feature-optimized-md5
Inga 🏳‍🌈 7 years ago
parent a3a426f023
commit b570a06f2b
  1. 10
      WhiteRabbit/Program.cs
  2. 5
      WhiteRabbit/StringsProcessor.cs
  3. 6
      WhiteRabbit/VectorsProcessor.cs

@ -86,5 +86,15 @@
yield return Encoding.ASCII.GetBytes(line);
}
}
#if SINGLE_THREADED
private static void ForAll<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var entry in source)
{
action(entry);
}
}
#endif
}
}

@ -15,6 +15,7 @@
// Dictionary of vectors to array of words represented by this vector
var vectorsToWords = words
.Where(word => word != null && word.Length > 0)
.Select(word => new { word, vector = this.VectorsConverter.GetVector(word) })
.Where(tuple => tuple.vector != null)
.Select(tuple => new { tuple.word, vector = tuple.vector.Value })
@ -41,7 +42,11 @@
private int NumberOfCharacters { get; }
#if SINGLE_THREADED
public IEnumerable<byte[]> GeneratePhrases()
#else
public ParallelQuery<byte[]> GeneratePhrases()
#endif
{
// task of finding anagrams could be reduced to the task of finding sequences of dictionary vectors with the target sum
var sums = this.VectorsProcessor.GenerateSequences();

@ -37,10 +37,16 @@
private ImmutableArray<VectorInfo> Dictionary { get; }
// Produces all sequences of vectors with the target sum
#if SINGLE_THREADED
public IEnumerable<int[]> GenerateSequences()
#else
public ParallelQuery<int[]> GenerateSequences()
#endif
{
return GenerateUnorderedSequences(this.Target, GetVectorNorm(this.Target, this.Target), this.MaxVectorsCount, this.Dictionary, 0)
#if !SINGLE_THREADED
.AsParallel()
#endif
.Select(Enumerable.ToArray)
.SelectMany(GeneratePermutations);
}

Loading…
Cancel
Save