Files
TraitTracker/Assets/Set/Data/ChampionUtils.cs

74 lines
2.0 KiB
C#

using System.Collections.Generic;
namespace Set.Data
{
public class ChampionUtils
{
public static HashSet<ChampionsEnum> FromLong(long champions)
{
HashSet<ChampionsEnum> result = new HashSet<ChampionsEnum>();
foreach (ChampionsEnum champion in System.Enum.GetValues(typeof(ChampionsEnum)))
{
if ((champions & (long)champion) != 0)
{
result.Add(champion);
}
}
return result;
}
public static long ToLong(HashSet<ChampionsEnum> 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);
}
/// <summary>
/// 0 to n-1
/// </summary>
/// <param name="champions"></param>
/// <param name="n"></param>
/// <returns></returns>
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;
}
}
}