Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 public static FrozenSetCollection __new__(CodeContext context, object cls)
 {
     if (cls == TypeCache.FrozenSet)
     {
         return(EMPTY);
     }
     else
     {
         PythonType          dt  = cls as PythonType;
         object              res = dt.CreateInstance(context);
         FrozenSetCollection fs  = res as FrozenSetCollection;
         if (fs == null)
         {
             throw PythonOps.TypeError("{0} is not a subclass of frozenset", res);
         }
         return(fs);
     }
 }
Exemplo n.º 7
0
 public static FrozenSetCollection NewInst(object cls)
 {
     if (cls == TypeCache.FrozenSet)
     {
         FrozenSetCollection fs = new FrozenSetCollection();
         return(fs);
     }
     else
     {
         object res             = ((PythonType)cls).ctor.Call(cls);
         FrozenSetCollection fs = res as FrozenSetCollection;
         if (fs == null)
         {
             throw Ops.TypeError("{0} is not a subclass of frozenset", res);
         }
         return(fs);
     }
 }
Exemplo n.º 8
0
        public static FrozenSetCollection __new__(CodeContext /*!*/ context, object cls, object set)
        {
            if (cls == TypeCache.FrozenSet)
            {
                return(Make(TypeCache.FrozenSet, set));
            }
            else
            {
                object res             = ((PythonType)cls).CreateInstance(context, set);
                FrozenSetCollection fs = res as FrozenSetCollection;
                if (fs == null)
                {
                    throw PythonOps.TypeError("{0} is not a subclass of frozenset", res);
                }

                return(fs);
            }
        }
Exemplo n.º 9
0
        int IStructuralEquatable.GetHashCode(IEqualityComparer /*!*/ comparer)
        {
            if (CompareUtil.Check(this))
            {
                return(0);
            }

            int res;

            CompareUtil.Push(this);
            try {
                res = ((IStructuralEquatable)FrozenSetCollection.Make(_items)).GetHashCode(comparer);
            } finally {
                CompareUtil.Pop(this);
            }

            return(res);
        }
Exemplo n.º 10
0
        private static FrozenSetCollection Make(PythonType /*!*/ cls, SetStorage items)
        {
            if (cls == TypeCache.FrozenSet)
            {
                if (items.Count == 0)
                {
                    return(_empty);
                }
                return(new FrozenSetCollection(items));
            }

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

            Debug.Assert(res != null);

            if (items.Count > 0)
            {
                res._items = items;
            }
            return(res);
        }
Exemplo n.º 11
0
        internal static FrozenSetCollection Make(object setData)
        {
            FrozenSetCollection fs = setData as FrozenSetCollection;

            if (fs != null)
            {
                // constructing frozen set from frozen set, we return the original frozen set.
                return(fs);
            }

            CommonDictionaryStorage items = ListToDictionary(setData);

            if (items.Count == 0)
            {
                fs = EMPTY;
            }
            else
            {
                fs = new FrozenSetCollection(items);
            }

            return(fs);
        }
Exemplo n.º 12
0
        int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
        {
            if (CompareUtil.Check(this))
            {
                return(0);
            }

            int  res;
            ISet pairs = new FrozenSetCollection();

            foreach (KeyValuePair <object, object> kvp in _storage.GetItems())
            {
                pairs.PrivAdd(PythonTuple.MakeTuple(kvp.Key, kvp.Value));
            }

            CompareUtil.Push(this);
            try {
                res = pairs.GetHashCode(comparer);
            } finally {
                CompareUtil.Pop(this);
            }

            return(res);
        }
Exemplo n.º 13
0
 public SetCollection difference(FrozenSetCollection set)
 {
     return(Make(
                SetStorage.Difference(_items, set._items)
                ));
 }
Exemplo n.º 14
0
 public SetCollection symmetric_difference(FrozenSetCollection set)
 {
     return(Make(SetStorage.SymmetricDifference(_items, set._items)));
 }
