14 |
14 |
class PruningTable
|
15 |
15 |
{
|
16 |
16 |
private static final int HEADER_SIZE = 5;
|
17 |
|
private final byte[] mData;
|
18 |
|
private final int mNumBits;
|
19 |
|
private final int mBucketBytes;
|
20 |
|
private final int mNumBuckets;
|
21 |
|
private final int mLevel;
|
|
17 |
private byte[] mData;
|
|
18 |
private int mNumBits;
|
|
19 |
private int mBucketBytes;
|
|
20 |
private int mNumBuckets;
|
|
21 |
private int mLevel;
|
22 |
22 |
|
23 |
23 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24 |
24 |
|
... | ... | |
173 |
173 |
}
|
174 |
174 |
|
175 |
175 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176 |
|
// PUBLIC API
|
|
176 |
|
|
177 |
private int computeApproximateSize(int tableSize, int numBits)
|
|
178 |
{
|
|
179 |
int entrySize = (1<<numBits);
|
|
180 |
int numBuckets = (tableSize+entrySize-1)/entrySize;
|
|
181 |
int overhang = (numBits==4 || numBits==12) ? numBuckets/4 : 0;
|
|
182 |
int totalBytesForTable = (tableSize*numBits)/8 + overhang;
|
|
183 |
int bucketBytes = numBytesForIndices(totalBytesForTable);
|
|
184 |
int totalBytesForBuckets = numBuckets*bucketBytes;
|
|
185 |
|
|
186 |
return HEADER_SIZE + totalBytesForBuckets + totalBytesForTable;
|
|
187 |
}
|
|
188 |
|
177 |
189 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178 |
|
// only numBits = 4,8,12,16 actually supported
|
179 |
190 |
|
180 |
|
PruningTable(Tablebase table, int level, int numBits)
|
|
191 |
private void construct(Tablebase table, int level, int numBits)
|
181 |
192 |
{
|
182 |
193 |
mNumBits = numBits;
|
183 |
194 |
mLevel = level;
|
... | ... | |
207 |
218 |
int totalSize = HEADER_SIZE + totalBytesForBuckets + totalBytesForTable;
|
208 |
219 |
mData = new byte[totalSize];
|
209 |
220 |
|
|
221 |
android.util.Log.e("D", "Constructing a pruningTable, numBits="+numBits+" size "+totalSize);
|
|
222 |
|
210 |
223 |
writeHeader();
|
211 |
224 |
writeBucketPointers(bucket);
|
212 |
225 |
writeBuckets(table);
|
213 |
226 |
}
|
214 |
227 |
|
|
228 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
229 |
// PUBLIC API
|
|
230 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
231 |
// only numBits = 4,8,12,16 actually supported
|
|
232 |
|
|
233 |
PruningTable(Tablebase table, int level, int numBits)
|
|
234 |
{
|
|
235 |
construct(table,level,numBits);
|
|
236 |
}
|
|
237 |
|
|
238 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
239 |
|
|
240 |
PruningTable(Tablebase table, int level)
|
|
241 |
{
|
|
242 |
int size = table.getSize();
|
|
243 |
int[] supported = {4,8,12,16};
|
|
244 |
int minimum = 0;
|
|
245 |
int chosen = 0;
|
|
246 |
|
|
247 |
for(int i=0; i<supported.length; i++)
|
|
248 |
{
|
|
249 |
int approx = computeApproximateSize(size, supported[i]);
|
|
250 |
|
|
251 |
if( i==0 || approx<minimum )
|
|
252 |
{
|
|
253 |
minimum = approx;
|
|
254 |
chosen = i;
|
|
255 |
}
|
|
256 |
|
|
257 |
android.util.Log.e("D", "trying numBits: "+supported[i]+" approx size: "+approx);
|
|
258 |
}
|
|
259 |
|
|
260 |
construct(table,level,supported[chosen]);
|
|
261 |
}
|
|
262 |
|
215 |
263 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
216 |
264 |
|
217 |
265 |
PruningTable(byte[] data)
|
progress with PruningTable.