예제 #1
0
        public static OrderedSet <T> operator *(OrderedSet <T> s, OrderedSet <T> t)
        {
            OrderedSet <T> r;

            if (s.Count < t.Count)
            {
                r = new OrderedSet <T>(s.count, s.elems);
                foreach (T o in s)
                {
                    if (!t.Contains(o))
                    {
                        r.InPlaceRemove(o);
                    }
                }
            }
            else
            {
                r = new OrderedSet <T>(t.count, t.elems);
                foreach (T o in t)
                {
                    if (!s.Contains(o))
                    {
                        r.InPlaceRemove(o);
                    }
                }
            }
            return(r);
        }
예제 #2
0
 /// <summary>
 /// Proper superset relation
 /// </summary>
 /// <param name="t"></param>
 /// <returns>True if this every element of set <paramref name="t"/> is also found in this set
 /// and there exists at least one element in this set that is not found in <paramref name="t"/>;
 /// false otherwise.</returns>
 public bool IsProperSupersetOf(OrderedSet <T> t)
 {
     if ((object)t == null)
     {
         throw new ArgumentNullException("t");
     }
     return(t.IsProperSubsetOf(this));
 }
예제 #3
0
        /// <summary>
        /// Transforms a set of one sort to a set of another sort by invoking a given delegate on each element.
        /// If the mapping is injective, then the number of elements in the result will be the same as the number
        /// of elements in this. Otherwise, (if not injective) the number of elements will be fewer.
        /// </summary>
        /// <typeparam name="S">The sort of the result</typeparam>
        /// <param name="converter">A pure (side-effect free) function that maps an element of T to an element of S</param>
        /// <returns>The set</returns>
        public OrderedSet <S> Convert <S>(Converter <T, S> converter)
        {
            OrderedSet <S> result = new OrderedSet <S>();

            foreach (T val in this)
            {
                result.InPlaceAdd(converter(val));
            }
            return(result);
        }
예제 #4
0
        public static OrderedSet <T> operator -(OrderedSet <T> s, OrderedSet <T> t)
        {
            OrderedSet <T> r = new OrderedSet <T>(s.count, s.elems);

            foreach (T o in t)
            {
                r.InPlaceRemove(o);
            }
            return(r);
        }
예제 #5
0
        internal static IComparable ConstructValue(Sequence <IComparable> args)
        {
            OrderedSet <T> result = EmptySet;

            foreach (IComparable arg in args)
            {
                T val = (T)arg;
                result = result.Add(val);
            }
            return(result);
        }
예제 #6
0
        /// <summary>
        /// Proper subset relation
        /// </summary>
        /// <param name="t"></param>
        /// <returns>True if this every element of this set is found in set <paramref name="t"/>
        /// and there exists at least one element in <paramref name="t"/> that is not found in this set;
        /// false otherwise.</returns>
        public bool IsProperSubsetOf(OrderedSet <T> t)
        {
            OrderedSet <T> s = this;

            if (!(s.Count < t.Count))
            {
                return(false);
            }
            foreach (T o in s)
            {
                if (!t.Contains(o))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #7
0
        public static OrderedSet <T> BigIntersect(OrderedSet <OrderedSet <T> > s)
        {
            OrderedSet <T> r = EmptySet; int i = 0;

            foreach (OrderedSet <T> ks in s)
            {
                if (i == 0)
                {
                    r = ks;
                }
                else
                {
                    r = r * ks;
                }
                i++;
            }
            return(r);
        }
예제 #8
0
        public static OrderedSet <T> operator +(OrderedSet <T> s, OrderedSet <T> t)
        {
            OrderedSet <T> r;

            if (s.Count > t.Count)
            {
                r = new OrderedSet <T>(s.count, s.elems);
                foreach (T o in t)
                {
                    r.InPlaceAdd(o);
                }
            }
            else
            {
                r = new OrderedSet <T>(t.count, t.elems);
                foreach (T o in s)
                {
                    r.InPlaceAdd(o);
                }
            }
            return(r);
        }
예제 #9
0
 /// <summary>
 /// OrderedSet intersection. Same as operator *.  [Time: max(s.Count,t.Count)*log(max(s.Count, t.Count))]
 /// </summary>
 /// <param name="t">A set to be intersected with this.</param>
 /// <returns>The set of all elements that shared by this and t</returns>
 public OrderedSet <T> Intersect(OrderedSet <T> t)
 {
     return(this * t);
 }
예제 #10
0
 /// <summary>
 /// OrderedSet difference. Same as operator -
 /// </summary>
 /// <param name="t">The set of unwanted elements to be removed from this set</param>
 /// <returns>The set containing all the elements from this that are not in t</returns>
 public OrderedSet <T> Difference(OrderedSet <T> t)
 {
     return(this - t);
 }
예제 #11
0
 /// <summary>
 /// Same as operator + (set union).
 /// </summary>
 /// <param name="t">A set to be unioned with this set</param>
 /// <returns>The set containing all the elements from both this and t</returns>
 public OrderedSet <T> Union(OrderedSet <T> t)
 {
     return(this + t);
 }