コード例 #1
0
        public bool TryCreateObject(ObjectType objectType, out IPersistable persistObj)
        {
            switch (objectType)
            {
            case ObjectType.StorageItem:
                persistObj = new StorageItem();
                break;

            case ObjectType.ScalableDictionaryNode:
                persistObj = new ScalableDictionaryNode();
                break;

            case ObjectType.ScalableDictionaryValues:
                persistObj = new ScalableDictionaryValues();
                break;

            case ObjectType.StorableArray:
                persistObj = new StorableArray();
                break;

            case ObjectType.ScalableHybridListEntry:
                persistObj = new ScalableHybridListEntry();
                break;

            default:
                persistObj = null;
                return(false);
            }
            return(true);
        }
コード例 #2
0
        private IDisposable SetAndPin(int index, T item, bool fromAdd)
        {
            this.CheckIndex(index, this.m_count - 1);
            IDisposable result;

            if (this.m_array != null)
            {
                result = this.m_array.PinValue();
                this.m_array.Value().Array[index] = item;
                if (fromAdd)
                {
                    this.m_array.UpdateSize(ItemSizes.SizeOfInObjectArray(item));
                }
            }
            else
            {
                int bucketIndex = this.GetBucketIndex(index);
                IReference <StorableArray> reference          = this.m_buckets[bucketIndex];
                UnPinCascadeHolder         unPinCascadeHolder = new UnPinCascadeHolder();
                unPinCascadeHolder.AddCleanupRef(reference.PinValue());
                this.m_buckets.PinContainingBucket(bucketIndex, unPinCascadeHolder);
                result = unPinCascadeHolder;
                StorableArray storableArray = reference.Value();
                storableArray.Array[this.GetIndexInBucket(index)] = item;
                if (fromAdd)
                {
                    reference.UpdateSize(ItemSizes.SizeOfInObjectArray(item));
                }
            }
            return(result);
        }
コード例 #3
0
 private void SetValue(int index, T value, bool fromAdd)
 {
     this.CheckIndex(index, this.m_count - 1);
     if (this.m_array != null)
     {
         using (this.m_array.PinValue())
         {
             this.m_array.Value().Array[index] = value;
             if (fromAdd)
             {
                 this.m_array.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
             }
         }
     }
     else
     {
         IReference <StorableArray> reference = this.m_buckets[this.GetBucketIndex(index)];
         using (reference.PinValue())
         {
             StorableArray storableArray = reference.Value();
             storableArray.Array[this.GetIndexInBucket(index)] = value;
             if (fromAdd)
             {
                 reference.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
             }
         }
     }
     this.m_version++;
 }
コード例 #4
0
 public T this[int index]
 {
     get
     {
         this.CheckIndex(index, this.m_count - 1);
         if (this.m_array != null)
         {
             using (this.m_array.PinValue())
             {
                 return((T)this.m_array.Value().Array[index]);
             }
         }
         IReference <StorableArray> reference = this.m_buckets[this.GetBucketIndex(index)];
         using (reference.PinValue())
         {
             StorableArray bucket = reference.Value();
             return(this.GetValueAt(index, bucket));
         }
     }
     set
     {
         this.CheckReadOnly("set value");
         this.SetValue(index, value, false);
     }
 }
コード例 #5
0
        private T GetValueAt(int index, StorableArray bucket)
        {
            object obj = bucket.Array[this.GetIndexInBucket(index)];

            if (obj == null)
            {
                return(default(T));
            }
            return((T)obj);
        }
コード例 #6
0
        private static List <Declaration> BuildDeclarations()
        {
            List <Declaration> list = new List <Declaration>(8);

            list.Add(BaseReference.GetDeclaration());
            list.Add(ScalableList <StorageItem> .GetDeclaration());
            list.Add(ScalableDictionary <int, StorageItem> .GetDeclaration());
            list.Add(ScalableDictionaryNode.GetDeclaration());
            list.Add(ScalableDictionaryValues.GetDeclaration());
            list.Add(StorageItem.GetDeclaration());
            list.Add(StorableArray.GetDeclaration());
            list.Add(ScalableHybridListEntry.GetDeclaration());
            return(list);
        }
