/// <summary> /// Creates a new sorted wrapper, sorting by BytesRef /// (ascending) then cost (ascending). /// </summary> public SortedInputIterator(IInputIterator source, IComparer <BytesRef> comparer) { this.tieBreakByCostComparer = Comparer <BytesRef> .Create((left, right) => { SortedInputIterator outerInstance = this; BytesRef leftScratch = new BytesRef(); BytesRef rightScratch = new BytesRef(); ByteArrayDataInput input = new ByteArrayDataInput(); // Make shallow copy in case decode changes the BytesRef: leftScratch.Bytes = left.Bytes; leftScratch.Offset = left.Offset; leftScratch.Length = left.Length; rightScratch.Bytes = right.Bytes; rightScratch.Offset = right.Offset; rightScratch.Length = right.Length; long leftCost = outerInstance.Decode(leftScratch, input); long rightCost = outerInstance.Decode(rightScratch, input); if (outerInstance.HasPayloads) { outerInstance.DecodePayload(leftScratch, input); outerInstance.DecodePayload(rightScratch, input); } if (outerInstance.HasContexts) { outerInstance.DecodeContexts(leftScratch, input); outerInstance.DecodeContexts(rightScratch, input); } // LUCENENET NOTE: outerInstance.Comparer != outerInstance.comparer!! int cmp = outerInstance.comparer.Compare(leftScratch, rightScratch); if (cmp != 0) { return(cmp); } if (leftCost < rightCost) { return(-1); } else if (leftCost > rightCost) { return(1); } else { return(0); } }); this.hasPayloads = source.HasPayloads; this.hasContexts = source.HasContexts; this.source = source; this.comparer = comparer; this.reader = Sort(); }
public virtual int Compare(BytesRef left, BytesRef right) { // Make shallow copy in case decode changes the BytesRef: leftScratch.Bytes = left.Bytes; leftScratch.Offset = left.Offset; leftScratch.Length = left.Length; rightScratch.Bytes = right.Bytes; rightScratch.Offset = right.Offset; rightScratch.Length = right.Length; long leftCost = outerInstance.Decode(leftScratch, input); long rightCost = outerInstance.Decode(rightScratch, input); if (outerInstance.HasPayloads) { outerInstance.DecodePayload(leftScratch, input); outerInstance.DecodePayload(rightScratch, input); } if (outerInstance.HasContexts) { outerInstance.DecodeContexts(leftScratch, input); outerInstance.DecodeContexts(rightScratch, input); } // LUCENENET NOTE: outerInstance.Comparator != outerInstance.comparator!! int cmp = outerInstance.comparator.Compare(leftScratch, rightScratch); if (cmp != 0) { return(cmp); } if (leftCost < rightCost) { return(-1); } else if (leftCost > rightCost) { return(1); } else { return(0); } }