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))); }
public void remove([NotNull] SetCollection o) { var set = SetHelpers.GetHashableSetIfSet(o); if (!_items.RemoveAlwaysHash(set)) { throw PythonOps.KeyError(o); } }
public ISet difference([NotNull] params object[] ss) { ISet res = this; foreach (object s in ss) { res = SetHelpers.Difference(res, s); } return(res); }
public ISet intersection([NotNull] params object[] ss) { ISet res = this; foreach (object s in ss) { res = SetHelpers.Intersection(res, s); } return(res); }
bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer) { ISet set = other as ISet; if (set != null) { return(SetHelpers.Equals(this, set, comparer)); } return(false); }
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)); }
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)); }
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); }
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 Remove(object o) { o = SetHelpers.GetHashableSetIfSet(o); Ops.Hash(o); if (!items.ContainsKey(o)) { throw Ops.KeyError("{0}", o.ToString()); } items.Remove(o); }
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 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); }
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); }
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))); }
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); }
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); }
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); }
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 ISet Union(object s) { return(SetHelpers.Union(this, s)); }
public object IsSubset(object s) { return(SetHelpers.IsSubset(this, s)); }
public override string ToString() { return(SetHelpers.SetToString(this, this.items.Keys)); }
public ISet difference() { return(SetHelpers.MakeSet(this, this)); }
public virtual string /*!*/ __repr__(CodeContext /*!*/ context) { return(SetHelpers.SetToString(context, this, _items)); }
public void Discard(object o) { o = SetHelpers.GetHashableSetIfSet(o); items.Remove(o); }
public ISet Intersection(object s) { return(SetHelpers.Intersection(this, s)); }
public ISet SymmetricDifference(object s) { return(SetHelpers.SymmetricDifference(this, s)); }
public ISet Difference(object s) { return(SetHelpers.Difference(this, s)); }