public bool Equals(InterningBag <T> x, InterningBag <T> y) { if (x == null) { return(y == null); } if (ReferenceEquals(x, y)) { return(true); } if (y == null) { return(false); } if (x._backingSize != y._backingSize) { return(false); } for (var i = 0; i < x._backingSize; i++) { var selfId = x._backing[i]; var has = false; for (var j = 0; j < y._backingSize; j++) { var otherId = y._backing[j]; if (!Comparer.Equals(selfId, otherId)) { continue; } has = true; break; } if (!has) { return(false); } } return(true); }
private static InterningBag <T> Intern(InterningBag <T> tmp) { while (true) { if (InternPool.TryGetValue(tmp, out var interned)) { if (Pool.Count < 1000) { Pool.Return(tmp); } return(interned); } // ReSharper disable once InvertIf if (InternPool.TryAdd(tmp, tmp)) { // Interned objects should have a minimal footprint. Array.Resize(ref tmp._backing, tmp._backingSize); return(tmp); } } }
public int GetHashCode(InterningBag <T> obj) => obj.GetHashCode();
public bool Equals(InterningBag <T> other) { return(ReferenceEquals(other, this)); }