Example #1
0
        public SetCollection intersection([NotNull] params object[] /*!*/ sets)
        {
            Debug.Assert(sets != null);

            if (sets.Length == 0)
            {
                return(copy());
            }

            SetStorage res = _items;

            foreach (object set in sets)
            {
                SetStorage items, x = res, y;
                if (SetStorage.GetItems(set, out items))
                {
                    y = items;
                    SetStorage.SortBySize(ref x, ref y);

                    if (object.ReferenceEquals(x, items) || object.ReferenceEquals(x, _items))
                    {
                        x = x.Clone();
                    }
                }
                else
                {
                    y = items;
                    SetStorage.SortBySize(ref x, ref y);

                    if (object.ReferenceEquals(x, _items))
                    {
                        x = x.Clone();
                    }
                }
                x.IntersectionUpdate(y);
                res = x;
            }

            Debug.Assert(!object.ReferenceEquals(res, _items));
            return(Make(res));
        }