/// <summary>
 /// Excludes elements of otherTable from this table. Actually faster than removing from existing hashtable
 /// </summary>
 /// <param name="otherTable">Table with elements to remove from this table.</param>
 /// <returns>Objects contained in this table minus the ones in otherTable</returns>
 public ICollection <T> Except(COHashTable <T> otherTable)
 {
     return
         ((from co in this.Objects
           where !otherTable.Contains(co)
           select co).ToArray());
 }
        /// <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>
        /// Excludes elements from this table by removing them. Actually slower than adding to a new list.
        /// </summary>
        /// <param name="otherTable"></param>
        public void ExceptAndRemove(COHashTable <T> otherTable)
        {
            var toBeRemoved = Intersect(otherTable);

            foreach (var co in toBeRemoved)
            {
                coDictionary.Remove(co.Key);
            }
        }
        /// <summary>
        /// Intersects two COHashTables and produces a collection.
        /// </summary>
        /// <param name="otherTable">Hashtable to intersect with</param>
        /// <returns>Returns empty if no common object exist.</returns>
        public ICollection <T> Intersect(COHashTable <T> otherTable)
        {
            COHashTable <T> smaller, bigger;

            if (this.Count > otherTable.Count)
            {
                smaller = otherTable;
                bigger  = this;
            }
            else
            {
                smaller = this;
                bigger  = otherTable;
            }
            return((
                       from co in smaller.Objects
                       where bigger.Contains(co)
                       select co
                       ).ToArray());
        }
        /// <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);
        }
 internal static int COHashTableCountComparer(COHashTable <T> x, COHashTable <T> y)
 {
     return(x.Count.CompareTo(y.Count));
 }