Exemple #1
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;
     }
 }
Exemple #2
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);
 }
 private void  InitTermBuffer()
 {
     if (termBuffer == null)
     {
         termBuffer = new char[ArrayUtil.GetNextSize(MIN_BUFFER_SIZE)];
         termLength = 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);
                }
            }
        }
        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));
        }
Exemple #6
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)];
         }
     }
 }
 /// <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);
 }
Exemple #8
0
        /// <summary>
        /// Allocates a buffer char[] of at least newSize.
        /// </summary>
        /// <param name="newSize">minimum size of the buffer</param>
        /// <returns>newly created buffer with length >= newSize or null if the current termBuffer is big enough</returns>
        private char[] GrowTermBuffer(int newSize)
        {
            if (termBuffer != null)
            {
                if (termBuffer.Length >= newSize)
                {
                    // Already big enough
                    return(null);
                }
                else
                {
                    // Not big enough; create a new array with slight
                    // over-allocation
                    return(new char[ArrayUtil.GetNextSize(newSize)]);
                }
            }
            else
            {
                // determine the best size
                // The buffer is always at least MIN_BUFFER_SIZE
                if (newSize < MIN_BUFFER_SIZE)
                {
                    newSize = MIN_BUFFER_SIZE;
                }

                // If there is already a termText, then the size has to be at least that big
                if (termText != null)
                {
                    int ttLengh = termText.Length;
                    if (newSize < ttLengh)
                    {
                        newSize = ttLengh;
                    }
                }

                return(new char[newSize]);
            }
        }
 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]);
         }
     }
 }