github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/util/pool.go (about) 1 package util 2 3 // util/ByteBlockPool.java 4 5 /* 6 Class that Posting and PostingVector use to write byte streams into 7 shared fixed-size []byte arrays. The idea is to allocate slices of 8 increasing lengths. For example, the first slice is 5 bytes, the next 9 slice is 14, etc. We start by writing our bytes into the first 5 10 bytes. When we hit the end of the slice, we allocate the next slice 11 and then write the address of the new slice into the last 4 bytes of 12 the previous slice (the "forwarding address"). 13 14 Each slice is filled with 0's initially, and we mark the end with a 15 non-zero byte. This way the methods that are writing into the slice 16 don't need to record its length and instead allocate a new slice once 17 they hit a non-zero byte. 18 */ 19 20 const ( 21 BYTE_BLOCK_SHIFT = 15 22 BYTE_BLOCK_SIZE = 1 << BYTE_BLOCK_SHIFT 23 BYTE_BLOCK_MASK = BYTE_BLOCK_SIZE - 1 24 )