lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: ByteBlockPool class.
Date Mon, 03 Aug 2015 16:24:39 GMT
On Mon, Aug 3, 2015 at 11:35 AM, elbek kamoliddinov <elbek.dev@gmail.com> wrote:
> Hi Lucene hackers.
> I was looking into lucene internals and came across ByteBlockPool class. In
> that class I see following static final array:
>  public final static int[] LEVEL_SIZE_ARRAY = {5, 14, 20, 30, 40, 40, 80,
> 80, 120, 200};
>
> why and how these numbers are selected?

I did that, long ago, but I don't remember why I picked those specific
numbers :)  Maybe I copied/was inspired by how Python grows its list
object?

We also do something similar in ArrayUtil.grow.

> In addition In the #allocSlice() method I see the following snippet:
>
> final int level = slice[upto] & 15;
> final int newLevel = NEXT_LEVEL_ARRAY[level];
> final int newSize = LEVEL_SIZE_ARRAY[newLevel];
>
> but NEXT_LEVEL_ARRAY size is upto 10. How can we guarantee that level
> variable value (slice[upto] & 15) will not exceed the array size and won't
> throw array out of index exception? Value of this (slice[upto] & 15) can go
> upto 15.

Look at NEXT_LEVEL_ARRAY: its biggest value is 9.  So once a slice
hits size 200, we just keep allocating 200 byte chunks forever after
that if that term keeps seeing new postings...

Mike McCandless

http://blog.mikemccandless.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message