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); }
public override TSize IndexOf(T item) { for (TSize i = Size.Zero; Size.Compare(i, _count) < 0; Size.Increment(ref i)) { if (ItemEqualityComparer.Equals(item, Size.GetValueFromArray <T>(_innerArray, i))) { return(i); } } return(Size.From(-1)); }
/// <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); }