static FTreeM <OrderedElement <T, M>, M> OrdMerge(FTreeM <OrderedElement <T, M>, M> ordTree1, FTreeM <OrderedElement <T, M>, M> ordTree2) { ViewL <OrderedElement <T, M>, M> lView2 = ordTree2.LeftView(); if (lView2 == null) { return(ordTree1); } //else OrderedElement <T, M> bHead = lView2.head; FTreeM <OrderedElement <T, M>, M> bTail = lView2.ftTail; // Split ordTree1 on elems <= and then > bHead Pair <FTreeM <OrderedElement <T, M>, M>, FTreeM <OrderedElement <T, M>, M> > tree1Split = ordTree1.SeqSplit (new MPredicate <M> (FP.Curry <M, M, bool>(LessThanOrEqual2, bHead.Measure())) ); FTreeM <OrderedElement <T, M>, M> leftTree1 = tree1Split.First; FTreeM <OrderedElement <T, M>, M> rightTree1 = tree1Split.Second; // OrdMerge the tail of ordTree2 // with the right-split part of ordTree1 FTreeM <OrderedElement <T, M>, M> mergedRightparts = OrdMerge(bTail, rightTree1); return(leftTree1.Merge(mergedRightparts.PushFront(bHead))); }
public FNSeq <T> take(int length) { return(new FNSeq <T> ( new Seq <T> ( this.theSeq.takeUntil(new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)length)) ) ) )); }
public Pair <T, PriorityQueue <T> > extractMax() { Split <CompElement <T>, FTreeM <CompElement <T>, double>, double> trSplit = _treeRep.Split(new MPredicate <double> (FP.Curry <double, double, bool> (theLessOrEqMethod2, _treeRep.Measure()) ), Prio.theMonoid.Zero ); return(new Pair <T, PriorityQueue <T> > (trSplit.Item.Value, new PriorityQueue <T>(trSplit.Left.Merge(trSplit.Right)) )); }
public FString insert(int startInd, FString fstr2) { Pair <FTreeM <SizedElem <char>, uint>, FTreeM <SizedElem <char>, uint> > theSplit = theSeq.SeqSplit(new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)startInd))); return(new FString( new Seq <char> ( ( theSplit.first.Merge(fstr2.theSeq.treeRep) .Merge(((Seq <char>)(theSplit.second)).treeRep) ) ) )); }
public OrderedSequence <T, M> DeleteAll(T t) { M vK = _key.Accessor(t); // the Key of t Pair <OrderedSequence <T, M>, OrderedSequence <T, M> > tPart = Partition(vK); OrderedSequence <T, M> seqPrecedestheEl = tPart.First; OrderedSequence <T, M> seqStartsWiththeEl = tPart.Second; Pair <FTreeM <OrderedElement <T, M>, M>, FTreeM <OrderedElement <T, M>, M> > lastTreeSplit = seqStartsWiththeEl._tree.SeqSplit(new MPredicate <M>(FP.Curry <M, M, bool>(LessThan2, vK))); //OrderedSequence<T, V> seqBeyondtheEl = // new OrderedSequence<T, V>(KeyObj, lastTreeSplit.second); return(new OrderedSequence <T, M>(_key, seqPrecedestheEl._tree.Merge(lastTreeSplit.Second))); }
public FString remove(int startInd, int subLength) { uint theLength = theSeq.length; if (theLength == 0 || subLength <= 0) { return(this); } //else if (startInd < 1) { startInd = 0; } if (startInd + subLength > theLength) { subLength = (int)(theLength - startInd); } // Now ready to do the real work Pair <FTreeM <SizedElem <char>, uint>, FTreeM <SizedElem <char>, uint> > split1 = theSeq.SeqSplit ( new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)startInd)) ); Pair <FTreeM <SizedElem <char>, uint>, FTreeM <SizedElem <char>, uint> > split2 = split1.second.SeqSplit ( new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)subLength)) ); FString fsResult = new FString( new Seq <char> ( split1.first.Merge(((Seq <char>)(split2.second)).treeRep) ) ); return(fsResult); }
// this inserts a whole sequence, so we cannot just use Seq.snsertAt() public FNSeq <T> insert_before(int ind, FNSeq <T> fSeq2) { if (ind < 0 || ind >= this.Length()) { throw new ArgumentOutOfRangeException(); } //else Pair <FTreeM <SizedElem <T>, uint>, FTreeM <SizedElem <T>, uint> > theSplit = theSeq.SeqSplit (new MPredicate <uint> ( FP.Curry <uint, uint, bool>(theLTMethod, (uint)ind - 1) ) ); FNSeq <T> fs1 = new FNSeq <T>((Seq <T>)(theSplit.first)); FNSeq <T> fs3 = new FNSeq <T>((Seq <T>)(theSplit.second)); return(fs1.Merge(fSeq2).Merge(fs3)); }
public FNSeq <T> subsequence(int startInd, int subLength) { uint theLength = theSeq.length; if (theLength == 0 || subLength <= 0) { return(this); } //else if (startInd < 0) { startInd = 0; } if (startInd + subLength > theLength) { subLength = (int)(theLength - startInd); } // Now ready to do the real work FNSeq <T> fsResult = new FNSeq <T>( (Seq <T>) ( ((Seq <T>) (theSeq.SeqSplit ( new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)startInd)) ).second ) ).SeqSplit (new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)subLength)) ).first ) ); return(fsResult); }
public FString substring(int startInd, int subLength) { uint theLength = theSeq.length; if (theLength == 0 || subLength <= 0) { return(this); } //else if (startInd < 1) { startInd = 0; } if (startInd + subLength > theLength) { subLength = (int)(theLength - startInd); } // Now ready to do the real work FString fsResult = new FString( new Seq <char> ( theSeq.SeqSplit ( new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)startInd)) ).second .SeqSplit (new MPredicate <uint> (FP.Curry <uint, uint, bool>(theLTMethod, (uint)subLength)) ).first ) ); return(fsResult); }
Pair <OrderedSequence <T, M>, OrderedSequence <T, M> > Partition(M vK) { Pair <FTreeM <OrderedElement <T, M>, M>, FTreeM <OrderedElement <T, M>, M> > baseSeqSplit = _tree.SeqSplit(new MPredicate <M>(FP.Curry <M, M, bool>(LessThanOrEqual2, vK))); var left = new OrderedSequence <T, M>(_key, baseSeqSplit.First); var right = new OrderedSequence <T, M>(_key, baseSeqSplit.Second); return(new Pair <OrderedSequence <T, M>, OrderedSequence <T, M> >(left, right)); }