Exemple #1
0
        private static VersioningTree <TKey, TValue> SetKeyValue(VersioningTree <TKey, TValue> me, TKey key, TValue value, Func <TKey, TKey, int> compareFunction)
        {
            if (me == null)
            {
                return(new VersioningTree <TKey, TValue>(key, value, null, null));
            }

            return(me.SetKeyValue(key, value, compareFunction));
        }
        public VersioningTree <TKey, TValue> SetKeyValue(TKey key, TValue value, Func <TKey, TKey, int> compareFunction)
        {
            VersioningTree <TKey, TValue> leftChild;
            VersioningTree <TKey, TValue> rightChild;
            TKey   tKey;
            TValue tValue;
            VersioningTree <TKey, TValue> versioningTree;
            VersioningTree <TKey, TValue> rightChild1;
            TKey   tKey1;
            TValue tValue1;
            VersioningTree <TKey, TValue> leftChild1      = this.LeftChild;
            VersioningTree <TKey, TValue> versioningTree1 = this.RightChild;
            int num = compareFunction(key, this.Key);

            if (num >= 0)
            {
                if (num != 0)
                {
                    if (VersioningTree <TKey, TValue> .GetHeight(leftChild1) >= VersioningTree <TKey, TValue> .GetHeight(versioningTree1))
                    {
                        return(new VersioningTree <TKey, TValue>(this.Key, this.Value, leftChild1, VersioningTree <TKey, TValue> .SetKeyValue(versioningTree1, key, value, compareFunction)));
                    }
                    else
                    {
                        int    num1    = compareFunction(key, versioningTree1.Key);
                        TKey   tKey2   = this.Key;
                        TValue tValue2 = this.Value;
                        VersioningTree <TKey, TValue> versioningTree2 = leftChild1;
                        if (num1 < 0)
                        {
                            leftChild = VersioningTree <TKey, TValue> .SetKeyValue(versioningTree1.LeftChild, key, value, compareFunction);
                        }
                        else
                        {
                            leftChild = versioningTree1.LeftChild;
                        }
                        VersioningTree <TKey, TValue> versioningTree3 = new VersioningTree <TKey, TValue>(tKey2, tValue2, versioningTree2, leftChild);
                        if (num1 > 0)
                        {
                            rightChild = VersioningTree <TKey, TValue> .SetKeyValue(versioningTree1.RightChild, key, value, compareFunction);
                        }
                        else
                        {
                            rightChild = versioningTree1.RightChild;
                        }
                        VersioningTree <TKey, TValue> versioningTree4 = rightChild;
                        if (num1 == 0)
                        {
                            tKey = key;
                        }
                        else
                        {
                            tKey = versioningTree1.Key;
                        }
                        if (num1 == 0)
                        {
                            tValue = value;
                        }
                        else
                        {
                            tValue = versioningTree1.Value;
                        }
                        return(new VersioningTree <TKey, TValue>(tKey, tValue, versioningTree3, versioningTree4));
                    }
                }
                else
                {
                    return(new VersioningTree <TKey, TValue>(key, value, leftChild1, versioningTree1));
                }
            }
            else
            {
                if (VersioningTree <TKey, TValue> .GetHeight(leftChild1) <= VersioningTree <TKey, TValue> .GetHeight(versioningTree1))
                {
                    return(new VersioningTree <TKey, TValue>(this.Key, this.Value, VersioningTree <TKey, TValue> .SetKeyValue(leftChild1, key, value, compareFunction), versioningTree1));
                }
                else
                {
                    int num2 = compareFunction(key, leftChild1.Key);
                    if (num2 < 0)
                    {
                        versioningTree = VersioningTree <TKey, TValue> .SetKeyValue(leftChild1.LeftChild, key, value, compareFunction);
                    }
                    else
                    {
                        versioningTree = leftChild1.LeftChild;
                    }
                    VersioningTree <TKey, TValue> versioningTree5 = versioningTree;
                    TKey   tKey3   = this.Key;
                    TValue tValue3 = this.Value;
                    if (num2 > 0)
                    {
                        rightChild1 = VersioningTree <TKey, TValue> .SetKeyValue(leftChild1.RightChild, key, value, compareFunction);
                    }
                    else
                    {
                        rightChild1 = leftChild1.RightChild;
                    }
                    VersioningTree <TKey, TValue> versioningTree6 = new VersioningTree <TKey, TValue>(tKey3, tValue3, rightChild1, versioningTree1);
                    if (num2 == 0)
                    {
                        tKey1 = key;
                    }
                    else
                    {
                        tKey1 = leftChild1.Key;
                    }
                    if (num2 == 0)
                    {
                        tValue1 = value;
                    }
                    else
                    {
                        tValue1 = leftChild1.Value;
                    }
                    return(new VersioningTree <TKey, TValue>(tKey1, tValue1, versioningTree5, versioningTree6));
                }
            }
        }