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); }
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); }
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); }
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); }
/// <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); }
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); } }
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); } }
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); } }
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); }
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); }
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); }
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); }
public SetCollection difference(FrozenSetCollection set) { return(Make( SetStorage.Difference(_items, set._items) )); }
public SetCollection symmetric_difference(FrozenSetCollection set) { return(Make(SetStorage.SymmetricDifference(_items, set._items))); }
public SetCollection union(FrozenSetCollection set) { return(Make(SetStorage.Union(_items, set._items))); }
public SetCollection intersection(FrozenSetCollection set) { return(Make(SetStorage.Intersection(_items, set._items))); }
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; } }
public bool issuperset(FrozenSetCollection set) { return(set._items.IsSubset(_items)); }
public void symmetric_difference_update(FrozenSetCollection set) { lock (_items) { _items.SymmetricDifferenceUpdate(set._items); } }
public SetCollection InPlaceExclusiveOr(FrozenSetCollection set) { symmetric_difference_update(set); return(this); }
public void intersection_update(FrozenSetCollection set) { lock (_items) { _items.IntersectionUpdate(set._items); } }
public void difference_update(FrozenSetCollection set) { lock (_items) { _items.DifferenceUpdate(set._items); } }
public void update(FrozenSetCollection set) { lock (_items) { _items.UnionUpdate(set._items); } }
public bool issubset([NotNull] FrozenSetCollection set) { return(_items.IsSubset(set._items)); }
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; } }
public SetCollection InPlaceBitwiseOr(FrozenSetCollection set) { update(set); return(this); }
public void __init__([NotNull] FrozenSetCollection set) { _items = set._items.Clone(); }
public SetCollection InPlaceBitwiseAnd(FrozenSetCollection set) { intersection_update(set); return(this); }
public bool isdisjoint(FrozenSetCollection set) { return(_items.IsDisjoint(set._items)); }
public SetCollection InPlaceSubtract(FrozenSetCollection set) { difference_update(set); return(this); }
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; }