예제 #1
0
        public SetInternal <OrdA, A> Subtract(SetInternal <OrdA, A> rhs)
        {
            if (Count == 0)
            {
                return(Empty);
            }
            if (rhs.Count == 0)
            {
                return(this);
            }

            if (rhs.Count < Count)
            {
                var self = this;
                foreach (var item in rhs)
                {
                    self = self.Remove(item);
                }
                return(self);
            }
            else
            {
                var root = SetItem <A> .Empty;
                foreach (var item in this)
                {
                    if (!rhs.Contains(item))
                    {
                        root = SetModuleM.Add <OrdA, A>(root, item, SetModuleM.AddOpt.TryAdd);
                    }
                }
                return(new SetInternal <OrdA, A>(root));
            }
        }
예제 #2
0
        public SetInternal <OrdA, A> Subtract(SetInternal <OrdA, A> rhs)
        {
            var self = this;

            foreach (var item in rhs)
            {
                self = self.Remove(item);
            }
            return(self);
        }
예제 #3
0
        public SetInternal <OrdA, A> Except(SetInternal <OrdA, A> rhs)
        {
            var root = SetItem <A> .Empty;

            foreach (var item in this)
            {
                if (!rhs.Contains(item))
                {
                    root = SetModuleM.Add <OrdA, A>(root, item, SetModuleM.AddOpt.TryAdd);
                }
            }
            return(new SetInternal <OrdA, A>(root));
        }
예제 #4
0
        public bool SetEquals(IEnumerable <A> other)
        {
            var rhs = new SetInternal <OrdA, A>(other);

            if (rhs.Count != Count)
            {
                return(false);
            }
            foreach (var item in rhs)
            {
                if (!Contains(item))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #5
0
        public bool IsSubsetOf(IEnumerable <A> other)
        {
            if (IsEmpty)
            {
                return(true);
            }

            var otherSet = new SetInternal <OrdA, A>(other);
            int matches  = 0;

            foreach (A item in otherSet)
            {
                if (Contains(item))
                {
                    matches++;
                }
            }
            return(matches == Count);
        }
예제 #6
0
        public int CompareTo <OrdAlt>(SetInternal <OrdA, A> other) where OrdAlt : struct, Ord <A>
        {
            var cmp = Count.CompareTo(other.Count);

            if (cmp != 0)
            {
                return(cmp);
            }
            var iterA = GetEnumerator();
            var iterB = other.GetEnumerator();

            while (iterA.MoveNext() && iterB.MoveNext())
            {
                cmp = default(OrdAlt).Compare(iterA.Current, iterB.Current);
                if (cmp != 0)
                {
                    return(cmp);
                }
            }
            return(0);
        }
예제 #7
0
        public SetInternal <OrdA, A> SymmetricExcept(IEnumerable <A> other)
        {
            var rhs = new SetInternal <OrdA, A>(other);
            var res = new List <A>();

            foreach (var item in this)
            {
                if (!rhs.Contains(item))
                {
                    res.Add(item);
                }
            }

            foreach (var item in other)
            {
                if (!Contains(item))
                {
                    res.Add(item);
                }
            }

            return(new SetInternal <OrdA, A>(res));
        }
예제 #8
0
 public bool Equals(SetInternal <OrdA, A> other) =>
 SetEquals(other.AsEnumerable());
예제 #9
0
 public SetInternal <OrdA, A> Append(SetInternal <OrdA, A> rhs) =>
 Union(rhs.AsEnumerable());
예제 #10
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal Set(SetInternal <OrdDefault <A>, A> set) =>
예제 #11
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal Set(SetInternal <OrdA, A> set) =>
예제 #12
0
 /// <summary>
 /// Ctor from an enumerable
 /// </summary>
 public Set(IEnumerable <A> items)
 {
     value = new SetInternal <OrdA, A>(items, true);
 }