/// <summary> /// Inserts a sequence at the specified index, pushing the element at the index forward. /// </summary> /// <param name="index"> The index. </param> /// <param name="items"> The sequence of items to insert. Very fast if the sequence is also an <see cref="ImmList{T}" />.</param> /// <returns> </returns> /// <exception cref="ArgumentOutOfRangeException">Thrown if the index doesn't exist.</exception> /// <exception cref="ArgumentNullException">Thrown if the IEnumerable is null.</exception> public ImmList <T> InsertRange(int index, IEnumerable <T> items) { items.CheckNotNull("items"); index.CheckIsBetween("index", -Root.Measure - 1, Root.Measure); index = index < 0 ? index + Length + 1 : index; if (index == 0) { return(AddFirstRange(items)); } if (index == Root.Measure) { return(AddLastRange(items)); } var list = items as ImmList <T>; if (list != null) { return(InsertList(index, list)); } FingerTree <T> .FTree <Leaf <T> > part1, part2; Root.Split(index, out part1, out part2, Lineage.Immutable); int len; var i = 0; var arr = items.ToArrayFast(out len); var lineage = Lineage.Mutable(); var middle = FingerTree <T> .FTree <Leaf <T> > .Construct(arr, ref i, len, lineage); return(part1.AddLastList(middle, Lineage.Immutable).AddLastList(part2, Lineage.Immutable).Wrap()); }
public override Split <FingerTree <WeightedElement <T>, double>, WeightedElement <T>, double> Split(Func <double, bool> p, double a) { var split = _finger.Split(p, a); split.Left = new PriorityQueue <T>(split.Left); split.Right = new PriorityQueue <T>(split.Right); return(split); }
public override Split <FingerTree <SizedElement <T>, int>, SizedElement <T>, int> Split(Func <int, bool> p, int a) { var split = _finger.Split(p, a); split.Left = new FingerArray <T>(split.Left); split.Right = new FingerArray <T>(split.Right); return(split); }
static FingerTree <OrderedElement <T, V>, V> Merge(FingerTree <OrderedElement <T, V>, V> f, FingerTree <OrderedElement <T, V>, V> g) { var v = g.LeftView(); if (v == null) { return(f); } var end = v.End; var rest = v.Rest; var fsplit = f.Split(((Func <V, V, bool>)LessThanOrEqual).Curry(end.Measure())); var fleft = fsplit.Left; var fright = fsplit.Right; var merged = Merge(rest, fright); return(fleft.Merge(merged.PushLeft(end))); }
public Pair <OrderedSequence <T, V>, OrderedSequence <T, V> > Partition(V v) { var split = _finger.Split(((Func <V, V, bool>)LessThanOrEqual).Curry(v)); return(new Pair <OrderedSequence <T, V>, OrderedSequence <T, V> >(new OrderedSequence <T, V>(_x, split.Left), new OrderedSequence <T, V>(_x, split.Right))); }