Example #1
0
        protected override void OnAdd(T item, out Iterator position)
        {
            int hashValue  = ItemEqualityComparer.GetHashCode(item);
            int tableIndex = GetTableIndexForHashValue(hashValue);

            Bucket bucket = _table[tableIndex];

            if (bucket != null)
            {
                do
                {
                    if (hashValue == bucket.HashValue && ItemEqualityComparer.Equals(item, bucket.Item))
                    {
                        break;
                    }
                    bucket = bucket.Next;
                } while (bucket != null);
            }

            if (bucket == null)
            {
                bucket             = new Bucket(item, hashValue, _table[tableIndex]);
                _table[tableIndex] = bucket;
                Size.Increment(ref _count);
            }

            position = new Iterator(this, bucket);
        }
Example #2
0
        /// <summary>
        /// Searches for bucket that contains specified item.
        /// </summary>
        /// <param name="item">The item to be found.</param>
        /// <returns>Returns bucket that contains the item or <c>null</c> if the
        /// item is not present in the set.</returns>
        private Bucket FindBucketForItem(T item)
        {
            int hashValue  = ItemEqualityComparer.GetHashCode(item);
            int tableIndex = GetTableIndexForHashValue(hashValue);

            Bucket bucket = _table[tableIndex];

            if (bucket != null)
            {
                do
                {
                    if (hashValue == bucket.HashValue && ItemEqualityComparer.Equals(item, bucket.Item))
                    {
                        break;
                    }
                    bucket = bucket.Next;
                } while (bucket != null);
            }

            return(bucket);
        }