Project

General

Profile

« Previous | Next » 

Revision f079bf77

Added by Leszek Koltunski about 1 year ago

PruningTables now support numBits=20,24.
Progress with TablebasesPruning.

View differences:

src/main/java/org/distorted/objectlib/tablebases/PruningTable.java
13 13

  
14 14
class PruningTable
15 15
{
16
  private static final int HEADER_SIZE = 5;
16
  static final int[] SUPPORTED = {4,8,12,16,20,24};
17

  
18
  private static final int HEADER_SIZE = 6;
17 19
  private byte[] mData;
18 20
  private int mNumBits;
19 21
  private int mBucketBytes;
......
49 51
    mData[0] = (byte)mLevel;
50 52
    mData[1] = (byte)mBucketBytes;
51 53
    mData[2] = (byte)mNumBits;
52
    mData[3] = (byte)(mNumBuckets/256);
53
    mData[4] = (byte)(mNumBuckets%256);
54
    mData[3] = (byte)(mNumBuckets>>>16);
55
    mData[4] = (byte)(mNumBuckets>>> 8);
56
    mData[5] = (byte)(mNumBuckets&0xff);
54 57
    }
55 58

  
56 59
///////////////////////////////////////////////////////////////////////////////////////////////////
......
102 105
               break;
103 106
      case  8: ret = (mData[bytes]&0xff);
104 107
               break;
105
      case 12: ret = (bits%8)!=0 ? ((mData[bytes]&0xf)*256 + (mData[bytes+1]&0xff)) : ( (mData[bytes]&0xff)*16 + ((mData[bytes+1]>>>4)&0xf));
108
      case 12: ret = (bits%8)!=0 ? (((mData[bytes]&0xf)<<8) + (mData[bytes+1]&0xff)) : (((mData[bytes]&0xff)<<4) + ((mData[bytes+1]>>>4)&0xf));
109
               break;
110
      case 16: ret = ((mData[bytes]&0xff)<<8) + (mData[bytes+1]&0xff);
111
               break;
112
      case 20: if( (bits%8) !=0 ) ret = (((mData[bytes]&0x0f)<<16) + ((mData[bytes+1]&0xff)<<8) + ( mData[bytes+2]     &0xff));
113
               else               ret = (((mData[bytes]&0xff)<<12) + ((mData[bytes+1]&0xff)<<4) + ((mData[bytes+2]>>>4)&0x0f));
106 114
               break;
107
      case 16: ret = (mData[bytes]&0xff)*256 + (mData[bytes+1]&0xff);
115
      case 24: ret = ((mData[bytes]&0xff)<<16) + ((mData[bytes+1]&0xff)<<8) + (mData[bytes+2]&0xff);
108 116
               break;
109 117
      }
110 118

  
......
133 141
               else
134 142
                 {
135 143
                 mData[bytes]  = (byte)(value>>>4);
136
                 mData[bytes+1]= (byte)((byte)(value<<4) + (mData[bytes+1]&( 0xf)));
144
                 mData[bytes+1]= (byte)((byte)(value<<4) + (mData[bytes+1]&0xf));
137 145
                 }
138 146
               break;
139 147
      case 16: mData[bytes]   = (byte)(value>>>8);
140 148
               mData[bytes+1] = (byte)(value&(0xff));
149
               break;
150
      case 20: if( (bits%8) !=0 )
151
                 {
152
                 mData[bytes]  = (byte)((mData[bytes]&(~0xf)) + (value>>>16));
153
                 mData[bytes+1]= (byte)(value>>>8);
154
                 mData[bytes+2]= (byte)(value&(0xff));
155
                 }
156
               else
157
                 {
158
                 mData[bytes]  = (byte)(value>>>12);
159
                 mData[bytes+1]= (byte)(value>>>4);
160
                 mData[bytes+2]= (byte)((byte)(value<<4) + (mData[bytes+2]&0xf));
161
                 }
162
               break;
163
      case 24: mData[bytes]   = (byte)(value>>>16);
164
               mData[bytes+1] = (byte)(value>>>8);
165
               mData[bytes+2] = (byte)(value&(0xff));
166
               break;
141 167
      }
142 168
    }
143 169

  
......
240 266
///////////////////////////////////////////////////////////////////////////////////////////////////
241 267
// PUBLIC API
242 268
///////////////////////////////////////////////////////////////////////////////////////////////////
243
// only numBits = 4,8,12,16 actually supported
269
// only numBits = 4,8,12,16,20,24 actually supported
244 270

  
245 271
  PruningTable(Tablebase table, int level, int numBits)
246 272
    {
......
251 277

  
252 278
  PruningTable(Tablebase table, int level)
253 279
    {
254
    int[] supported = {4,8,12,16};
255 280
    int minimum = 0, chosen =  0;
256 281
    int size = retNumPositions(table,level);
257 282
    int tableSize = table.getSize();
258 283

  
259 284
    android.util.Log.e("D", "----- PRUNING TABLE LEVEL "+level+" ------");
260 285

  
261
    for(int i=0; i<supported.length; i++)
286
    for(int i=0; i<SUPPORTED.length; i++)
262 287
      {
263
      int approx = computeApproximateSize( tableSize, size, supported[i]);
288
      int approx = computeApproximateSize( tableSize, size, SUPPORTED[i]);
264 289

  
265 290
      if( i==0 || approx<minimum )
266 291
        {
......
268 293
        chosen  = i;
269 294
        }
270 295

  
271
      android.util.Log.e("D", "trying numBits: "+supported[i]+" approx size: "+approx);
296
      android.util.Log.e("D", "trying numBits: "+SUPPORTED[i]+" approx size: "+approx);
272 297
      }
273 298

  
274
    construct(table,level,supported[chosen]);
299
    construct(table,level,SUPPORTED[chosen]);
275 300
    }
276 301

  
277 302
///////////////////////////////////////////////////////////////////////////////////////////////////
......
283 308
    mLevel       = ((int)mData[0])&0xff;
284 309
    mBucketBytes = ((int)mData[1])&0xff;
285 310
    mNumBits     = ((int)mData[2])&0xff;
286
    mNumBuckets  =(((int)mData[3])&0xff)*256 + ((int)mData[4])&0xff;
311
    mNumBuckets  =((((int)mData[3])&0xff)<<16) + ((((int)mData[4])&0xff)<<8) + ((int)mData[5])&0xff;
287 312
    }
288 313

  
289 314
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff