Exemplo n.º 1
0
 public virtual DictionaryStorage Clone()
 {
     CommonDictionaryStorage storage = new CommonDictionaryStorage();
     foreach (KeyValuePair<object, object> kvp in GetItems())
     {
         storage.Add(kvp.Key, kvp.Value);
     }
     return storage;
 }
Exemplo n.º 2
0
        public override void Add(ref DictionaryStorage storage, object key, object value)
        {
            lock (this)
            {
                if (storage == this)
                {
                    CommonDictionaryStorage newStorage = new CommonDictionaryStorage();
                    newStorage.AddNoLock(key, value);
                    storage = newStorage;
                    return;
                }
            }

            // race, try again...
            storage.Add(ref storage, key, value);
        }
        private void CommonCopyTo(CommonDictionaryStorage into)
        {
            if (into._buckets == null)
            {
                into._buckets = new Bucket[_buckets.Length];
            }
            else
            {
                int curSize = into._buckets.Length;
                int newSize = (int)((_count + into._count) / Load) + 2;
                while (curSize < newSize)
                {
                    curSize *= ResizeMultiplier;
                }
                into.EnsureSize(curSize);
            }

            if (into._keyType == null)
            {
                into._keyType = _keyType;
                into._hashFunc = _hashFunc;
                into._eqFunc = _eqFunc;
            }
            else if (into._keyType != _keyType)
            {
                into.SetHeterogeneousSites();
            }

            for (int i = 0; i < _buckets.Length; i++)
            {
                Bucket curBucket = _buckets[i];

                if (curBucket.Key != null &&
                    curBucket.Key != _removed &&
                    into.AddWorker(into._buckets, curBucket.Key, curBucket.Value, curBucket.HashCode))
                {
                    into._count++;
                }
            }
        }