Exemple #1
0
            public bool TryGetValue(T equalValue, out T actualValue)
            {
                var hashcode = this._comparer.GetHashCode(equalValue);

                // We must capture the _buckets field in a local variable. It is set to a new table on each table resize.
                var tables = this._tables;

                var bucketNo = ConcurrentHashSet <T> .GetBucket(hashcode, tables.Buckets.Length);

                // We can get away w/out a lock here.
                // The Volatile.Read ensures that the load of the fields of 'n' doesn't move before the load from buckets[i].
                var current = Volatile.Read(ref tables.Buckets[bucketNo]);

                while (current != null)
                {
                    if (hashcode == current.Hashcode && this._comparer.Equals(current.Item, equalValue))
                    {
                        actualValue = current.Item;
                        return(true);
                    }

                    current = current.Next;
                }

                #pragma warning disable
                actualValue = default;
                #pragma warning restore
                return(false);
            }