protected override AcceptStatus AcceptPosition(Spans spans) { bool result = spans.IsPayloadAvailable; if (result == true) { var candidate = spans.GetPayload(); if (candidate.Count == m_payloadToMatch.Count) { //TODO: check the byte arrays are the same using (var toMatchIter = m_payloadToMatch.GetEnumerator()) { //check each of the byte arrays, in order //hmm, can't rely on order here foreach (var candBytes in candidate) { toMatchIter.MoveNext(); //if one is a mismatch, then return false if (Arrays.Equals(candBytes, toMatchIter.Current) == false) { return(AcceptStatus.NO); } } } //we've verified all the bytes return(AcceptStatus.YES); } else { return(AcceptStatus.NO); } } return(AcceptStatus.YES); }
public override int End => includeSpans.End; // TODO: Remove warning after API has been finalized public override ICollection <byte[]> GetPayload() { JCG.List <byte[]> result = null; if (includeSpans.IsPayloadAvailable) { result = new JCG.List <byte[]>(includeSpans.GetPayload()); } return(result); }
public override ICollection <byte[]> GetPayload() { JCG.List <byte[]> result = null; if (spans.IsPayloadAvailable) { result = new JCG.List <byte[]>(spans.GetPayload()); } return(result); //TODO: any way to avoid the new construction? }
public override ICollection <byte[]> GetPayload() { List <byte[]> result = null; Spans theTop = Top; if (theTop != null && theTop.IsPayloadAvailable) { result = new List <byte[]>(theTop.GetPayload()); } return(result); }
protected override AcceptStatus AcceptPosition(Spans spans) { bool result = spans.IsPayloadAvailable; if (result == true) { var candidate = spans.GetPayload(); if (candidate.Count == m_payloadToMatch.Count) { //TODO: check the byte arrays are the same //hmm, can't rely on order here int matches = 0; foreach (var candBytes in candidate) { //Unfortunately, we can't rely on order, so we need to compare all foreach (var payBytes in m_payloadToMatch) { if (Arrays.Equals(candBytes, payBytes) == true) { matches++; break; } } } if (matches == m_payloadToMatch.Count) { //we've verified all the bytes return(AcceptStatus.YES); } else { return(AcceptStatus.NO); } } else { return(AcceptStatus.NO); } } return(AcceptStatus.NO); }
/// <summary> /// The <see cref="SubSpans"/> are ordered in the same doc, so there is a possible match. /// Compute the slop while making the match as short as possible by advancing /// all <see cref="SubSpans"/> except the last one in reverse order. /// </summary> private bool ShrinkToAfterShortestMatch() { matchStart = subSpans[subSpans.Length - 1].Start; matchEnd = subSpans[subSpans.Length - 1].End; var possibleMatchPayloads = new JCG.HashSet <byte[]>(); if (subSpans[subSpans.Length - 1].IsPayloadAvailable) { possibleMatchPayloads.UnionWith(subSpans[subSpans.Length - 1].GetPayload()); } IList <byte[]> possiblePayload = null; int matchSlop = 0; int lastStart = matchStart; int lastEnd = matchEnd; for (int i = subSpans.Length - 2; i >= 0; i--) { Spans prevSpans = subSpans[i]; if (collectPayloads && prevSpans.IsPayloadAvailable) { possiblePayload = new List <byte[]>(prevSpans.GetPayload()); // LUCENENET specific - using copy constructor instead of AddRange() } int prevStart = prevSpans.Start; int prevEnd = prevSpans.End; while (true) // Advance prevSpans until after (lastStart, lastEnd) { if (!prevSpans.Next()) { inSameDoc = false; more = false; break; // Check remaining subSpans for final match. } else if (matchDoc != prevSpans.Doc) { inSameDoc = false; // The last subSpans is not advanced here. break; // Check remaining subSpans for last match in this document. } else { int ppStart = prevSpans.Start; int ppEnd = prevSpans.End; // Cannot avoid invoking .end() if (!DocSpansOrdered(ppStart, ppEnd, lastStart, lastEnd)) { break; // Check remaining subSpans. } // prevSpans still before (lastStart, lastEnd) else { prevStart = ppStart; prevEnd = ppEnd; if (collectPayloads && prevSpans.IsPayloadAvailable) { possiblePayload = new List <byte[]>(prevSpans.GetPayload()); // LUCENENET specific - using copy constructor instead of AddRange() } } } } if (collectPayloads && possiblePayload != null) { possibleMatchPayloads.UnionWith(possiblePayload); } if (Debugging.AssertsEnabled) { Debugging.Assert(prevStart <= matchStart); } if (matchStart > prevEnd) // Only non overlapping spans add to slop. { matchSlop += (matchStart - prevEnd); } /* Do not break on (matchSlop > allowedSlop) here to make sure * that subSpans[0] is advanced after the match, if any. */ matchStart = prevStart; lastStart = prevStart; lastEnd = prevEnd; } bool match = matchSlop <= allowedSlop; if (collectPayloads && match && possibleMatchPayloads.Count > 0) { matchPayload.AddRange(possibleMatchPayloads); } return(match); // ordered and allowed slop }
public override ICollection <byte[]> GetPayload() { return(new List <byte[]>(spans.GetPayload())); }