public static void UpdateResources <TSource>( this IResourceManager <TSource> mgr, IEnumerable <TSource> collection) { mgr.UpdateResources( collection .Distinct() .ToDictionary(x => x, _ => WeightItem.CreateDefaultItem())); }
public static IResourceManager <TSource> Create <TSource>(IEnumerable <TSource> sources) { var resources = new ConcurrentDictionary <TSource, WeightItem>(); foreach (var source in sources) { resources.GetOrAdd(source, WeightItem.CreateDefaultItem()); } return(new ResourceManager <TSource>(resources, new AgodaWeightManipulationStrategy())); }
public WeightItem UpdateWeight <T>(T source, WeightItem originalWeight, bool isSuccess) { var originialWeightValue = originalWeight.Weight; var newWeight = isSuccess ? originialWeightValue * Magnitude : originialWeightValue / Magnitude; // Convert.ToInt32 is Math.Round that returns int var delta = Convert.ToInt32(newWeight) - originialWeightValue; return(originalWeight.SetNewWeight(delta)); }
public WeightItem UpdateWeight <T>(T source, WeightItem originalWeight, bool isSuccess) { return(_strategy.UpdateWeight(source, originalWeight, isSuccess)); }
public static IResourceManager <TSource> Create <TSource>(IEnumerable <TSource> sources) => new ResourceManager <TSource>( sources.ToDictionary( x => x, _ => WeightItem.CreateDefaultItem()), new AgodaWeightManipulationStrategy());
public static WeightItem SetNewWeight(this WeightItem weight, int delta) { var newWeight = Math.Min(Math.Max(weight.Weight + delta, weight.MinWeight), weight.MaxWeight); return(new WeightItem(newWeight, weight.MaxWeight, weight.MinWeight)); }
private bool Equals(WeightItem other) { return(Weight == other.Weight && MinWeight == other.MinWeight && MaxWeight == other.MaxWeight); }