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); }
public T this[int index] { get { CheckIndex(index, m_count - 1); if (m_array != null) { using (m_array.PinValue()) { return((T)m_array.Value().Array[index]); } } IReference <StorableArray> reference = m_buckets[GetBucketIndex(index)]; using (reference.PinValue()) { StorableArray bucket = reference.Value(); return(GetValueAt(index, bucket)); } } set { CheckReadOnly("set value"); SetValue(index, value, fromAdd: false); } }
private T GetValueAt(int index, StorableArray bucket) { object obj = bucket.Array[GetIndexInBucket(index)]; if (obj == null) { return(default(T)); } return((T)obj); }
private static List <Declaration> BuildDeclarations() { return(new List <Declaration>(8) { BaseReference.GetDeclaration(), ScalableList <StorageItem> .GetDeclaration(), ScalableDictionary <int, StorageItem> .GetDeclaration(), ScalableDictionaryNode.GetDeclaration(), ScalableDictionaryValues.GetDeclaration(), StorageItem.GetDeclaration(), StorableArray.GetDeclaration(), ScalableHybridListEntry.GetDeclaration() }); }
public IDisposable GetAndPin(int index, out T item) { CheckIndex(index, m_count - 1); if (m_array != null) { m_array.PinValue(); item = (T)m_array.Value().Array[index]; return((IDisposable)m_array); } IReference <StorableArray> reference = m_buckets[GetBucketIndex(index)]; reference.PinValue(); StorableArray bucket = reference.Value(); item = GetValueAt(index, bucket); return((IDisposable)reference); }
private void EnsureCapacity(int count) { if (count <= m_capacity) { return; } if (m_array == null && m_buckets == null) { StorableArray storableArray = new StorableArray(); storableArray.Array = new object[count]; int emptySize = storableArray.EmptySize; if (m_bucketPinState == BucketPinState.UntilBucketFull || m_bucketPinState == BucketPinState.UntilListEnd) { m_array = m_cache.AllocateAndPin(storableArray, m_priority, emptySize); } else { m_array = m_cache.Allocate(storableArray, m_priority, emptySize); } m_capacity = count; } if (m_array != null) { if (count <= m_bucketSize) { int num = Math.Min(Math.Max(count, m_capacity * 2), m_bucketSize); using (m_array.PinValue()) { Array.Resize(ref m_array.Value().Array, num); } m_capacity = num; } else { if (m_capacity < m_bucketSize) { using (m_array.PinValue()) { Array.Resize(ref m_array.Value().Array, m_bucketSize); } m_capacity = m_bucketSize; } m_buckets = new ScalableList <IReference <StorableArray> >(m_priority, m_cache, 100, 10, m_bucketPinState == BucketPinState.UntilListEnd); m_buckets.Add(m_array); m_array = null; } } if (m_buckets == null) { return; } while (GetBucketIndex(count - 1) >= m_buckets.Count) { StorableArray storableArray2 = new StorableArray(); storableArray2.Array = new object[m_bucketSize]; int emptySize2 = storableArray2.EmptySize; if (m_bucketPinState == BucketPinState.UntilListEnd) { IReference <StorableArray> item = m_cache.AllocateAndPin(storableArray2, m_priority, emptySize2); m_buckets.Add(item); } else if (m_bucketPinState == BucketPinState.UntilBucketFull) { IReference <StorableArray> item = m_cache.AllocateAndPin(storableArray2, m_priority, emptySize2); m_buckets.AddAndPin(item); } else { IReference <StorableArray> item = m_cache.Allocate(storableArray2, m_priority, emptySize2); m_buckets.Add(item); } m_capacity += m_bucketSize; } }