Beispiel #1
0
        public object Contains(object o)
        {
            // promote sets to FrozenSet's for contains checks (so we get a hash code)
            o = SetHelpers.GetHashableSetIfSet(o);

            Ops.Hash(o);// make sure we have a hashable item
            return(Ops.Bool2Object(items.ContainsKey(o)));
        }
Beispiel #2
0
        public void remove([NotNull] SetCollection o)
        {
            var set = SetHelpers.GetHashableSetIfSet(o);

            if (!_items.RemoveAlwaysHash(set))
            {
                throw PythonOps.KeyError(o);
            }
        }
Beispiel #3
0
        public ISet difference([NotNull] params object[] ss)
        {
            ISet res = this;

            foreach (object s in ss)
            {
                res = SetHelpers.Difference(res, s);
            }
            return(res);
        }
Beispiel #4
0
        public ISet intersection([NotNull] params object[] ss)
        {
            ISet res = this;

            foreach (object s in ss)
            {
                res = SetHelpers.Intersection(res, s);
            }
            return(res);
        }
Beispiel #5
0
        bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
        {
            ISet set = other as ISet;

            if (set != null)
            {
                return(SetHelpers.Equals(this, set, comparer));
            }
            return(false);
        }
Beispiel #6
0
        public static bool operator <=(SetCollection self, object other)
        {
            ISet s = other as ISet;

            if (s == null)
            {
                throw PythonOps.TypeError("can only compare to a set");
            }

            return(SetHelpers.IsSubset(self, s, false));
        }
Beispiel #7
0
        public bool __contains__(object value)
        {
            // promote sets to FrozenSets for contains checks (so we get a hash code)
            value = SetHelpers.GetHashableSetIfSet(value);

            if (_items.Count == 0)
            {
                PythonOps.Hash(DefaultContext.Default, value);    // make sure we have a hashable item
            }
            return(_items.Contains(value));
        }
Beispiel #8
0
        public static ISet Union(ISet x, object y)
        {
            ISet        set = SetHelpers.MakeSet(x, x);
            IEnumerator ie  = PythonOps.GetEnumerator(y);

            while (ie.MoveNext())
            {
                set.PrivAdd(ie.Current);
            }
            return(set);
        }
Beispiel #9
0
        public ISet __rsub__(ISet s)
        {
            SetCollection set = s as SetCollection;

            if (set != null)
            {
                return(set.Difference(this));
            }

            return(SetHelpers.MakeSet(this, s.PrivDifference(this)));
        }
Beispiel #10
0
        public void Remove(object o)
        {
            o = SetHelpers.GetHashableSetIfSet(o);

            Ops.Hash(o);
            if (!items.ContainsKey(o))
            {
                throw Ops.KeyError("{0}", o.ToString());
            }

            items.Remove(o);
        }
Beispiel #11
0
        public FrozenSetCollection copy()
        {
            // Python behavior: If we're a non-derived frozen set, we return ourselves.
            // If we're a derived frozen set we make a new set of our type that contains our
            // contents.
            if (this.GetType() == typeof(FrozenSetCollection))
            {
                return(this);
            }
            FrozenSetCollection set = (FrozenSetCollection)SetHelpers.MakeSet(this, this);

            return(set);
        }
Beispiel #12
0
        public ISet OperatorReverseSubtract(ISet s)
        {
            FrozenSetCollection fs = s as FrozenSetCollection;

            if (fs != null)
            {
                return(fs.Difference(this));
            }

            ISet set = SetHelpers.MakeSet(this, s.PrivDifference(this));

            set.PrivFreeze();
            return(set);
        }
Beispiel #13
0
        public static ISet Intersection(ISet x, object y)
        {
            ISet res = SetHelpers.MakeSet(x);

            IEnumerator ie = PythonOps.GetEnumerator(y);

            while (ie.MoveNext())
            {
                if (x.__contains__(ie.Current))
                {
                    res.PrivAdd(ie.Current);
                }
            }
            return(res);
        }
Beispiel #14
0
        public static ISet Difference(ISet x, object y)
        {
            ISet res = SetHelpers.MakeSet(x, x);

            IEnumerator ie = PythonOps.GetEnumerator(y);

            while (ie.MoveNext())
            {
                if (res.__contains__(ie.Current))
                {
                    res.PrivRemove(ie.Current);
                }
            }
            return(res);
        }
