/// <summary> /// Determine whether a Multiset<T> object is a subset of another multiset. /// </summary> /// <param name="another"> Another multiset.</param> public bool IsSubsetOf(Multiset <T> another) { int count; return(v_Data.All(kvp => (another.v_Data.TryGetValue(kvp.Key, out count) && kvp.Value <= count))); }
/// <summary> /// Computes union of this multiset with another: {1,1}\cup {1,2}={1,1,2} /// https://en.wikipedia.org/wiki/Multiset#Example_multiset_operations /// </summary> /// <param name="another"> Another multiset.</param> public void UnionWith(Multiset <T> another) { foreach (var key in another.v_Data.Keys) { int count; v_Data.TryGetValue(key, out count); v_Data[key] = Math.Max(count, another.v_Data[key]); } }
/// <summary> /// Determine whether a Multiset<T> object equals to another multiset. /// </summary> /// <param name="another"> Another multiset.</param> /// <returns>True if this multiset equals the other one.</returns> public bool Equals(Multiset <T> another) { // Determines whether a Multiset<T> object equals (componentwise) to another multiset. return(IsSubsetOf(another) && another.IsSubsetOf(this)); }