CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
// see: https://stackoverflow.com/a/49749471/1016343
public class Program
{
public static void Main()
{
var pilots=TestSetComparison().ToList().GroupBy(p=>p.Skills, new MyComparer());
pilots.Select(chunk => string.Join(", ", chunk
.Select(item => item.Name)
.OrderBy(name => name))).Dump();
}
public class Pilot
{
public string Name;
public HashSet<string> Skills;
}
public static Pilot[] TestSetComparison()
{
var pilots = new[]
{
new Pilot { Name = "Smith", Skills = new HashSet<string>(new[] { "B-52", "F-14" }) },
new Pilot { Name = "Higgins", Skills = new HashSet<string>(new[] { "Concorde", "F-14" }) },
new Pilot { Name = "Jones", Skills = new HashSet<string>(new[] { "F-14", "B-52" }) },
new Pilot { Name = "Wilson", Skills = new HashSet<string>(new[] { "F-14", "Concorde" }) },
new Pilot { Name = "Celko", Skills = new HashSet<string>(new[] { "Piper Cub" }) },
};
return pilots;
}
private sealed class MyComparer : IEqualityComparer<HashSet<string>>
{
public bool Equals(HashSet<string> x, HashSet<string> y)
{
if (object.ReferenceEquals(x, y))
return true;
else if (null == x || null == y)
return false;
return (x.Count == y.Count) && (!x.Except(y).Any());
}
public int GetHashCode(HashSet<string> obj)
{
return obj == null ? -1 : obj.Count;
}
}
}