Exemple #1
0
 internal virtual void AddPosition(int position, int startOffset, int length, int payloadLength)
 {
     if (hasPositions)
     {
         if (posStart + totalPositions == outerInstance.positionsBuf.Length)
         {
             outerInstance.positionsBuf = ArrayUtil.Grow(outerInstance.positionsBuf);
         }
         outerInstance.positionsBuf[posStart + totalPositions] = position;
     }
     if (hasOffsets)
     {
         if (offStart + totalPositions == outerInstance.startOffsetsBuf.Length)
         {
             int newLength = ArrayUtil.Oversize(offStart + totalPositions, 4);
             outerInstance.startOffsetsBuf = Arrays.CopyOf(outerInstance.startOffsetsBuf, newLength);
             outerInstance.lengthsBuf      = Arrays.CopyOf(outerInstance.lengthsBuf, newLength);
         }
         outerInstance.startOffsetsBuf[offStart + totalPositions] = startOffset;
         outerInstance.lengthsBuf[offStart + totalPositions]      = length;
     }
     if (hasPayloads)
     {
         if (payStart + totalPositions == outerInstance.payloadLengthsBuf.Length)
         {
             outerInstance.payloadLengthsBuf = ArrayUtil.Grow(outerInstance.payloadLengthsBuf);
         }
         outerInstance.payloadLengthsBuf[payStart + totalPositions] = payloadLength;
     }
     ++totalPositions;
 }
Exemple #2
0
        public override void AddProx(int numProx, DataInput positions, DataInput offsets)
        {
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert((curField.hasPositions) == (positions != null));
                Debugging.Assert((curField.hasOffsets) == (offsets != null));
            }

            if (curField.hasPositions)
            {
                int posStart = curField.posStart + curField.totalPositions;
                if (posStart + numProx > positionsBuf.Length)
                {
                    positionsBuf = ArrayUtil.Grow(positionsBuf, posStart + numProx);
                }
                int position = 0;
                if (curField.hasPayloads)
                {
                    int payStart = curField.payStart + curField.totalPositions;
                    if (payStart + numProx > payloadLengthsBuf.Length)
                    {
                        payloadLengthsBuf = ArrayUtil.Grow(payloadLengthsBuf, payStart + numProx);
                    }
                    for (int i = 0; i < numProx; ++i)
                    {
                        int code = positions.ReadVInt32();
                        if ((code & 1) != 0)
                        {
                            // this position has a payload
                            int payloadLength = positions.ReadVInt32();
                            payloadLengthsBuf[payStart + i] = payloadLength;
                            payloadBytes.CopyBytes(positions, payloadLength);
                        }
                        else
                        {
                            payloadLengthsBuf[payStart + i] = 0;
                        }
                        position += code.TripleShift(1);
                        positionsBuf[posStart + i] = position;
                    }
                }
                else
                {
                    for (int i = 0; i < numProx; ++i)
                    {
                        position += positions.ReadVInt32().TripleShift(1);
                        positionsBuf[posStart + i] = position;
                    }
                }
            }

            if (curField.hasOffsets)
            {
                int offStart = curField.offStart + curField.totalPositions;
                if (offStart + numProx > startOffsetsBuf.Length)
                {
                    int newLength = ArrayUtil.Oversize(offStart + numProx, 4);
                    startOffsetsBuf = Arrays.CopyOf(startOffsetsBuf, newLength);
                    lengthsBuf      = Arrays.CopyOf(lengthsBuf, newLength);
                }
                int lastOffset = 0, startOffset, endOffset;
                for (int i = 0; i < numProx; ++i)
                {
                    startOffset = lastOffset + offsets.ReadVInt32();
                    endOffset   = startOffset + offsets.ReadVInt32();
                    lastOffset  = endOffset;
                    startOffsetsBuf[offStart + i] = startOffset;
                    lengthsBuf[offStart + i]      = endOffset - startOffset;
                }
            }

            curField.totalPositions += numProx;
        }