private void ComputeVennDiagram() { Intersection = new HashSet <T>(); Set1Only = new HashSet <T>(); Set2Only = new HashSet <T>(); foreach (var element in Set1) { if (Set2.Contains(element)) { Intersection.Add(element); } else { Set1Only.Add(element); } } foreach (var element in Set2) { if (!Intersection.Contains(element)) { Set2Only.Add(element); } } }
/// <summary> /// Determines if the two sets are equivalent /// </summary> /// <param name="Set1">Set 1</param> /// <param name="Set2">Set 2</param> /// <returns>True if they are, false otherwise</returns> public static bool operator ==(Set <T> Set1, Set <T> Set2) { if (((object)Set1) == null && ((object)Set2) == null) { return(true); } if (((object)Set1) == null || ((object)Set2) == null) { return(false); } return(Set1.Contains(Set2) && Set2.Contains(Set1)); }
/// <summary> /// Removes items from set 2 from set 1 /// </summary> /// <param name="Set1">Set 1</param> /// <param name="Set2">Set 2</param> /// <returns>The resulting set</returns> public static Set <T> operator -(Set <T> Set1, Set <T> Set2) { Contract.Requires <ArgumentNullException>(Set1 != null, "Set1"); Contract.Requires <ArgumentNullException>(Set2 != null, "Set2"); var ReturnValue = new Set <T>(); for (int x = 0; x < Set1.Count; ++x) { if (!Set2.Contains(Set1[x])) { ReturnValue.Add(Set1[x]); } } return(ReturnValue); }
/// <summary> /// Removes items from set 2 from set 1 /// </summary> /// <param name="Set1">Set 1</param> /// <param name="Set2">Set 2</param> /// <returns>The resulting set</returns> public static Set <T> operator -(Set <T> Set1, Set <T> Set2) { if (Set1 == null || Set2 == null) { throw new ArgumentNullException(); } Set <T> ReturnValue = new Set <T>(); for (int x = 0; x < Set1.NumberItems; ++x) { if (!Set2.Contains(Set1.Items[x])) { ReturnValue.Add(Set1.Items[x]); } } return(ReturnValue); }