Beispiel #1
0
                public override Digit Update(int index, Leaf <TValue> leaf, Lineage lineage)
                {
                    if (Lineage.AllowMutation(lineage))
                    {
                        return(Update_MUTATES(index, leaf));
                    }
#if ASSERTS
                    leaf.AssertNotNull();
#endif
                    var    whereIsThisIndex = WhereIsThisIndex(index);
                    TChild res;
                    switch (whereIsThisIndex)
                    {
                    case IN_START:
                    case IN_MIDDLE_OF_1:
                        res = First.Update(index, leaf, lineage);
                        return(CreateCheckNull(lineage, res, Second, Third, Fourth));

                    case IN_START_OF_2:
                    case IN_MIDDLE_OF_2:
                        res = Second.Update(index - First.Measure, leaf, lineage);
                        return(CreateCheckNull(lineage, First, res, Third, Fourth));

                    case IN_START_OF_3:
                    case IN_MIDDLE_OF_3:
                        res = Third.Update(index - First.Measure - Second.Measure, leaf, lineage);
                        return(CreateCheckNull(lineage, First, Second, res, Fourth));

                    case IN_START_OF_4:
                    case IN_MIDDLE_OF_4:
                        res = Fourth.Update(index - First.Measure - Second.Measure - Third.Measure, leaf, lineage);
                        return(CreateCheckNull(lineage, First, Second, Third, res));

                    case IN_END:
                    case OUTSIDE:
                        throw ImplErrors.Arg_out_of_range("index", index);

                    default:
                        throw ImplErrors.Invalid_execution_path("Checked all index locations.");
                    }
                }
Beispiel #2
0
                public override void Insert(int index, Leaf <TValue> leaf, out Digit leftmost, out Digit rightmost, Lineage lineage)
                {
#if ASSERTS
                    leaf.AssertNotNull();
#endif

                    var    whereIsThisIndex = WhereIsThisIndex(index);
                    TChild myLeftmost;
                    TChild myRightmost;
                    leftmost  = null;
                    rightmost = null;
                    switch (whereIsThisIndex)
                    {
                    case IN_START:
                    case IN_MIDDLE_OF_1:
                        First.Insert(index, leaf, out myLeftmost, out myRightmost, lineage);
                        if (Size == 4 && myRightmost != null)
                        {
                            leftmost  = new Digit(myLeftmost, myRightmost, Second, lineage);
                            rightmost = MutateOrCreate(Third, Fourth, lineage);
                            return;
                        }
                        leftmost = myRightmost != null
                                                                ? CreateCheckNull(lineage, myLeftmost, myRightmost, Second, Third)
                                                                : CreateCheckNull(lineage, myLeftmost, Second, Third, Fourth);

                        rightmost = null;
                        return;

                    case IN_START_OF_2:
                    case IN_MIDDLE_OF_2:
                        Second.Insert(index - First.Measure, leaf, out myLeftmost, out myRightmost, lineage);
                        if (Size == 4 && myRightmost != null)
                        {
                            leftmost  = new Digit(First, myLeftmost, myRightmost, lineage);
                            rightmost = MutateOrCreate(Third, Fourth, lineage);
                            return;
                        }
                        leftmost = myRightmost != null
                                                                ? CreateCheckNull(lineage, First, myLeftmost, myRightmost, Third)
                                                                : CreateCheckNull(lineage, First, myLeftmost, Third, Fourth);

                        rightmost = null;
                        return;

                    case IN_START_OF_3:
                    case IN_MIDDLE_OF_3:
                        Third.Insert(index - First.Measure - Second.Measure, leaf, out myLeftmost, out myRightmost, lineage);
                        if (Size == 4 && myRightmost != null)
                        {
                            leftmost  = new Digit(First, Second, myLeftmost, lineage);
                            rightmost = MutateOrCreate(myRightmost, Fourth, lineage);
                            return;
                        }
                        leftmost =
                            myRightmost != null
                                                                        ? CreateCheckNull(lineage, First, Second, myLeftmost, myRightmost)
                                                                        : CreateCheckNull(lineage, First, Second, myLeftmost, Fourth);

                        rightmost = null;
                        return;

                    case IN_START_OF_4:
                    case IN_MIDDLE_OF_4:
                        Fourth.Insert(index - Measure + Fourth.Measure, leaf, out myLeftmost, out myRightmost, lineage);
                        if (Size == 4 && myRightmost != null)
                        {
                            leftmost  = new Digit(First, Second, Third, lineage);
                            rightmost = MutateOrCreate(myLeftmost, myRightmost, lineage);
                            return;
                        }
                        leftmost  = MutateOrCreate(First, Second, Third, myLeftmost, lineage);
                        rightmost = null;
                        return;

                    default:
                        throw ImplErrors.Invalid_execution_path("");
                    }
                }