36 using System.Collections.Generic;
37 using Lucene.Net.Support;
39 namespace Lucene.Net.Index
44 private void InitBlock()
51 public abstract void RecycleByteBlocks(byte[][] blocks,
int start,
int end);
52 public abstract void RecycleByteBlocks(IList<byte[]> blocks);
53 public abstract byte[] GetByteBlock(
bool trackAllocations);
56 public byte[][] buffers =
new byte[10][];
58 internal int bufferUpto = - 1;
64 private readonly
bool trackAllocations;
70 this.allocator = allocator;
71 this.trackAllocations = trackAllocations;
76 if (bufferUpto != - 1)
80 for (
int i = 0; i < bufferUpto; i++)
82 System.Array.Clear(buffers[i], 0, buffers[i].Length);
85 System.Array.Clear(buffers[bufferUpto], 0, byteUpto);
99 public void NextBuffer()
101 if (1 + bufferUpto == buffers.Length)
103 var newBuffers =
new byte[(int) (buffers.Length * 1.5)][];
104 Array.Copy(buffers, 0, newBuffers, 0, buffers.Length);
105 buffers = newBuffers;
107 buffer = buffers[1 + bufferUpto] = allocator.GetByteBlock(trackAllocations);
114 public int NewSlice(
int size)
120 buffer[byteUpto - 1] = 16;
129 internal static readonly
int[] nextLevelArray =
new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 9};
130 internal static readonly
int[] levelSizeArray =
new int[]{5, 14, 20, 30, 40, 40, 80, 80, 120, 200};
131 internal static readonly
int FIRST_LEVEL_SIZE = levelSizeArray[0];
132 public readonly
static int FIRST_LEVEL_SIZE_For_NUnit_Test = levelSizeArray[0];
134 public int AllocSlice(byte[] slice,
int upto)
137 int level = slice[upto] & 15;
138 int newLevel = nextLevelArray[level];
139 int newSize = levelSizeArray[newLevel];
145 int newUpto = byteUpto;
146 int offset = newUpto + byteOffset;
151 buffer[newUpto] = slice[upto - 3];
152 buffer[newUpto + 1] = slice[upto - 2];
153 buffer[newUpto + 2] = slice[upto - 1];
159 slice[upto] = (byte) offset;
162 buffer[byteUpto - 1] = (byte) (16 | newLevel);
167 public static int FIRST_LEVEL_SIZE_ForNUnit
169 get {
return FIRST_LEVEL_SIZE; }