Exemplo n.º 1
0
 public void  Reset()
 {
     // Shrink back if we are overallocated now:
     docIDs = ArrayUtil.Shrink(docIDs, upto);
     norms  = ArrayUtil.Shrink(norms, upto);
     upto   = 0;
 }
Exemplo n.º 2
0
 // TODO: once we remove the deprecated termText() method
 // and switch entirely to char[] termBuffer we don't need
 // to use this method anymore, only for late init of the buffer
 private void  InitTermBuffer()
 {
     if (termBuffer == null)
     {
         if (termText == null)
         {
             termBuffer = new char[ArrayUtil.GetNextSize(MIN_BUFFER_SIZE)];
             termLength = 0;
         }
         else
         {
             int length = termText.Length;
             if (length < MIN_BUFFER_SIZE)
             {
                 length = MIN_BUFFER_SIZE;
             }
             termBuffer = new char[ArrayUtil.GetNextSize(length)];
             termLength = termText.Length;
             SupportClass.TextSupport.GetCharsFromString(termText, 0, termText.Length, termBuffer, 0);
             termText = null;
         }
     }
     else
     {
         termText = null;
     }
 }
Exemplo n.º 3
0
 /// <summary>Grows the termBuffer to at least size newSize, preserving the
 /// existing content. Note: If the next operation is to change
 /// the contents of the term buffer use
 /// {@link #SetTermBuffer(char[], int, int)},
 /// {@link #SetTermBuffer(String)}, or
 /// {@link #SetTermBuffer(String, int, int)}
 /// to optimally combine the resize with the setting of the termBuffer.
 /// </summary>
 /// <param name="newSize">minimum size of the new termBuffer
 /// </param>
 /// <returns> newly created termBuffer with length >= newSize
 /// </returns>
 public virtual char[] ResizeTermBuffer(int newSize)
 {
     if (termBuffer == null)
     {
         // The buffer is always at least MIN_BUFFER_SIZE
         newSize = newSize < MIN_BUFFER_SIZE?MIN_BUFFER_SIZE:newSize;
         //Preserve termText
         if (termText != null)
         {
             int ttLen = termText.Length;
             newSize    = newSize < ttLen?ttLen:newSize;
             termBuffer = new char[ArrayUtil.GetNextSize(newSize)];
             SupportClass.TextSupport.GetCharsFromString(termText, 0, termText.Length, termBuffer, 0);
             termText = null;
         }
         else
         {
             // no term Text, the first allocation
             termBuffer = new char[ArrayUtil.GetNextSize(newSize)];
         }
     }
     else
     {
         if (termBuffer.Length < newSize)
         {
             // Not big enough; create a new array with slight
             // over allocation and preserve content
             char[] newCharBuffer = new char[ArrayUtil.GetNextSize(newSize)];
             Array.Copy(termBuffer, 0, newCharBuffer, 0, termBuffer.Length);
             termBuffer = newCharBuffer;
         }
     }
     return(termBuffer);
 }
Exemplo n.º 4
0
        public override int GetHashCode()
        {
            InitTermBuffer();
            int code = termLength;

            code = code * 31 + ArrayUtil.HashCode(termBuffer, 0, termLength);
            return(code);
        }
Exemplo n.º 5
0
 private void  InitTermBuffer()
 {
     if (termBuffer == null)
     {
         termBuffer = new char[ArrayUtil.GetNextSize(MIN_BUFFER_SIZE)];
         termLength = 0;
     }
 }
Exemplo n.º 6
0
        public void  GetPostings(RawPostingList[] postings)
        {
            lock (this)
            {
                System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint("TermsHash.getPostings start"));

                System.Diagnostics.Debug.Assert(postingsFreeCount <= postingsFreeList.Length);
                System.Diagnostics.Debug.Assert(postingsFreeCount <= postingsAllocCount, "postingsFreeCount=" + postingsFreeCount + " postingsAllocCount=" + postingsAllocCount);

                int numToCopy;
                if (postingsFreeCount < postings.Length)
                {
                    numToCopy = postingsFreeCount;
                }
                else
                {
                    numToCopy = postings.Length;
                }
                int start = postingsFreeCount - numToCopy;
                System.Diagnostics.Debug.Assert(start >= 0);
                System.Diagnostics.Debug.Assert(start + numToCopy <= postingsFreeList.Length);
                System.Diagnostics.Debug.Assert(numToCopy <= postings.Length);
                Array.Copy(postingsFreeList, start, postings, 0, numToCopy);

                // Directly allocate the remainder if any
                if (numToCopy != postings.Length)
                {
                    int extra = postings.Length - numToCopy;
                    int newPostingsAllocCount = postingsAllocCount + extra;

                    consumer.CreatePostings(postings, numToCopy, extra);
                    System.Diagnostics.Debug.Assert(docWriter.writer.TestPoint("TermsHash.getPostings after create"));
                    postingsAllocCount += extra;

                    if (trackAllocations)
                    {
                        docWriter.BytesAllocated(extra * bytesPerPosting);
                    }

                    if (newPostingsAllocCount > postingsFreeList.Length)
                    {
                        // Pre-allocate the postingsFreeList so it's large
                        // enough to hold all postings we've given out
                        postingsFreeList = new RawPostingList[ArrayUtil.GetNextSize(newPostingsAllocCount)];
                    }
                }

                postingsFreeCount -= numToCopy;

                if (trackAllocations)
                {
                    docWriter.BytesUsed(postings.Length * bytesPerPosting);
                }
            }
        }
