예제 #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> 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));
        }
예제 #3
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));
        }