示例#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 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()
     });
 }
            private bool FindNext(ScalableDictionaryNode node, ContextItem <int, ScalableDictionaryNodeReference> curContext)
            {
                bool flag = false;

                while (!flag && curContext.Key < node.Entries.Length)
                {
                    IScalableDictionaryEntry scalableDictionaryEntry = node.Entries[curContext.Key];
                    if (scalableDictionaryEntry != null)
                    {
                        switch (scalableDictionaryEntry.GetObjectType())
                        {
                        case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNodeReference:
                        {
                            ScalableDictionaryNodeReference value = scalableDictionaryEntry as ScalableDictionaryNodeReference;
                            m_context.Push(new ContextItem <int, ScalableDictionaryNodeReference>(0, value));
                            flag = FindNext();
                            break;
                        }

                        case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryValues:
                        {
                            ScalableDictionaryValues scalableDictionaryValues = scalableDictionaryEntry as ScalableDictionaryValues;
                            if (m_currentValueIndex < scalableDictionaryValues.Count)
                            {
                                m_currentPair = new KeyValuePair <TKey, TValue>((TKey)scalableDictionaryValues.Keys[m_currentValueIndex], (TValue)scalableDictionaryValues.Values[m_currentValueIndex]);
                                m_currentValueIndex++;
                                return(true);
                            }
                            m_currentValueIndex = 0;
                            break;
                        }

                        default:
                            Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                            break;
                        }
                    }
                    curContext.Key++;
                }
                if (!flag)
                {
                    m_currentValueIndex = 0;
                    m_context.Pop();
                }
                return(flag);
            }
        private bool Find(ScalableDictionaryNodeReference nodeRef, int hashCode, TKey key, int level, out TValue value, out IDisposable containingNodeRef)
        {
            containingNodeRef = null;
            IDisposable            disposable             = nodeRef.PinValue();
            ScalableDictionaryNode scalableDictionaryNode = nodeRef.Value();

            value = default(TValue);
            bool result = false;
            int  num    = HashToSlot(scalableDictionaryNode, hashCode, level);
            IScalableDictionaryEntry scalableDictionaryEntry = scalableDictionaryNode.Entries[num];

            if (scalableDictionaryEntry != null)
            {
                switch (scalableDictionaryEntry.GetObjectType())
                {
                case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNodeReference:
                {
                    ScalableDictionaryNodeReference nodeRef2 = scalableDictionaryEntry as ScalableDictionaryNodeReference;
                    result = Find(nodeRef2, hashCode, key, level + 1, out value, out containingNodeRef);
                    break;
                }

                case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryValues:
                {
                    ScalableDictionaryValues scalableDictionaryValues = scalableDictionaryEntry as ScalableDictionaryValues;
                    for (int i = 0; i < scalableDictionaryValues.Count; i++)
                    {
                        if (m_comparer.Equals(key, (TKey)scalableDictionaryValues.Keys[i]))
                        {
                            value             = (TValue)scalableDictionaryValues.Values[i];
                            containingNodeRef = disposable;
                            return(true);
                        }
                    }
                    break;
                }

                default:
                    Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                    break;
                }
            }
            disposable.Dispose();
            return(result);
        }
        private bool Remove(ScalableDictionaryNodeReference nodeRef, int hashCode, TKey key, int level, out int newCount)
        {
            using (nodeRef.PinValue())
            {
                ScalableDictionaryNode scalableDictionaryNode = nodeRef.Value();
                bool flag = false;
                int  num  = HashToSlot(scalableDictionaryNode, hashCode, level);
                IScalableDictionaryEntry scalableDictionaryEntry = scalableDictionaryNode.Entries[num];
                if (scalableDictionaryEntry == null)
                {
                    flag = false;
                }
                else
                {
                    switch (scalableDictionaryEntry.GetObjectType())
                    {
                    case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNodeReference:
                    {
                        ScalableDictionaryNodeReference scalableDictionaryNodeReference = scalableDictionaryEntry as ScalableDictionaryNodeReference;
                        flag = Remove(scalableDictionaryNodeReference, hashCode, key, level + 1, out int newCount2);
                        if (flag && newCount2 == 0)
                        {
                            scalableDictionaryNode.Entries[num] = null;
                            scalableDictionaryNodeReference.Free();
                        }
                        break;
                    }

                    case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryValues:
                    {
                        ScalableDictionaryValues scalableDictionaryValues = scalableDictionaryEntry as ScalableDictionaryValues;
                        for (int i = 0; i < scalableDictionaryValues.Count; i++)
                        {
                            if (!m_comparer.Equals(key, (TKey)scalableDictionaryValues.Keys[i]))
                            {
                                continue;
                            }
                            if (scalableDictionaryValues.Count == 1)
                            {
                                scalableDictionaryNode.Entries[num] = null;
                            }
                            else
                            {
                                scalableDictionaryValues.Keys[i]   = null;
                                scalableDictionaryValues.Values[i] = null;
                                scalableDictionaryValues.Count--;
                                int num2 = scalableDictionaryValues.Count - i;
                                if (num2 > 0)
                                {
                                    Array.Copy(scalableDictionaryValues.Keys, i + 1, scalableDictionaryValues.Keys, i, num2);
                                    Array.Copy(scalableDictionaryValues.Values, i + 1, scalableDictionaryValues.Values, i, num2);
                                }
                            }
                            flag = true;
                            break;
                        }
                        break;
                    }

                    default:
                        Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                        break;
                    }
                }
                if (flag)
                {
                    scalableDictionaryNode.Count--;
                }
                newCount = scalableDictionaryNode.Count;
                return(flag);
            }
        }
        private bool Insert(ScalableDictionaryNodeReference nodeRef, int hashCode, TKey key, TValue value, bool add, int level, bool updateSize, out IDisposable cleanupRef)
        {
            IDisposable            disposable             = nodeRef.PinValue();
            ScalableDictionaryNode scalableDictionaryNode = nodeRef.Value();
            bool flag = false;
            int  num  = HashToSlot(scalableDictionaryNode, hashCode, level);
            IScalableDictionaryEntry scalableDictionaryEntry = scalableDictionaryNode.Entries[num];

            if (scalableDictionaryEntry == null)
            {
                ScalableDictionaryValues scalableDictionaryValues = new ScalableDictionaryValues(m_valuesCapacity);
                scalableDictionaryValues.Keys[0]   = key;
                scalableDictionaryValues.Values[0] = value;
                scalableDictionaryValues.Count++;
                scalableDictionaryNode.Entries[num] = scalableDictionaryValues;
                flag       = true;
                cleanupRef = disposable;
                if (!m_useFixedReferences && updateSize)
                {
                    int sizeBytesDelta = ItemSizes.SizeOfInObjectArray(key) + ItemSizes.SizeOfInObjectArray(value) + scalableDictionaryValues.EmptySize;
                    nodeRef.UpdateSize(sizeBytesDelta);
                }
            }
            else
            {
                switch (scalableDictionaryEntry.GetObjectType())
                {
                case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryNodeReference:
                {
                    ScalableDictionaryNodeReference nodeRef2 = scalableDictionaryEntry as ScalableDictionaryNodeReference;
                    flag = Insert(nodeRef2, hashCode, key, value, add, level + 1, updateSize, out cleanupRef);
                    break;
                }

                case Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.ObjectType.ScalableDictionaryValues:
                {
                    ScalableDictionaryValues scalableDictionaryValues2 = scalableDictionaryEntry as ScalableDictionaryValues;
                    bool flag2 = false;
                    cleanupRef = null;
                    for (int i = 0; i < scalableDictionaryValues2.Count; i++)
                    {
                        if (m_comparer.Equals(key, (TKey)scalableDictionaryValues2.Keys[i]))
                        {
                            if (add)
                            {
                                Global.Tracer.Assert(condition: false, "ScalableDictionary: An element with the same key already exists within the Dictionary");
                            }
                            scalableDictionaryValues2.Values[i] = value;
                            flag2      = true;
                            flag       = false;
                            cleanupRef = disposable;
                            break;
                        }
                    }
                    if (flag2)
                    {
                        break;
                    }
                    if (scalableDictionaryValues2.Count < scalableDictionaryValues2.Capacity)
                    {
                        int count = scalableDictionaryValues2.Count;
                        scalableDictionaryValues2.Keys[count]   = key;
                        scalableDictionaryValues2.Values[count] = value;
                        scalableDictionaryValues2.Count++;
                        flag       = true;
                        cleanupRef = disposable;
                        if (!m_useFixedReferences && updateSize)
                        {
                            nodeRef.UpdateSize(ItemSizes.SizeOfInObjectArray(key));
                            nodeRef.UpdateSize(ItemSizes.SizeOfInObjectArray(value));
                        }
                        break;
                    }
                    ScalableDictionaryNodeReference scalableDictionaryNodeReference = BuildNode(level + 1, m_nodeCapacity);
                    scalableDictionaryNode.Entries[num] = scalableDictionaryNodeReference;
                    using (scalableDictionaryNodeReference.PinValue())
                    {
                        if (!m_useFixedReferences && updateSize)
                        {
                            int num2 = ItemSizes.SizeOfInObjectArray(scalableDictionaryValues2);
                            nodeRef.UpdateSize(num2 * -1);
                            scalableDictionaryNodeReference.UpdateSize(num2);
                        }
                        for (int j = 0; j < scalableDictionaryValues2.Count; j++)
                        {
                            TKey key2 = (TKey)scalableDictionaryValues2.Keys[j];
                            Insert(scalableDictionaryNodeReference, GetHashCode(key2), key2, (TValue)scalableDictionaryValues2.Values[j], add: false, level + 1, updateSize: false, out IDisposable cleanupRef2);
                            cleanupRef2.Dispose();
                        }
                        flag = Insert(scalableDictionaryNodeReference, hashCode, key, value, add, level + 1, updateSize, out cleanupRef);
                    }
                    break;
                }

                default:
                    Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                    cleanupRef = null;
                    break;
                }
            }
            if (flag)
            {
                scalableDictionaryNode.Count++;
            }
            if (disposable != cleanupRef)
            {
                disposable.Dispose();
            }
            return(flag);
        }