Exemplo n.º 1
0
 // TODO: Remove warning after API has been finalized
 public override System.Collections.Generic.ICollection <byte[]> GetPayload()
 {
     System.Collections.Generic.ICollection <byte[]> result = null;
     if (spans.IsPayloadAvailable())
     {
         result = spans.GetPayload();
     }
     return(result);                //TODO: any way to avoid the new construction?
 }
Exemplo n.º 2
0
 // TODO: Remove warning after API has been finalizedb
 public override System.Collections.Generic.ICollection <byte[]> GetPayload()
 {
     System.Collections.Generic.ICollection <byte[]> result = null;
     if (includeSpans.IsPayloadAvailable())
     {
         result = includeSpans.GetPayload();
     }
     return(result);
 }
Exemplo n.º 3
0
            // TODO: Remove warning after API has been finalized
            public override System.Collections.Generic.ICollection <byte[]> GetPayload()
            {
                System.Collections.Generic.ICollection <byte[]> result = null;
                Spans theTop = Top();

                if (theTop != null && theTop.IsPayloadAvailable())
                {
                    result = theTop.GetPayload();
                }
                return(result);
            }
Exemplo n.º 4
0
        /// <summary>The 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 subSpans except the last one in reverse order.
        /// </summary>
        private bool ShrinkToAfterShortestMatch()
        {
            matchStart = subSpans[subSpans.Length - 1].Start();
            matchEnd   = subSpans[subSpans.Length - 1].End();
            System.Collections.Generic.Dictionary <byte[], byte[]> possibleMatchPayloads = new System.Collections.Generic.Dictionary <byte[], byte[]>();
            if (subSpans[subSpans.Length - 1].IsPayloadAvailable())
            {
                System.Collections.Generic.ICollection <byte[]> payload = subSpans[subSpans.Length - 1].GetPayload();
                foreach (byte[] pl in payload)
                {
                    if (!possibleMatchPayloads.ContainsKey(pl))
                    {
                        possibleMatchPayloads.Add(pl, pl);
                    }
                }
            }

            System.Collections.Generic.List <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())
                {
                    System.Collections.Generic.ICollection <byte[]> payload = prevSpans.GetPayload();
                    possiblePayload = new System.Collections.Generic.List <byte[]>(payload.Count);
                    possiblePayload.AddRange(payload);
                }

                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.
                        }
                        else
                        {
                            // prevSpans still before (lastStart, lastEnd)
                            prevStart = ppStart;
                            prevEnd   = ppEnd;
                            if (collectPayloads && prevSpans.IsPayloadAvailable())
                            {
                                System.Collections.Generic.ICollection <byte[]> payload = prevSpans.GetPayload();
                                possiblePayload = new System.Collections.Generic.List <byte[]>(payload.Count);
                                possiblePayload.AddRange(payload);
                            }
                        }
                    }
                }

                if (collectPayloads && possiblePayload != null)
                {
                    foreach (byte[] pl in possiblePayload)
                    {
                        if (!possibleMatchPayloads.ContainsKey(pl))
                        {
                            possibleMatchPayloads.Add(pl, pl);
                        }
                    }
                }

                System.Diagnostics.Debug.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.Keys);
            }

            return(match);            // ordered and allowed slop
        }
Exemplo n.º 5
0
 // TODO: Remove warning after API has been finalized
 public override System.Collections.Generic.ICollection <byte[]> GetPayload()
 {
     return(spans.GetPayload());
 }