コード例 #1
0
            private bool FindNext(SegmentedDictionaryNode node, ContextItem <int, SegmentedDictionaryNode> curContext)
            {
                bool flag = false;

                while (!flag && curContext.Key < node.Entries.Length)
                {
                    ISegmentedDictionaryEntry segmentedDictionaryEntry = node.Entries[curContext.Key];
                    if (segmentedDictionaryEntry != null)
                    {
                        switch (segmentedDictionaryEntry.EntryType)
                        {
                        case SegmentedDictionaryEntryType.Node:
                        {
                            SegmentedDictionaryNode value = segmentedDictionaryEntry as SegmentedDictionaryNode;
                            m_context.Push(new ContextItem <int, SegmentedDictionaryNode>(0, value));
                            flag = FindNext();
                            break;
                        }

                        case SegmentedDictionaryEntryType.Values:
                        {
                            SegmentedDictionaryValues segmentedDictionaryValues = segmentedDictionaryEntry as SegmentedDictionaryValues;
                            if (m_currentValueIndex < segmentedDictionaryValues.Count)
                            {
                                m_currentPair = new KeyValuePair <TKey, TValue>(segmentedDictionaryValues.Keys[m_currentValueIndex], segmentedDictionaryValues.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);
            }
コード例 #2
0
        private bool Find(SegmentedDictionaryNode node, int hashCode, TKey key, int level, out TValue value)
        {
            value = default(TValue);
            bool result = false;
            int  num    = HashToSlot(node, hashCode, level);
            ISegmentedDictionaryEntry segmentedDictionaryEntry = node.Entries[num];

            if (segmentedDictionaryEntry != null)
            {
                switch (segmentedDictionaryEntry.EntryType)
                {
                case SegmentedDictionaryEntryType.Node:
                {
                    SegmentedDictionaryNode node2 = segmentedDictionaryEntry as SegmentedDictionaryNode;
                    result = Find(node2, hashCode, key, level + 1, out value);
                    break;
                }

                case SegmentedDictionaryEntryType.Values:
                {
                    SegmentedDictionaryValues segmentedDictionaryValues = segmentedDictionaryEntry as SegmentedDictionaryValues;
                    for (int i = 0; i < segmentedDictionaryValues.Count; i++)
                    {
                        if (m_comparer.Equals(key, segmentedDictionaryValues.Keys[i]))
                        {
                            value = segmentedDictionaryValues.Values[i];
                            return(true);
                        }
                    }
                    break;
                }

                default:
                    Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                    break;
                }
            }
            return(result);
        }
コード例 #3
0
        private bool Remove(SegmentedDictionaryNode node, int hashCode, TKey key, int level, out int newCount)
        {
            bool flag = false;
            int  num  = HashToSlot(node, hashCode, level);
            ISegmentedDictionaryEntry segmentedDictionaryEntry = node.Entries[num];

            if (segmentedDictionaryEntry == null)
            {
                flag = false;
            }
            else
            {
                switch (segmentedDictionaryEntry.EntryType)
                {
                case SegmentedDictionaryEntryType.Node:
                {
                    SegmentedDictionaryNode node2 = segmentedDictionaryEntry as SegmentedDictionaryNode;
                    flag = Remove(node2, hashCode, key, level + 1, out int newCount2);
                    if (flag && newCount2 == 0)
                    {
                        node.Entries[num] = null;
                    }
                    break;
                }

                case SegmentedDictionaryEntryType.Values:
                {
                    SegmentedDictionaryValues segmentedDictionaryValues = segmentedDictionaryEntry as SegmentedDictionaryValues;
                    for (int i = 0; i < segmentedDictionaryValues.Count; i++)
                    {
                        if (!m_comparer.Equals(key, segmentedDictionaryValues.Keys[i]))
                        {
                            continue;
                        }
                        if (segmentedDictionaryValues.Count == 1)
                        {
                            node.Entries[num] = null;
                        }
                        else
                        {
                            segmentedDictionaryValues.Keys[i]   = default(TKey);
                            segmentedDictionaryValues.Values[i] = default(TValue);
                            segmentedDictionaryValues.Count--;
                            int num2 = segmentedDictionaryValues.Count - i;
                            if (num2 > 0)
                            {
                                Array.Copy(segmentedDictionaryValues.Keys, i + 1, segmentedDictionaryValues.Keys, i, num2);
                                Array.Copy(segmentedDictionaryValues.Values, i + 1, segmentedDictionaryValues.Values, i, num2);
                            }
                        }
                        flag = true;
                        break;
                    }
                    break;
                }

                default:
                    Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                    break;
                }
            }
            if (flag)
            {
                node.Count--;
            }
            newCount = node.Count;
            return(flag);
        }
コード例 #4
0
        private bool Insert(SegmentedDictionaryNode node, int hashCode, TKey key, TValue value, bool add, int level)
        {
            bool flag = false;
            int  num  = HashToSlot(node, hashCode, level);
            ISegmentedDictionaryEntry segmentedDictionaryEntry = node.Entries[num];

            if (segmentedDictionaryEntry == null)
            {
                SegmentedDictionaryValues segmentedDictionaryValues = new SegmentedDictionaryValues(m_valuesCapacity);
                segmentedDictionaryValues.Keys[0]   = key;
                segmentedDictionaryValues.Values[0] = value;
                segmentedDictionaryValues.Count++;
                node.Entries[num] = segmentedDictionaryValues;
                flag = true;
            }
            else
            {
                switch (segmentedDictionaryEntry.EntryType)
                {
                case SegmentedDictionaryEntryType.Node:
                {
                    SegmentedDictionaryNode node2 = segmentedDictionaryEntry as SegmentedDictionaryNode;
                    flag = Insert(node2, hashCode, key, value, add, level + 1);
                    break;
                }

                case SegmentedDictionaryEntryType.Values:
                {
                    SegmentedDictionaryValues segmentedDictionaryValues2 = segmentedDictionaryEntry as SegmentedDictionaryValues;
                    bool flag2 = false;
                    for (int i = 0; i < segmentedDictionaryValues2.Count; i++)
                    {
                        if (m_comparer.Equals(key, segmentedDictionaryValues2.Keys[i]))
                        {
                            if (add)
                            {
                                Global.Tracer.Assert(condition: false, "SegmentedDictionary: An element with the same key already exists within the Dictionary");
                            }
                            segmentedDictionaryValues2.Values[i] = value;
                            flag2 = true;
                            flag  = false;
                            break;
                        }
                    }
                    if (flag2)
                    {
                        break;
                    }
                    if (segmentedDictionaryValues2.Count < segmentedDictionaryValues2.Capacity)
                    {
                        int count = segmentedDictionaryValues2.Count;
                        segmentedDictionaryValues2.Keys[count]   = key;
                        segmentedDictionaryValues2.Values[count] = value;
                        segmentedDictionaryValues2.Count++;
                        flag = true;
                        break;
                    }
                    SegmentedDictionaryNode segmentedDictionaryNode = BuildNode(level + 1, m_nodeCapacity);
                    node.Entries[num] = segmentedDictionaryNode;
                    for (int j = 0; j < segmentedDictionaryValues2.Count; j++)
                    {
                        TKey val = segmentedDictionaryValues2.Keys[j];
                        Insert(segmentedDictionaryNode, m_comparer.GetHashCode(val), val, segmentedDictionaryValues2.Values[j], add: false, level + 1);
                    }
                    flag = Insert(segmentedDictionaryNode, hashCode, key, value, add, level + 1);
                    break;
                }

                default:
                    Global.Tracer.Assert(condition: false, "Unknown ObjectType");
                    break;
                }
            }
            if (flag)
            {
                node.Count++;
            }
            return(flag);
        }
コード例 #5
0
        private bool Remove(SegmentedDictionaryNode node, int hashCode, TKey key, int level, out int newCount)
        {
            bool flag = false;
            int  num  = this.HashToSlot(node, hashCode, level);
            ISegmentedDictionaryEntry segmentedDictionaryEntry = node.Entries[num];

            if (segmentedDictionaryEntry == null)
            {
                flag = false;
            }
            else
            {
                switch (segmentedDictionaryEntry.EntryType)
                {
                case SegmentedDictionaryEntryType.Node:
                {
                    SegmentedDictionaryNode node2 = segmentedDictionaryEntry as SegmentedDictionaryNode;
                    int num4 = default(int);
                    flag = this.Remove(node2, hashCode, key, level + 1, out num4);
                    if (flag && num4 == 0)
                    {
                        node.Entries[num] = null;
                    }
                    break;
                }

                case SegmentedDictionaryEntryType.Values:
                {
                    SegmentedDictionaryValues segmentedDictionaryValues = segmentedDictionaryEntry as SegmentedDictionaryValues;
                    int num2 = 0;
                    while (num2 < segmentedDictionaryValues.Count)
                    {
                        if (!this.m_comparer.Equals(key, segmentedDictionaryValues.Keys[num2]))
                        {
                            num2++;
                            continue;
                        }
                        if (segmentedDictionaryValues.Count == 1)
                        {
                            node.Entries[num] = null;
                        }
                        else
                        {
                            segmentedDictionaryValues.Keys[num2]   = default(TKey);
                            segmentedDictionaryValues.Values[num2] = default(TValue);
                            segmentedDictionaryValues.Count--;
                            int num3 = segmentedDictionaryValues.Count - num2;
                            if (num3 > 0)
                            {
                                Array.Copy(segmentedDictionaryValues.Keys, num2 + 1, segmentedDictionaryValues.Keys, num2, num3);
                                Array.Copy(segmentedDictionaryValues.Values, num2 + 1, segmentedDictionaryValues.Values, num2, num3);
                            }
                        }
                        flag = true;
                        break;
                    }
                    break;
                }

                default:
                    Global.Tracer.Assert(false, "Unknown ObjectType");
                    break;
                }
            }
            if (flag)
            {
                node.Count--;
            }
            newCount = node.Count;
            return(flag);
        }