예제 #1
0
        void Grow()
        {
            var oldData = _data;
            var oldSize = oldData.Slots.Length;
            var newSize = oldSize * 2;

            var newSlots = new Slot[newSize];

            Array.Copy(oldData.Slots, newSlots, oldSize);

            var newBuckets = new int[newSize];

            for (var i = 0; i < oldSize; i++)
            {
                var bucket = newSlots[i].HashCode.Value % newSize;
                newSlots[i].Next   = newBuckets[bucket] - 1;
                newBuckets[bucket] = i + 1;
            }

            _data = new BucketsAndSlots(newBuckets, newSlots, oldData.NextAvailableSlotIndex);
        }
예제 #2
0
 /// <summary>
 /// Initializes an empty set.
 /// </summary>
 /// <param name="initialSize">The initial number of strings the set can contain before having to resize its internal datastructures.</param>
 public StringSet(int initialSize)
 {
     _data = new BucketsAndSlots(new int[initialSize], new Slot[initialSize], 0);
 }