OrdMerge(FTreeM <OrdElem <T, V>, V> ordTree1, FTreeM <OrdElem <T, V>, V> ordTree2 ) { ViewL <OrdElem <T, V>, V> lView2 = ordTree2.LeftView(); if (lView2 == null) { return(ordTree1); } //else OrdElem <T, V> bHead = lView2.head; FTreeM <OrdElem <T, V>, V> bTail = lView2.ftTail; // Split ordTree1 on elems <= and then > bHead Pair <FTreeM <OrdElem <T, V>, V>, FTreeM <OrdElem <T, V>, V> > tree1Split = ordTree1.SeqSplit (new MPredicate <V> (FP.Curry <V, V, bool> (theLEMethod2, bHead.Measure())) ); FTreeM <OrdElem <T, V>, V> leftTree1 = tree1Split.first; FTreeM <OrdElem <T, V>, V> rightTree1 = tree1Split.second; // OrdMerge the tail of ordTree2 // with the right-split part of ordTree1 FTreeM <OrdElem <T, V>, V> mergedRightparts = OrdMerge(bTail, rightTree1); return(leftTree1.Merge(mergedRightparts.Push_Front(bHead))); }
public OrderedSequence <T, V> Insert(T t) { Pair <OrderedSequence <T, V>, OrderedSequence <T, V> > tPart = Partition(KeyObj.KeyAssign(t)); OrdElem <T, V> tOrd = new OrdElem <T, V>(t, KeyObj); return(new OrderedSequence <T, V> ( KeyObj, tPart.first.treeRep.Merge(tPart.second.treeRep.Push_Front(tOrd)) )); }
OrderedSequence <T, V> Push_Front(OrdElem <T, V> ordEl) { var viewL = treeRep.LeftView(); if (viewL != null) { if (treeRep.LeftView().head.Measure() .CompareTo(ordEl.Measure()) < 0) { throw new Exception( "OrderedSequence Error: PushFront() of an element greater than the smallest seq el." ); } } //else return(new OrderedSequence <T, V>(KeyObj, treeRep.Push_Front(ordEl))); }
OrderedSequence <T, V> Push_Back(OrdElem <T, V> ordEl) { var viewR = treeRep.RightView(); if (viewR != null) { if (viewR.last.Measure() .CompareTo(ordEl.Measure()) > 0) { throw new Exception( "OrderedSequence Error: PushBack() of an element less than the biggest seq el." ); } } //else return(new OrderedSequence <T, V>(KeyObj, treeRep.Push_Back(ordEl))); }