iverase commented on code in PR #12625: URL: https://github.com/apache/lucene/pull/12625#discussion_r1358473230
########## lucene/core/src/java/org/apache/lucene/index/TermsHashPerField.java: ########## @@ -255,6 +255,81 @@ final void writeBytes(int stream, byte[] b, int offset, int len) { } } + // Size of each slice. These arrays should be at most 16 + // elements (index is encoded with 4 bits). First array + // is just a compact way to encode X+1 with a max. Second + // array is the length of each slice, ie first slice is 5 + // bytes, next slice is 14 bytes, etc. + + /** + * An array holding the offset into the {@link #LEVEL_SIZE_ARRAY} to quickly navigate to the next + * slice level. + */ + static final int[] NEXT_LEVEL_ARRAY = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9}; + + /** An array holding the level sizes for byte slices. */ + static final int[] LEVEL_SIZE_ARRAY = {5, 14, 20, 30, 40, 40, 80, 80, 120, 200}; + + /** The first level size for new slices */ + static final int FIRST_LEVEL_SIZE = LEVEL_SIZE_ARRAY[0]; + + /** + * Allocates a new slice with the given size. As each slice is filled with 0's initially, we mark + * the end with a non-zero byte. This way we don't need to record its length and instead allocate + * new slice once they hit a non-zero byte. + */ + // pkg private for access by tests + static int newSlice(ByteBlockPool bytePool, final int size, final int level) { + assert LEVEL_SIZE_ARRAY[level] == size; Review Comment: I think it is just a micro optimization to avoid looking twice into the array. This is a copy paste of the original code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org