public void remove([NotNull] SetCollection o) { var set = SetHelpers.GetHashableSetIfSet(o); if (!_items.RemoveAlwaysHash(set)) { throw PythonOps.KeyError(o); } }
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); }
public SetCollection symmetric_difference(SetCollection set) { if (ReferenceEquals(set, this)) { return(Empty); } return(Make(SetStorage.SymmetricDifference(_items, set._items))); }
/// <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); }
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)); }
public ISet __rsub__(ISet s) { SetCollection set = s as SetCollection; if (set != null) { return(set.Difference(this)); } return(SetHelpers.MakeSet(this, s.PrivDifference(this))); }
public void update(SetCollection set) { if (ReferenceEquals(set, this)) { return; } lock (_items) { _items.UnionUpdate(set._items); } }
public void intersection_update(SetCollection set) { if (object.ReferenceEquals(set, this)) { return; } lock (_items) { _items.IntersectionUpdate(set._items); } }
public SetCollection difference(SetCollection set) { if (object.ReferenceEquals(set, this)) { return(Empty); } return(Make( SetStorage.Difference(_items, set._items) )); }
public void difference_update(object s) { SetCollection set = new SetCollection(PythonOps.GetEnumerator(s)); foreach (object o in set) { if (__contains__(o)) { remove(o); } } }
public void difference_update([NotNull] SetCollection set) { if (object.ReferenceEquals(set, this)) { _items.Clear(); return; } lock (_items) { _items.DifferenceUpdate(set._items); } }
public void DifferenceUpdate(object s) { SetCollection set = new SetCollection(Ops.GetEnumerator(s)); foreach (object o in set) { if (Contains(o) == Ops.TRUE) { Remove(o); } } }
public void symmetric_difference_update(SetCollection set) { if (object.ReferenceEquals(set, this)) { _items.Clear(); return; } lock (_items) { _items.SymmetricDifferenceUpdate(set._items); } }
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); }
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))); }
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))); }
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); }
/// <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 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); }
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; }
public SetCollection intersection(SetCollection set) { return(Make(SetStorage.Intersection(_items, set._items))); }
public SetCollection union(SetCollection set) { return(Make(SetStorage.Union(_items, set._items))); }
public bool issuperset(SetCollection set) { return(set._items.IsSubset(_items)); }
// *** BEGIN GENERATED CODE *** // generated by function: _gen_setops from: generate_set.py public bool isdisjoint(SetCollection set) { return(_items.IsDisjoint(set._items)); }
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; }
public SetCollection InPlaceExclusiveOr(SetCollection set) { symmetric_difference_update(set); return(this); }
public SetCollection InPlaceBitwiseOr(SetCollection set) { update(set); return(this); }
public FrozenSetCollection symmetric_difference(SetCollection set) { return(Make(SetStorage.SymmetricDifference(_items, set._items))); }
public FrozenSetCollection difference(SetCollection set) { return(Make( SetStorage.Difference(_items, set._items) )); }
public SetCollection InPlaceBitwiseAnd(SetCollection set) { intersection_update(set); return(this); }
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); } } }
public SetCollection InPlaceSubtract(SetCollection set) { difference_update(set); return(this); }
public void __init__([NotNull] SetCollection set) { _items = set._items.Clone(); }