internal bool Contains(object x, object y) { if (!IsReferencePair(x, y)) { return(false); } using (var pair = ReferencePair.GetOrCreate(x, y)) { return(this.pairs.Contains(pair)); } }
public bool Equals(ReferencePair other) { Debug.Assert(!this.disposed, "this.disposed"); if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(ReferenceEquals(this.X, other.X) && ReferenceEquals(this.Y, other.Y)); }
internal bool?Add(object x, object y) { if (!IsReferencePair(x, y)) { return(null); } var refCounted = ReferencePair.GetOrCreate(x, y); var added = this.pairs.Add(refCounted); if (!added) { refCounted.Dispose(); } return(added); }
internal static IRefCounted <TValue> GetOrAdd <TKey, TValue>( TKey x, TKey y, MemberSettings settings, ConditionalWeakTable <IRefCounted <ReferencePair>, TValue> .CreateValueCallback creator, out bool created) where TKey : class where TValue : class, IDisposable { var refCounted = ReferencePair.GetOrCreate(x, y); var value = GetOrAdd(refCounted, settings, creator, out created); if (!created) { refCounted.Dispose(); } return(value); }
public static IRefCounted <ReferencePair> GetOrCreate <T>(T x, T y) where T : class { var key = new ReferencePair(x, y); if (!Cache.GetOrAdd(key, p => p).TryRefCount(out var refcounted)) { if (!Cache.TryAdd(key, key)) { throw Throw.ShouldNeverGetHereException("Adding created pair failed"); } if (!key.TryRefCount(out refcounted)) { throw Throw.ShouldNeverGetHereException("Refcounting created pair failed"); } } return(refcounted); }
private bool Equals(ReferencePair x, ReferencePair y) { return(ReferenceEquals(x.X, y.X) && ReferenceEquals(x.Y, y.Y)); }