| 123456789101112131415161718192021222324252627282930313233343536 |
-
- namespace Yuuna.Contracts.Optimization
- {
- using System.Collections.Generic;
- public sealed class ScoreComparer : IComparer<IScore>
- {
- public readonly static IComparer<IScore> Default = new ScoreComparer();
- private ScoreComparer()
- {
- }
- public int Compare(IScore x, IScore y)
- {
- var f1 = x.Contrast.SequentialKeys.Count == x.SequentialMatches.Count;
- var f2 = y.Contrast.SequentialKeys.Count == y.SequentialMatches.Count;
- if (f1 & f2)
- return x.Contrast.SequentialKeys.Count - y.Contrast.SequentialKeys.Count;
- else if (f1)
- return 1;
- else if (f2)
- return -1;
- else
- {
- var v1 = x.Contrast.SequentialKeys.Count - x.SequentialMatches.Count;
- var v2 = y.Contrast.SequentialKeys.Count - y.SequentialMatches.Count;
- if (v1 > v2)
- return -v2;
- else if (v1 < v2)
- return v1;
- return x.Contrast.SequentialKeys.Count - y.Contrast.SequentialKeys.Count;
- }
- }
- }
- }
|