ScoreComparer.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 
  2. namespace Yuuna.Contracts.Optimization
  3. {
  4. using System.Collections.Generic;
  5. public sealed class ScoreComparer : IComparer<IScore>
  6. {
  7. public readonly static IComparer<IScore> Default = new ScoreComparer();
  8. private ScoreComparer()
  9. {
  10. }
  11. public int Compare(IScore x, IScore y)
  12. {
  13. var f1 = x.Contrast.SequentialKeys.Count == x.SequentialMatches.Count;
  14. var f2 = y.Contrast.SequentialKeys.Count == y.SequentialMatches.Count;
  15. if (f1 & f2)
  16. return x.Contrast.SequentialKeys.Count - y.Contrast.SequentialKeys.Count;
  17. else if (f1)
  18. return 1;
  19. else if (f2)
  20. return -1;
  21. else
  22. {
  23. var v1 = x.Contrast.SequentialKeys.Count - x.SequentialMatches.Count;
  24. var v2 = y.Contrast.SequentialKeys.Count - y.SequentialMatches.Count;
  25. if (v1 > v2)
  26. return -v2;
  27. else if (v1 < v2)
  28. return v1;
  29. return x.Contrast.SequentialKeys.Count - y.Contrast.SequentialKeys.Count;
  30. }
  31. }
  32. }
  33. }