Ejemplo n.º 1
0
        public void remove([NotNull] SetCollection o)
        {
            var set = SetHelpers.GetHashableSetIfSet(o);

            if (!_items.RemoveAlwaysHash(set))
            {
                throw PythonOps.KeyError(o);
            }
        }
Ejemplo n.º 2
0
        private static bool IsHashable(SetCollection asSet)
        {
            PythonTypeSlot pts;
            PythonType     pt = DynamicHelpers.GetPythonType(asSet);
            object         slotValue;

            return(pt.TryResolveSlot(DefaultContext.Default, "__hash__", out pts) &&
                   pts.TryGetValue(DefaultContext.Default, asSet, pt, out slotValue) && slotValue != null);
        }
Ejemplo n.º 3
0
        public SetCollection symmetric_difference(SetCollection set)
        {
            if (ReferenceEquals(set, this))
            {
                return(Empty);
            }

            return(Make(SetStorage.SymmetricDifference(_items, set._items)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a set that can be hashable.  If the set is currently a FrozenSet the
        /// set is returned.  If the set is a normal Set then a FrozenSet is returned
        /// with its contents.
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static object GetHashableSetIfSet(object o)
        {
            SetCollection asSet = o as SetCollection;

            if (asSet != null)
            {
                return(FrozenSetCollection.Make(asSet.GetEnumerator()));
            }
            return(o);
        }
Ejemplo n.º 5
0
        public static bool IsSuperset(ISet x, object y)
        {
            ISet set = y as ISet;

            if (set == null)
            {
                set = new SetCollection(PythonOps.GetEnumerator(y));
            }

            return(IsSubset(set, x, false));
        }
Ejemplo n.º 6
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)));
        }
Ejemplo n.º 7
0
        public void update(SetCollection set)
        {
            if (ReferenceEquals(set, this))
            {
                return;
            }

            lock (_items) {
                _items.UnionUpdate(set._items);
            }
        }
Ejemplo n.º 8
0
        public void intersection_update(SetCollection set)
        {
            if (object.ReferenceEquals(set, this))
            {
                return;
            }

            lock (_items) {
                _items.IntersectionUpdate(set._items);
            }
        }
Ejemplo n.º 9
0
        public SetCollection difference(SetCollection set)
        {
            if (object.ReferenceEquals(set, this))
            {
                return(Empty);
            }

            return(Make(
                       SetStorage.Difference(_items, set._items)
                       ));
        }
Ejemplo n.º 10
0
        public void difference_update(object s)
        {
            SetCollection set = new SetCollection(PythonOps.GetEnumerator(s));

            foreach (object o in set)
            {
                if (__contains__(o))
                {
                    remove(o);
                }
            }
        }
Ejemplo n.º 11
0
        public void difference_update([NotNull] SetCollection set)
        {
            if (object.ReferenceEquals(set, this))
            {
                _items.Clear();
                return;
            }

            lock (_items) {
                _items.DifferenceUpdate(set._items);
            }
        }
Ejemplo n.º 12
0
        public void DifferenceUpdate(object s)
        {
            SetCollection set = new SetCollection(Ops.GetEnumerator(s));

            foreach (object o in set)
            {
                if (Contains(o) == Ops.TRUE)
                {
                    Remove(o);
                }
            }
        }
Ejemplo n.º 13
0
        public void symmetric_difference_update(SetCollection set)
        {
            if (object.ReferenceEquals(set, this))
            {
                _items.Clear();
                return;
            }

            lock (_items) {
                _items.SymmetricDifferenceUpdate(set._items);
            }
        }
Ejemplo n.º 14
0
        public static object IsSubset(ISet x, object y)
        {
            SetCollection set = new SetCollection(Ops.GetEnumerator(y));

            foreach (object o in x)
            {
                if (set.Contains(o) == Ops.FALSE)
                {
                    return(Ops.FALSE);
                }
            }
            return(Ops.TRUE);
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 17
0
        private static SetCollection Make(PythonType /*!*/ cls, SetStorage items)
        {
            if (cls == TypeCache.Set)
            {
                return(new SetCollection(items));
            }

            SetCollection res = PythonCalls.Call(cls) as SetCollection;

            Debug.Assert(res != null);

            if (items.Count > 0)
            {
                res._items = items;
            }
            return(res);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates a set that can be hashable.  If the set is currently a FrozenSet the
        /// set is returned.  If the set is a normal Set then a FrozenSet is returned
        /// with its contents.
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static object GetHashableSetIfSet(object o)
        {
            SetCollection asSet = o as SetCollection;

            if (asSet != null)
            {
                if (asSet.GetType() != typeof(SetCollection))
                {
                    // subclass of set, need to check if it is hashable
                    if (IsHashable(asSet))
                    {
                        return(o);
                    }
                }
                return(FrozenSetCollection.Make(((IEnumerable)asSet).GetEnumerator()));
            }
            return(o);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public static ISet SymmetricDifference(ISet x, object y)
        {
            SetCollection otherSet = new SetCollection(Ops.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) == Ops.TRUE) {
                    res.PrivRemove(o);
                } else {
                    res.PrivAdd(o);
                }
            }
            res.PrivFreeze();
            return res;
        }
Ejemplo n.º 21
0
 public SetCollection intersection(SetCollection set)
 {
     return(Make(SetStorage.Intersection(_items, set._items)));
 }
Ejemplo n.º 22
0
 public SetCollection union(SetCollection set)
 {
     return(Make(SetStorage.Union(_items, set._items)));
 }
Ejemplo n.º 23
0
 public bool issuperset(SetCollection set)
 {
     return(set._items.IsSubset(_items));
 }
Ejemplo n.º 24
0
        // *** BEGIN GENERATED CODE ***
        // generated by function: _gen_setops from: generate_set.py

        public bool isdisjoint(SetCollection set)
        {
            return(_items.IsDisjoint(set._items));
        }
Ejemplo n.º 25
0
 public static object IsSubset(ISet x, object y)
 {
     SetCollection set = new SetCollection(Ops.GetEnumerator(y));
     foreach (object o in x) {
         if (set.Contains(o) == Ops.FALSE) {
             return Ops.FALSE;
         }
     }
     return Ops.TRUE;
 }
Ejemplo n.º 26
0
 public SetCollection InPlaceExclusiveOr(SetCollection set)
 {
     symmetric_difference_update(set);
     return(this);
 }
Ejemplo n.º 27
0
 public SetCollection InPlaceBitwiseOr(SetCollection set)
 {
     update(set);
     return(this);
 }
Ejemplo n.º 28
0
 public FrozenSetCollection symmetric_difference(SetCollection set)
 {
     return(Make(SetStorage.SymmetricDifference(_items, set._items)));
 }
Ejemplo n.º 29
0
 public FrozenSetCollection difference(SetCollection set)
 {
     return(Make(
                SetStorage.Difference(_items, set._items)
                ));
 }
Ejemplo n.º 30
0
 public SetCollection InPlaceBitwiseAnd(SetCollection set)
 {
     intersection_update(set);
     return(this);
 }
Ejemplo n.º 31
0
 public void SymmetricDifferenceUpdate(object s)
 {
     SetCollection set = new SetCollection(Ops.GetEnumerator(s));
     foreach (object o in set) {
         if (Contains(o) == Ops.TRUE) {
             Remove(o);
         } else {
             Add(o);
         }
     }
 }
Ejemplo n.º 32
0
 public SetCollection InPlaceSubtract(SetCollection set)
 {
     difference_update(set);
     return(this);
 }
Ejemplo n.º 33
0
 public void __init__([NotNull] SetCollection set)
 {
     _items = set._items.Clone();
 }