public int getRecordLength() { return recordFactory.recordLength() ; }
public RecordBuffer(ByteBuffer bb, RecordFactory recFactory, int num) { super(bb, recFactory.recordLength(), num) ; this.factory = recFactory ; }
public int getKeyLength() { return keyFactory.recordLength() ; }
public RecordBuffer(RecordFactory recFactory, int maxRec) { this(ByteBuffer.allocate(recFactory.recordLength() * maxRec), recFactory, 0) ; }
public static int calcRecordSize(RecordFactory factory, int blkSize, int headerOffset) { // Length = X*recordLength + HEADER int x = blkSize - totalOffset(headerOffset) ; return x / factory.recordLength() ; }
/** * Return the best fit for the blocksize and the record length. Knows about * block header space. */ public static int calcOrder(int blockSize, RecordFactory factory) { return calcOrder(blockSize, factory.recordLength()) ; }
public static int calcBlockSize(RecordFactory factory, int maxRec, int headerOffset) { return totalOffset(headerOffset) + factory.recordLength() * maxRec ; }
public static Record intToRecord(int v, RecordFactory factory) { byte[] vb = Bytes.packInt(v) ; int recLen = factory.recordLength() ; byte[] bb = new byte[recLen] ; int x = 0 ; // Start point in bb. if ( recLen > 4 ) x = recLen-4 ; int len = Math.min(4, recLen) ; int z = 4-len ; // Start point in vb // Furthest right bytes. for ( int i = len-1 ; i >= 0 ; i-- ) bb[x+i] = vb[z+i] ; return factory.create(bb) ; }
public static RangeIndex makeBPlusTree(ComponentId cid, FileSet fs, int blkSize, int readCacheSize, int writeCacheSize, int dftKeyLength, int dftValueLength) { RecordFactory recordFactory = makeRecordFactory(dftKeyLength, dftValueLength) ; int order = BPlusTreeParams.calcOrder(blkSize, recordFactory.recordLength()) ; RangeIndex rIndex = createBPTree(cid, fs, order, blkSize, readCacheSize, writeCacheSize, recordFactory) ; return rIndex ; }
/** return the size of a block */ public static int calcBlockSize(int bpTreeOrder, RecordFactory factory) { BPlusTreeParams p = new BPlusTreeParams(bpTreeOrder, factory) ; int x = p.getMaxRec() * factory.recordLength() + p.getMaxPtr() * SizeOfPointer ; x += BlockHeaderSize ; return x ; }
/** Knowing all the parameters, create a B+Tree */ public static BPlusTree createBPTree(ComponentId cid, FileSet fileset, int order, int blockSize, int readCacheSize, int writeCacheSize, RecordFactory factory) { // ---- Checking if (blockSize < 0 && order < 0) throw new IllegalArgumentException("Neither blocksize nor order specified") ; if (blockSize >= 0 && order < 0) order = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ; if (blockSize >= 0 && order >= 0) { int order2 = BPlusTreeParams.calcOrder(blockSize, factory.recordLength()) ; if (order != order2) throw new IllegalArgumentException("Wrong order (" + order + "), calculated = " + order2) ; } // Iffy - does not allow for slop. if (blockSize < 0 && order >= 0) { // Only in-memory. blockSize = BPlusTreeParams.calcBlockSize(order, factory) ; } BPlusTreeParams params = new BPlusTreeParams(order, factory) ; BufferChannel bptState = FileFactory.createBufferChannel(fileset, Names.extBptState) ; BlockMgr blkMgrNodes = BlockMgrFactory.create(fileset, Names.extBptTree, blockSize, readCacheSize, writeCacheSize) ; BlockMgr blkMgrRecords = BlockMgrFactory.create(fileset, Names.extBptRecords, blockSize, readCacheSize, writeCacheSize) ; return BPlusTreeFactory.create(cid, params, bptState, blkMgrNodes, blkMgrRecords) ; }