commit
This commit is contained in:
67
Assets/Data/ChampionUtils.cs
Normal file
67
Assets/Data/ChampionUtils.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Assets.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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user