/// <summary> /// Loads a set of tokens /// </summary> /// <param name="SetATokens">Set A</param> /// <param name="SetBTokens">Set B</param> public virtual void LoadTokens(IEnumerable <T> SetATokens, IEnumerable <T> SetBTokens) { Contract.Requires <ArgumentNullException>(SetATokens != null, "SetATokens"); Contract.Requires <ArgumentNullException>(SetBTokens != null, "SetBTokens"); SetA = SetA.Check(() => new Bag <T>()); SetB = SetB.Check(() => new Bag <T>()); SetA.Add(SetATokens); SetB.Add(SetBTokens); TotalA = SetA.Sum(x => SetA[x]); TotalB = SetB.Sum(x => SetB[x]); Total = TotalA + TotalB; Probabilities = new Dictionary <T, double>(); foreach (T Token in SetA) { Probabilities.Add(Token, CalculateProbabilityOfToken(Token)); } foreach (T Token in SetB) { if (!Probabilities.ContainsKey(Token)) { Probabilities.Add(Token, CalculateProbabilityOfToken(Token)); } } }
/// <summary> /// Loads a set of tokens /// </summary> /// <param name="SetATokens">Set A</param> /// <param name="SetBTokens">Set B</param> public virtual void LoadTokens(IEnumerable <T> SetATokens, IEnumerable <T> SetBTokens) { Contract.Requires <ArgumentNullException>(SetATokens != null, "SetATokens"); Contract.Requires <ArgumentNullException>(SetBTokens != null, "SetBTokens"); SetA = SetA.Check(() => new Bag <T>()); SetB = SetB.Check(() => new Bag <T>()); SetA.Add(SetATokens); SetB.Add(SetBTokens); TotalA = SetA.Sum(x => SetA[x]); TotalB = SetB.Sum(x => SetB[x]); Total = TotalA + TotalB; Probabilities = new ConcurrentDictionary <T, double>(); Parallel.ForEach(SetA, Token => { Probabilities.AddOrUpdate(Token, x => CalculateProbabilityOfToken(x), (x, y) => CalculateProbabilityOfToken(x)); }); Parallel.ForEach(SetB, Token => { if (!Probabilities.ContainsKey(Token)) { Probabilities.AddOrUpdate(Token, x => CalculateProbabilityOfToken(x), (x, y) => y); } }); }