Ejemplo n.º 1
0
        protected GroupingInternal <TKey, TElement> Create(TKey key, int hashCode)
        {
            if (Count == _groupings.Length)
            {
                _groupings = Resize();
            }

            int index = hashCode % _groupings.Length;
            GroupingInternal <TKey, TElement> g = new GroupingInternal <TKey, TElement>(this);

            g._key            = key;
            g._hashCode       = hashCode;
            g._hashNext       = _groupings[index];
            _groupings[index] = g;
            if (_lastGrouping == null)
            {
                g._next = g;
            }
            else
            {
                g._next             = _lastGrouping._next;
                _lastGrouping._next = g;
            }

            _lastGrouping = g;
            Count++;
            return(g);
        }
Ejemplo n.º 2
0
        private GroupingInternal <TKey, TElement>[] Resize()
        {
            int newSize = checked ((Count * 2) + 1);

            GroupingInternal <TKey, TElement>[] newGroupings = new GroupingInternal <TKey, TElement> [newSize];
            GroupingInternal <TKey, TElement>   g            = _lastGrouping;

            do
            {
                g = g._next;
                int index = g._hashCode % newSize;
                g._hashNext         = newGroupings[index];
                newGroupings[index] = g;
            }while (g != _lastGrouping);

            return(newGroupings);
        }