Exemplo n.º 15
0
 public SetCollection union(FrozenSetCollection set)
 {
     return(Make(SetStorage.Union(_items, set._items)));
 }
Exemplo n.º 16
0
 public SetCollection intersection(FrozenSetCollection set)
 {
     return(Make(SetStorage.Intersection(_items, set._items)));
 }
Exemplo n.º 17
0
        public static FrozenSetCollection NewInst(object cls, object setData)
        {
            if (cls == TypeCache.FrozenSet) {
                FrozenSetCollection fs = setData as FrozenSetCollection;
                if (fs != null) {
                    // constructing frozen set from set, we return the original frozen set.
                    return fs;
                }

                fs = new FrozenSetCollection(setData);
                return fs;
            } else {
                object res = ((DynamicType)cls).ctor.Call(cls, setData);
                FrozenSetCollection fs = res as FrozenSetCollection;
                if (fs == null) throw Ops.TypeError("{0} is not a subclass of frozenset", res);

                return fs;
            }
        }
Exemplo n.º 18
0
 public bool issuperset(FrozenSetCollection set)
 {
     return(set._items.IsSubset(_items));
 }
Exemplo n.º 19
0
 public void symmetric_difference_update(FrozenSetCollection set)
 {
     lock (_items) {
         _items.SymmetricDifferenceUpdate(set._items);
     }
 }
Exemplo n.º 20
0
 public SetCollection InPlaceExclusiveOr(FrozenSetCollection set)
 {
     symmetric_difference_update(set);
     return(this);
 }
Exemplo n.º 21
0
 public void intersection_update(FrozenSetCollection set)
 {
     lock (_items) {
         _items.IntersectionUpdate(set._items);
     }
 }
Exemplo n.º 22
0
 public void difference_update(FrozenSetCollection set)
 {
     lock (_items) {
         _items.DifferenceUpdate(set._items);
     }
 }
Exemplo n.º 23
0
 public void update(FrozenSetCollection set)
 {
     lock (_items) {
         _items.UnionUpdate(set._items);
     }
 }
Exemplo n.º 24
0
 public bool issubset([NotNull] FrozenSetCollection set)
 {
     return(_items.IsSubset(set._items));
 }
Exemplo n.º 25
0
 public static FrozenSetCollection NewInst(object cls)
 {
     if (cls == TypeCache.FrozenSet) {
         FrozenSetCollection fs = new FrozenSetCollection();
         return fs;
     } else {
         object res = ((DynamicType)cls).ctor.Call(cls);
         FrozenSetCollection fs = res as FrozenSetCollection;
         if (fs == null) throw Ops.TypeError("{0} is not a subclass of frozenset", res);
         return fs;
     }
 }
Exemplo n.º 26
0
 public SetCollection InPlaceBitwiseOr(FrozenSetCollection set)
 {
     update(set);
     return(this);
 }
Exemplo n.º 27
0
 public void __init__([NotNull] FrozenSetCollection set)
 {
     _items = set._items.Clone();
 }
Exemplo n.º 28
0
 public SetCollection InPlaceBitwiseAnd(FrozenSetCollection set)
 {
     intersection_update(set);
     return(this);
 }
Exemplo n.º 29
0
 public bool isdisjoint(FrozenSetCollection set)
 {
     return(_items.IsDisjoint(set._items));
 }
Exemplo n.º 30
0
 public SetCollection InPlaceSubtract(FrozenSetCollection set)
 {
     difference_update(set);
     return(this);
 }
Exemplo n.º 31
0
        internal static FrozenSetCollection Make(object setData)
        {
            FrozenSetCollection fs = setData as FrozenSetCollection;
            if (fs != null) {
                // constructing frozen set from set, we return the original frozen set.
                return fs;
            }

            fs = new FrozenSetCollection(setData);
            return fs;
        }