예제 #1
0
        public void Clear(ConcurrentHashtable <TStored, TSearch> traits)
        {
            var oldList = _List;

            _List = new TStored[4];

            var effect = _List.Length - oldList.Length;

            if (effect != 0)
            {
                traits.EffectTotalAllocatedSpace(effect);
            }

            _Count = 0;
        }
예제 #2
0
 /// <summary>
 /// When segment gets removed from hashtable then its allocated space should be subtracted to the
 /// total allocated space.
 /// Single threaded access or locking is needed
 /// </summary>
 /// <param name="traits"></param>
 public void Bye(ConcurrentHashtable <TStored, TSearch> traits)
 {
     traits.EffectTotalAllocatedSpace(-_List.Length);
     _List = null;
 }
예제 #3
0
 /// <summary>
 /// When segment gets introduced into hashtable then its allocated space should be added to the
 /// total allocated space.
 /// Single threaded access or locking is needed
 /// </summary>
 /// <param name="traits"></param>
 public void Welcome(ConcurrentHashtable <TStored, TSearch> traits)
 {
     traits.EffectTotalAllocatedSpace(_List.Length);
 }
예제 #4
0
        protected virtual void ResizeList(ConcurrentHashtable <TStored, TSearch> traits)
        {
            var oldList       = _List;
            var oldListLength = oldList.Length;

            var newListLength = 2;

            while (newListLength < _Count)
            {
                newListLength <<= 1;
            }

            newListLength <<= 1;

            if (newListLength != oldListLength)
            {
                _List = new TStored[newListLength];

                var mask = (UInt32)(newListLength - 1);

                for (int i = 0; i != oldListLength; ++i)
                {
                    if (!traits.IsEmpty(ref oldList[i]))
                    {
                        var searchHash = traits.GetItemHashCode(ref oldList[i]);

                        //j is prefered insertion pos in new list.
                        var j = searchHash & mask;

                        if (traits.IsEmpty(ref _List[j]))
                        {
                            _List[j] = oldList[i];
                        }
                        else
                        {
                            var firstHash      = traits.GetItemHashCode(ref _List[j]);
                            var storedItemHash = firstHash;
                            var searchHashDiff = (searchHash - firstHash) & mask;

                            while (true)
                            {
                                j = (j + 1) & mask;

                                if (traits.IsEmpty(ref _List[j]))
                                {
                                    _List[j] = oldList[i];
                                    break;
                                }

                                storedItemHash = traits.GetItemHashCode(ref _List[j]);

                                if (((storedItemHash - firstHash) & mask) > searchHashDiff)
                                {
                                    InsertItemAtIndex(mask, j, oldList[i], traits);
                                    break;
                                }
                            }
                        }
                    }
                }

                traits.EffectTotalAllocatedSpace(newListLength - oldListLength);
            }
        }