Exemplo n.º 7
0
 internal void  AddField(int fieldNumber)
 {
     if (numVectorFields == fieldNumbers.Length)
     {
         fieldNumbers  = ArrayUtil.Grow(fieldNumbers);
         fieldPointers = ArrayUtil.Grow(fieldPointers);
     }
     fieldNumbers[numVectorFields]  = fieldNumber;
     fieldPointers[numVectorFields] = perDocTvf.GetFilePointer();
     numVectorFields++;
 }
Exemplo n.º 8
0
        public override int GetHashCode()
        {
            InitTermBuffer();
            int code = termLength;

            code = code * 31 + startOffset;
            code = code * 31 + endOffset;
            code = code * 31 + flags;
            code = code * 31 + positionIncrement;
            code = code * 31 + type.GetHashCode();
            code = (payload == null?code:code * 31 + payload.GetHashCode());
            code = code * 31 + ArrayUtil.HashCode(termBuffer, 0, termLength);
            return(code);
        }
Exemplo n.º 9
0
        internal virtual FormatPostingsDocsConsumer AddTerm(System.String text)
        {
            int len = text.Length;

            if (termBuffer == null || termBuffer.Length < 1 + len)
            {
                termBuffer = new char[ArrayUtil.GetNextSize(1 + len)];
            }
            for (int i = 0; i < len; i++)
            {
                termBuffer[i] = (char)text[i];
            }
            termBuffer[len] = (char)(0xffff);
            return(AddTerm(termBuffer, 0));
        }
Exemplo n.º 10
0
 /// <summary>Allocates a buffer char[] of at least newSize, without preserving the existing content.
 /// its always used in places that set the content
 /// </summary>
 /// <param name="newSize">minimum size of the buffer
 /// </param>
 private void  GrowTermBuffer(int newSize)
 {
     if (termBuffer == null)
     {
         // The buffer is always at least MIN_BUFFER_SIZE
         termBuffer = new char[ArrayUtil.GetNextSize(newSize < MIN_BUFFER_SIZE?MIN_BUFFER_SIZE:newSize)];
     }
     else
     {
         if (termBuffer.Length < newSize)
         {
             // Not big enough; create a new array with slight
             // over allocation:
             termBuffer = new char[ArrayUtil.GetNextSize(newSize)];
         }
     }
 }
Exemplo n.º 11
0
 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++;
     }
 }
Exemplo n.º 12
0
 /// <summary>Grows the termBuffer to at least size newSize, preserving the
 /// existing content. Note: If the next operation is to change
 /// the contents of the term buffer use
 /// {@link #SetTermBuffer(char[], int, int)},
 /// {@link #SetTermBuffer(String)}, or
 /// {@link #SetTermBuffer(String, int, int)}
 /// to optimally combine the resize with the setting of the termBuffer.
 /// </summary>
 /// <param name="newSize">minimum size of the new termBuffer
 /// </param>
 /// <returns> newly created termBuffer with length >= newSize
 /// </returns>
 public virtual char[] ResizeTermBuffer(int newSize)
 {
     if (termBuffer == null)
     {
         // The buffer is always at least MIN_BUFFER_SIZE
         termBuffer = new char[ArrayUtil.GetNextSize(newSize < MIN_BUFFER_SIZE?MIN_BUFFER_SIZE:newSize)];
     }
     else
     {
         if (termBuffer.Length < newSize)
         {
             // Not big enough; create a new array with slight
             // over allocation and preserve content
             char[] newCharBuffer = new char[ArrayUtil.GetNextSize(newSize)];
             Array.Copy(termBuffer, 0, newCharBuffer, 0, termBuffer.Length);
             termBuffer = newCharBuffer;
         }
     }
     return(termBuffer);
 }
Exemplo n.º 13
0
 internal PerDoc GetPerDoc()
 {
     lock (this)
     {
         if (freeCount == 0)
         {
             allocCount++;
             if (allocCount > docFreeList.Length)
             {
                 // Grow our free list up front to make sure we have
                 // enough space to recycle all outstanding PerDoc
                 // instances
                 System.Diagnostics.Debug.Assert(allocCount == 1 + docFreeList.Length);
                 docFreeList = new PerDoc[ArrayUtil.GetNextSize(allocCount)];
             }
             return(new PerDoc(this));
         }
         else
         {
             return(docFreeList[--freeCount]);
         }
     }
 }
Exemplo n.º 14
0
 public override int GetHashCode()
 {
     return(ArrayUtil.HashCode(data, offset, offset + length));
 }