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
        private void  CheckReadBytes(IndexInput input, int size, int pos)
        {
            // Just to see that "offset" is treated properly in readBytes(), we
            // add an arbitrary offset at the beginning of the array
            int offset = size % 10;             // arbitrary

            buffer = ArrayUtil.Grow(buffer, offset + size);
            Assert.AreEqual(pos, input.GetFilePointer());
            long left = TEST_FILE_LENGTH - input.GetFilePointer();

            if (left <= 0)
            {
                return;
            }
            else if (left < size)
            {
                size = (int)left;
            }
            input.ReadBytes(buffer, offset, size);
            Assert.AreEqual(pos + size, input.GetFilePointer());
            for (int i = 0; i < size; i++)
            {
                Assert.AreEqual(Byten(pos + i), buffer[offset + i], "pos=" + i + " filepos=" + (pos + i));
            }
        }
Exemple #3
0
 internal void  AddField(int fieldNumber)
 {
     if (numVectorFields == fieldNumbers.Length)
     {
         fieldNumbers  = ArrayUtil.Grow(fieldNumbers);
         fieldPointers = ArrayUtil.Grow(fieldPointers);
     }
     fieldNumbers[numVectorFields]  = fieldNumber;
     fieldPointers[numVectorFields] = perDocTvf.FilePointer;
     numVectorFields++;
 }
Exemple #4
0
 internal void addField(int fieldNumber)
 {
     if (numVectorFields == fieldNumbers.Length)
     {
         fieldNumbers  = ArrayUtil.Grow(fieldNumbers);
         fieldPointers = ArrayUtil.Grow(fieldPointers);
     }
     fieldNumbers[numVectorFields]  = fieldNumber;
     fieldPointers[numVectorFields] = tvf.GetFilePointer();
     numVectorFields++;
 }
 internal override void  Finish()
 {
     System.Diagnostics.Debug.Assert(docIDs.Length == norms.Length);
     if (fieldInfo.isIndexed && !fieldInfo.omitNorms)
     {
         if (docIDs.Length <= upto)
         {
             System.Diagnostics.Debug.Assert(docIDs.Length == upto);
             docIDs = ArrayUtil.Grow(docIDs, 1 + upto);
             norms  = ArrayUtil.Grow(norms, 1 + upto);
         }
         float norm = docState.similarity.ComputeNorm(fieldInfo.name, fieldState);
         norms[upto]  = Similarity.EncodeNorm(norm);
         docIDs[upto] = docState.docID;
         upto++;
     }
 }
Exemple #6
0
        /// <summary>
        /// Subclass &amp; override if you change the encoding.
        /// </summary>
        protected virtual void Decode(BytesRef buf, Int32sRef ordinals)
        {
            // grow the buffer up front, even if by a large number of values (buf.length)
            // that saves the need to check inside the loop for every decoded value if
            // the buffer needs to grow.
            if (ordinals.Int32s.Length < buf.Length)
            {
                ordinals.Int32s = ArrayUtil.Grow(ordinals.Int32s, buf.Length);
            }

            ordinals.Offset = 0;
            ordinals.Length = 0;

            // it is better if the decoding is inlined like so, and not e.g.
            // in a utility method
            int upto   = buf.Offset + buf.Length;
            int value  = 0;
            int offset = buf.Offset;
            int prev   = 0;

            while (offset < upto)
            {
                byte b = buf.Bytes[offset++];
                if ((sbyte)b >= 0)
                {
                    ordinals.Int32s[ordinals.Length] = ((value << 7) | b) + prev;
                    value = 0;
                    prev  = ordinals.Int32s[ordinals.Length];
                    ordinals.Length++;
                }
                else
                {
                    value = (value << 7) | (b & 0x7F);
                }
            }
        }
        public override void AddProx(int numProx, DataInput positions, DataInput offsets)
        {
            Debug.Assert((curField.hasPositions) == (positions != null));
            Debug.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 += (int)((uint)code >> 1);
                        positionsBuf[posStart + i] = position;
                    }
                }
                else
                {
                    for (int i = 0; i < numProx; ++i)
                    {
                        position += ((int)((uint)positions.ReadVInt32() >> 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;
        }