using System.Collections.Generic; namespace Assets.Data { public class ChampionUtils { public static HashSet FromLong(long champions) { HashSet result = new HashSet(); foreach (ChampionsEnum champion in System.Enum.GetValues(typeof(ChampionsEnum))) { if ((champions & (long)champion) != 0) { result.Add(champion); } } return result; } public static long ToLong(HashSet champions) { long result = 0; foreach (ChampionsEnum champion in champions) { result |= (long)champion; } return result; } public static long ToLong(ChampionsEnum champions) { return (long)champions; } public static bool ContainsChampion(long champions, ChampionsEnum champion) { return (champions & (long)champion) != 0; } public static bool ContainsChampion(long champions, long champion) { return (champions & champion) != 0; } public static int NumberOfChampions(long champions) { return BitWise.HammingWeight(champions); } public static long GetNthChampion(long champions, int n) { int kThFoundChampion = 0; for (int i = 0; i < 64; i++) { if ((champions & (1L << i)) != 0) { if (kThFoundChampion == n) { return 1L << i; } kThFoundChampion++; } } return 0; } } }