1 11 package org.eclipse.core.internal.indexing; 12 13 class SpaceMapPage extends ObjectStorePage { 14 private static int[] SpaceClassSize = {7616, 6906, 6196, 5486, 4776, 4066, 3356, 2646, 1936, 1226, 516, 258, 129, 64, 32, 0}; 15 16 19 public static int freeSpaceForClass(int spaceClass) { 20 return SpaceClassSize[spaceClass]; 21 } 22 23 26 public SpaceMapPage(int pageNumber, byte[] buffer, PageStore pageStore) { 27 super(pageNumber, buffer, pageStore); 28 } 29 30 33 public void toBuffer(byte[] buffer) { 34 int n = Math.min(buffer.length, pageBuffer.length()); 35 System.arraycopy(pageBuffer.getByteArray(), 0, buffer, 0, n); 36 } 37 38 44 56 public int getFreeSpace(int pageNumber) { 57 int slot = pageNumber - this.pageNumber; 58 if (slot < 1 || slot >= SIZE) 59 return 0; 60 int spaceClass = pageBuffer.getByte(slot); 61 int freeSpace = freeSpaceForClass(spaceClass); 62 return freeSpace; 63 } 64 65 68 public void setFreeSpace(int pageNumber, int freeSpace) { 69 int slot = pageNumber - this.pageNumber; 70 if (slot < 1 || slot >= SIZE) 71 return; 72 byte spaceClass = 0; 73 while (SpaceClassSize[spaceClass] > freeSpace) 74 spaceClass++; 75 pageBuffer.put(slot, spaceClass); 76 setChanged(); 77 notifyObservers(); 78 } 79 80 protected void materialize() { 81 } 82 } 83 | Popular Tags |