@Override public boolean equals(Object other) { if ( this == other ) return true ; if ( ! ( other instanceof Record ) ) return false ; Record r = (Record)other ; return compareByKeyValue(this, r) == 0 ; }
public static Iterator<Record> create(BPTreeNode node, Record minRec, Record maxRec) { if ( minRec != null && maxRec != null && Record.keyGE(minRec, maxRec) ) return Iter.nullIter(); return new BPTreeRangeIterator(node, minRec, maxRec) ; }
@Override public boolean delete(Record record) { ByteArray x = index.remove(wrap(record.getKey())) ; if ( x == null ) return false ; return true ; }
BPT.error("Node: %d: Can't get high record from %d", id, n.getId()) ; if ( keySubTree.getKey() == null ) BPT.error("Node: %d: Can't get high record is missing it's key from %d", id, n.getId()) ; BPT.error("Node: %d: record is null", id) ; if ( keyHere.getKey() == null ) BPT.error("Node: %d: Record key is null", id) ; if ( keyGT(keySubTree, keyHere) ) BPT.error("Node: %d: Child key %s is greater than this key %s", id, keySubTree, keyHere) ; if ( keyNE(keyHere, keyMax) ) BPT.error("Node: %d: Key %s is not the max [%s] of the sub-tree idx=%d", id, keyHere, keyMax, i) ; if ( min != null && keyGT(min, keyMin) ) BPT.error("Node: %d: Minimun for this node should be %s but it's %s", id, min, keyMin) ; if ( max != null && keyLT(max, keyMax) ) BPT.error("Node: %d: Maximum for this node should be %s but it's %s", id, max, keyMax) ; if ( min != null && keyGT(min, keyHere) ) BPT.error("Node: %d: Key too small: %s - min should be %s", id, keyHere, min) ; if ( max != null && keyLT(max, keyHere) ) BPT.error("Node: %d: Key too large: %s - max should be %s", id, keyHere, max) ;
/** * Split: place old high half in 'other'. Return the new (upper) * BPTreeRecords(BPTreePage). * Split is the high end of the low page. */ @Override public BPTreePage split() { BPTreeRecords other = insertNewPage() ; int splitIdx = rBuff.size() / 2 - 1 ; Record r = rBuff.get(splitIdx) ; // Only need key for checking later. int moveLen = rBuff.size() - (splitIdx + 1) ; // Number to move. // Copy high end to new. rBuff.copy(splitIdx + 1, other.getRecordBufferPage().getRecordBuffer(), 0, moveLen) ; rBuff.clear(splitIdx + 1, moveLen) ; rBuff.setSize(splitIdx + 1) ; if ( CheckingNode ) { if ( !Record.keyEQ(r, maxRecord()) ) { System.err.println(rBuff) ; System.err.println(other.rBuff) ; error("BPTreeRecords.split: Not returning expected record") ; } } return other ; }
private RecordRangeIterator(int id, Record fromRec, Record toRec, RecordBufferPageMgr pageMgr, RecordMapper<X> mapper) { currentIdx = 0 ; this.pageMgr = pageMgr; this.minRec = fromRec ; this.maxRec = toRec ; this.mapper = mapper ; this.keySlot = new byte[pageMgr.getRecordFactory().keyLength()] ; if ( toRec != null && fromRec != null && Record.keyLE(toRec, fromRec) ) { currentPage = null ; return ; } pageMgr.startRead(); currentPage = pageMgr.getRead(id) ; if ( currentPage.getCount() == 0 ) { // Empty page. close() ; return ; } if ( fromRec != null ) { currentIdx = currentPage.getRecordBuffer().find(fromRec) ; if ( currentIdx < 0 ) currentIdx = decodeIndex(currentIdx) ; } }
@Override public String toString() { StringBuilder str = new StringBuilder(40000) ; str.append(format("Len=%d Max=%d: ", numSlot, bb.limit() / slotLen)) ; // Print active slots as records. for ( int i = 0 ; i < numSlot ; i++ ) { if ( i != 0 ) str.append(" ") ; Record r = _get(i) ; str.append(r.toString()) ; } // // Print empty slots // for ( int i = numSlot*slotLen ; i < maxSlot*slotLen ; i++ ) // { // if ( i != 0 && i%slotLen == 0 ) // str.append(" ") ; // byte b = bb.get(i) ; // str.append(format("%02x", b)) ; // } String s = str.toString() ; return s ; }
@Override public final void checkNode() { if ( !CheckingNode ) return ; if ( rBuff.size() < 0 || rBuff.size() > rBuff.maxSize() ) error("Misized: %s", this) ; for ( int i = 1 ; i < getCount() ; i++ ) { Record r1 = rBuff.get(i - 1) ; Record r2 = rBuff.get(i) ; if ( Record.keyGT(r1, r2) ) error("Not sorted: %s", this) ; } }
public static void scanComparision(List<Record> originaldata, BPlusTree bpt2) { // ** Scan comparisonSetupIndex Iterator<Record> iter1 = originaldata.iterator() ; Iterator<Record> iter2 = bpt2.iterator() ; long count = 0 ; for ( ; iter1.hasNext() ; ) { count++ ; Record r1 = iter1.next(); if ( ! iter2.hasNext() ) error("Deviation: new B+Tree is smaller") ; Record r2 = iter2.next(); if ( ! Record.equals(r1, r2) ) error("Deviation in iteration record %d: %s : %s", count, r1, r2) ; } if ( iter2.hasNext() ) error("New B+Tree larger than original") ; }
public static int recordToInt(Record key) { return Bytes.getInt(key.getKey()) ; }
@Test public void bpt_records_6() { BPTreeRecords bpr = make() ; fill(bpr) ; // No match. assertNull(search(bpr, RecordLib.intToRecord(0x20))) ; Record r = RecordLib.intToRecord(0x32) ; Record r2 = search(bpr, r) ; assertTrue(Record.keyEQ(r, r2)) ; r = bpr.getLowRecord() ; r2 = search(bpr, r) ; assertTrue(Record.keyEQ(r, r2)) ; r = bpr.getHighRecord() ; r2 = search(bpr, r) ; assertTrue(Record.keyEQ(r, r2)) ; bpr.release() ; }
protected static void check(BPTreeRecords bpr) { assertTrue(bpr.getCount() >= 0) ; assertTrue(bpr.getCount() <= bpr.getMaxSize()) ; assertEquals(bpr.getRecordBuffer().getLow(), bpr.getLowRecord()) ; assertEquals(bpr.getRecordBuffer().getHigh(), bpr.getHighRecord()) ; for ( int i = 1 ; i < bpr.getCount() ; i++ ) { Record r1 = bpr.getRecordBuffer().get(i - 1) ; Record r2 = bpr.getRecordBuffer().get(i) ; assertTrue(Record.keyLE(r1, r2)) ; } }
private final String recstr(RecordBuffer records, int idx) { if ( records.isClear(idx) ) return "----" ; Record r = records._get(idx) ; return r.toString() ; }