Beispiel #15
0
        public ISet __rxor__(ISet s)
        {
            if (s.GetLength() < GetLength())
            {
                return(SymmetricDifference(s));
            }
            SetCollection set = s as SetCollection;

            if (set != null)
            {
                return(set.SymmetricDifference(this));
            }

            return(SetHelpers.MakeSet(this, s.PrivSymmetricDifference(this)));
        }
Beispiel #16
0
        public ISet __ror__(ISet s)
        {
            if (s.GetLength() < GetLength())
            {
                return(Union(s));
            }

            SetCollection set = s as SetCollection;

            if (set != null)
            {
                return(set.Union(this));
            }

            return(SetHelpers.MakeSet(this, s.PrivUnion(this)));
        }
Beispiel #17
0
        public static ISet Intersection(ISet x, object y)
        {
            ISet res = SetHelpers.MakeSet(x);

            IEnumerator ie = Ops.GetEnumerator(y);

            while (ie.MoveNext())
            {
                if (x.Contains(ie.Current) == Ops.TRUE)
                {
                    res.PrivAdd(ie.Current);
                }
            }
            res.PrivFreeze();
            return(res);
        }
Beispiel #18
0
        public object OperatorReverseOr(ISet s)
        {
            if (s.GetLength() < GetLength())
            {
                return(Union(s));
            }
            FrozenSetCollection fs = s as FrozenSetCollection;

            if (fs != null)
            {
                return(fs.Union(this));
            }
            ISet set = SetHelpers.MakeSet(this, s.PrivUnion(this));

            set.PrivFreeze();
            return(set);
        }
Beispiel #19
0
        public ISet OperatorReverseXor(ISet s)
        {
            if (s.GetLength() < GetLength())
            {
                return(SymmetricDifference(s));
            }
            FrozenSetCollection fs = s as FrozenSetCollection;

            if (fs != null)
            {
                return(fs.SymmetricDifference(this));
            }
            ISet set = SetHelpers.MakeSet(this, s.PrivSymmetricDifference(this));

            set.PrivFreeze();
            return(set);
        }
Beispiel #20
0
        public static ISet Difference(ISet x, object y)
        {
            ISet res = SetHelpers.MakeSet(x, x) as ISet;

            Debug.Assert(res != null);

            IEnumerator ie = Ops.GetEnumerator(y);

            while (ie.MoveNext())
            {
                if (res.Contains(ie.Current) == Ops.TRUE)
                {
                    res.PrivRemove(ie.Current);
                }
            }
            res.PrivFreeze();
            return(res);
        }
Beispiel #21
0
        public static ISet SymmetricDifference(ISet x, object y)
        {
            SetCollection otherSet = new SetCollection(PythonOps.GetEnumerator(y));       //make a set to deal w/ dups in the enumerator
            ISet          res      = SetHelpers.MakeSet(x, x) as ISet;

            Debug.Assert(res != null);

            foreach (object o in otherSet)
            {
                if (res.__contains__(o))
                {
                    res.PrivRemove(o);
                }
                else
                {
                    res.PrivAdd(o);
                }
            }
            return(res);
        }
Beispiel #22
0
 public ISet Union(object s)
 {
     return(SetHelpers.Union(this, s));
 }
Beispiel #23
0
 public object IsSubset(object s)
 {
     return(SetHelpers.IsSubset(this, s));
 }
Beispiel #24
0
 public override string ToString()
 {
     return(SetHelpers.SetToString(this, this.items.Keys));
 }
Beispiel #25
0
 public ISet difference()
 {
     return(SetHelpers.MakeSet(this, this));
 }
Beispiel #26
0
 public virtual string /*!*/ __repr__(CodeContext /*!*/ context)
 {
     return(SetHelpers.SetToString(context, this, _items));
 }
Beispiel #27
0
        public void Discard(object o)
        {
            o = SetHelpers.GetHashableSetIfSet(o);

            items.Remove(o);
        }
Beispiel #28
0
 public ISet Intersection(object s)
 {
     return(SetHelpers.Intersection(this, s));
 }
Beispiel #29
0
 public ISet SymmetricDifference(object s)
 {
     return(SetHelpers.SymmetricDifference(this, s));
 }
Beispiel #30
0
 public ISet Difference(object s)
 {
     return(SetHelpers.Difference(this, s));
 }