Exemplo n.º 1
0
                public override FTree <TChild> AddFirst(TChild item, Lineage lineage)
                {
                    FTree <TChild> ret;

#if ASSERTS
                    var expectedSize = Measure + item.Measure;
#endif
                    if (LeftDigit.Size < 4)
                    {
                        ret = MutateOrCreate(LeftDigit.AddFirst(item, lineage), DeepTree, RightDigit, lineage);
                    }
                    else
                    {
                        var leftmost  = new Digit(item, LeftDigit.First, lineage);
                        var rightmost = LeftDigit.RemoveFirst(lineage);
                        var newDeep   = DeepTree.AddFirst(rightmost, lineage);
                        ret = MutateOrCreate(leftmost, newDeep, RightDigit, lineage);
                    }
#if ASSERTS
                    ret.Measure.AssertEqual(expectedSize);
                    ret.Left.AssertEqual(item);
#endif
                    return(ret);
                }
Exemplo n.º 2
0
			/// <summary>
			/// Splits the finger tree right before the specified index.
			/// </summary>
			/// <param name="index">The index.</param>
			/// <param name="left">The left.</param>
			/// <param name="right">The right.</param>
			/// <param name="lineage">The lineage.</param>
			public void Split(int index, out FTree<TChild> left, out FTree<TChild> right, Lineage lineage) {
				if (index == Measure) {
					left = this;
					right = Empty;
					return;
				}
#if ASSERTS
				var oldValue = this[index];
				var oldFirst = Left;
				var oldLast = Right;
#endif
				TChild center;
				Split(index, out left, out center, out right, lineage);
				right = right.AddFirst(center, lineage);
#if ASSERTS
				center[0].AssertEqual(oldValue);
				if (left.Measure != 0) {
					left.Left.AssertEqual(oldFirst);
				}
				if (right.Measure != 0) {
					right.Right.AssertEqual(oldLast);
				}
#endif
			}