コード例 #7
0
        public int BinarySearch(T value, IComparer comparer)
        {
            if (comparer == null)
            {
                Global.Tracer.Assert(false, "Cannot pass null comparer to BinarySearch");
            }
            if (this.m_array != null)
            {
                StorableArray storableArray = this.m_array.Value();
                return(Array.BinarySearch(storableArray.Array, 0, this.Count, value, comparer));
            }
            ArrayList arrayList = ArrayList.Adapter(this);

            return(arrayList.BinarySearch(value, comparer));
        }
コード例 #8
0
        public IDisposable GetAndPin(int index, out T item)
        {
            this.CheckIndex(index, this.m_count - 1);
            if (this.m_array != null)
            {
                this.m_array.PinValue();
                item = (T)this.m_array.Value().Array[index];
                return((IDisposable)this.m_array);
            }
            IReference <StorableArray> reference = this.m_buckets[this.GetBucketIndex(index)];

            reference.PinValue();
            StorableArray bucket = reference.Value();

            item = this.GetValueAt(index, bucket);
            return((IDisposable)reference);
        }
コード例 #9
0
 private void EnsureCapacity(int count)
 {
     if (count > this.m_capacity)
     {
         if (this.m_array == null && this.m_buckets == null)
         {
             StorableArray storableArray = new StorableArray();
             storableArray.Array = new object[count];
             int emptySize = storableArray.EmptySize;
             if (this.m_bucketPinState == BucketPinState.UntilBucketFull || this.m_bucketPinState == BucketPinState.UntilListEnd)
             {
                 this.m_array = this.m_cache.AllocateAndPin <StorableArray>(storableArray, this.m_priority, emptySize);
             }
             else
             {
                 this.m_array = this.m_cache.Allocate <StorableArray>(storableArray, this.m_priority, emptySize);
             }
             this.m_capacity = count;
         }
         if (this.m_array != null)
         {
             if (count <= this.m_bucketSize)
             {
                 int num = Math.Min(Math.Max(count, this.m_capacity * 2), this.m_bucketSize);
                 using (this.m_array.PinValue())
                 {
                     StorableArray storableArray2 = this.m_array.Value();
                     Array.Resize <object>(ref storableArray2.Array, num);
                 }
                 this.m_capacity = num;
             }
             else
             {
                 if (this.m_capacity < this.m_bucketSize)
                 {
                     using (this.m_array.PinValue())
                     {
                         StorableArray storableArray3 = this.m_array.Value();
                         Array.Resize <object>(ref storableArray3.Array, this.m_bucketSize);
                     }
                     this.m_capacity = this.m_bucketSize;
                 }
                 this.m_buckets = new ScalableList <IReference <StorableArray> >(this.m_priority, this.m_cache, 100, 10, this.m_bucketPinState == BucketPinState.UntilListEnd);
                 this.m_buckets.Add(this.m_array);
                 this.m_array = null;
             }
         }
         if (this.m_buckets != null)
         {
             while (this.GetBucketIndex(count - 1) >= this.m_buckets.Count)
             {
                 StorableArray storableArray4 = new StorableArray();
                 storableArray4.Array = new object[this.m_bucketSize];
                 int emptySize2 = storableArray4.EmptySize;
                 if (this.m_bucketPinState == BucketPinState.UntilListEnd)
                 {
                     IReference <StorableArray> item = this.m_cache.AllocateAndPin <StorableArray>(storableArray4, this.m_priority, emptySize2);
                     this.m_buckets.Add(item);
                 }
                 else if (this.m_bucketPinState == BucketPinState.UntilBucketFull)
                 {
                     IReference <StorableArray> item = this.m_cache.AllocateAndPin <StorableArray>(storableArray4, this.m_priority, emptySize2);
                     this.m_buckets.AddAndPin(item);
                 }
                 else
                 {
                     IReference <StorableArray> item = this.m_cache.Allocate <StorableArray>(storableArray4, this.m_priority, emptySize2);
                     this.m_buckets.Add(item);
                 }
                 this.m_capacity += this.m_bucketSize;
             }
         }
     }
 }