Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public static void HashSetConstructor_IEn_IEq_Comparer_Custom()
        {
            Item[] items = new Item[] { new Item(1), new Item(2), new Item(3), new Item(4) };
            IEqualityComparer <Item>  comparer = new ItemEqualityComparer();
            HashSet <Item>            hashSet  = new HashSet <Item>(items, comparer);
            HashSetTestSupport <Item> driver   = new HashSetTestSupport <Item>(hashSet, Item.GenerateNext, items, comparer);

            driver.VerifyHashSetTests();
        }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public static void HashSetConstructor_IEn_IEq_Comparer_Custom()
 {
     Item[] items = new Item[] { new Item(1), new Item(2), new Item(3), new Item(4) };
     IEqualityComparer<Item> comparer = new ItemEqualityComparer();
     HashSet<Item> hashSet = new HashSet<Item>(items, comparer);
     HashSetTestSupport<Item> driver = new HashSetTestSupport<Item>(hashSet, Item.GenerateNext, items, comparer);
     driver.VerifyHashSetTests();
 }