/** * <summary>The removeDistribution method takes a {@link DiscreteDistribution} as an input and loops through the entries in this distribution * and if this map contains a mapping for the entry it puts the entry with its key - value, else it removes the entry. * It also decrements the value of entry from sum and assigns to the sum variable.</summary> * * <param name="distribution">{@link DiscreteDistribution} type input.</param> */ public void RemoveDistribution(DiscreteDistribution distribution) { foreach (var entry in distribution.Keys) { if (this[entry] - distribution[entry] != 0) { this[entry] = this[entry] - distribution[entry]; } else { Remove(entry); } _sum -= distribution[entry]; } }
/** * <summary>The addDistribution method takes a {@link DiscreteDistribution} as an input and loops through the entries in this distribution * and if this map contains a mapping for the entry it puts the entry with its value + entry, else it puts entry with its value. * It also accumulates the values of entries and assigns to the sum variable.</summary> * * <param name="distribution">{@link DiscreteDistribution} type input.</param> */ public void AddDistribution(DiscreteDistribution distribution) { foreach (var entry in distribution.Keys) { if (ContainsKey(entry)) { this[entry] = this[entry] + distribution[entry]; } else { Add(entry, distribution[entry]); } _sum += distribution[entry]; } }