示例#1
0
        /// <summary>
        /// Initializes buckets and slots arrays. Uses suggested capacity by finding next prime
        /// greater than or equal to capacity.
        /// </summary>
        /// <param name="capacity"></param>
        private void Initialize(int capacity)
        {
            int size = HashSetCopyableHashHelpers.GetPrime(capacity);

            m_buckets = new int[size];
            m_slots   = new Slot[size];
        }
示例#2
0
        /// <summary>
        /// Expand to new capacity. New capacity is next prime greater than or equal to suggested
        /// size. This is called when the underlying array is filled. This performs no
        /// defragmentation, allowing faster execution; note that this is reasonable since
        /// AddIfNotPresent attempts to insert new elements in re-opened spots.
        /// </summary>
        /// <param name="sizeSuggestion"></param>
        private void IncreaseCapacity()
        {
            int newSize = HashSetCopyableHashHelpers.ExpandPrime(m_count);

            if (newSize <= m_count)
            {
                throw new ArgumentException();
            }

            // Able to increase capacity; copy elements to larger array and rehash
            SetCapacity(newSize, false);
        }