/// <summary> /// Intersects two COHashTables and produces a COHashTable. /// </summary> /// <param name="otherTable">Hashtable to intersect with</param> /// <returns>Returns empty if no common object exist.</returns> public COHashTable <T> IntersectToHashTable(COHashTable <T> otherTable) { COHashTable <T> smaller, bigger; if (this.Count > otherTable.Count) { smaller = otherTable; bigger = this; } else { smaller = this; bigger = otherTable; } var ret = new COHashTable <T>(smaller.Count); var intersection = from co in smaller.Objects where bigger.Contains(co) select co; foreach (var co in intersection) { ret.Add(co); } return(ret); }
/// <summary> /// Union of two or more COHashtables /// </summary> /// <param name="otherTables"></param> /// <returns></returns> public COHashTable <T> Union(COHashTable <T>[] otherTables) { int maxSize = this.Count; if (Object.ReferenceEquals(otherTables, null)) { throw new ArgumentNullException("otherTables"); } else { maxSize += otherTables.Sum(t => t.Count); } COHashTable <T> ret = this.Clone(); foreach (COHashTable <T> table in otherTables) { foreach (T co in table.Objects) { ret.Add(co); } } return(ret); }