public static int recordToInt(Record key) { return Bytes.getInt(key.getKey()) ; }
@Override public boolean delete(Record record) { ByteArray x = index.remove(wrap(record.getKey())) ; if ( x == null ) return false ; return true ; }
@Override public Record find(Record record) { ByteArray k = wrap(record.getKey()) ; ByteArray v = index.get(k) ; if ( v == null ) return null ; return record(k, v) ; }
public void insertInto(Record record, ByteBuffer bb, int idx) { check(record); bb.position(idx * slotLen); bb.put(record.getKey(), 0, keyLength); if ( hasValue() && record.getValue() != null ) bb.put(record.getValue(), 0, valueLength); }
/** Search for key in range fromIndex (inclusive) to toIndex (exclusive) */ public int find(Record rec, int fromIndex, int toIndex) { int low = fromIndex ; int high = toIndex - 1 ; byte[] key = rec.getKey() ; // http://en.wikipedia.org/wiki/Binary_search while (low <= high) { int mid = (low + high) >>> 1 ; // int divide by 2 int x = compare(mid, key) ; // System.out.printf("Compare: %d(%s) %s ==> %d\n", mid, // Record.str(get(mid)), Record.str(data), x) ; if ( x < 0 ) low = mid + 1 ; else if ( x > 0 ) high = mid - 1 ; else return mid ; } // On exit, when not finding, low is the least value // above, including off the end of the array. return encodeIndex(low) ; }
@Override public boolean insert(Record record) { Record r = find(record) ; if ( r != null && r.equals(record) ) return false ; index.put(wrap(record.getKey()), wrap(record.getValue())) ; return true ; }
static List<Record> createData(int N, RecordFactory recordFactory) { List<Record> originaldata = new ArrayList<>(N) ; for ( int i = 0; i < N ; i++ ) { Record record = recordFactory.create() ; Bytes.setInt(i+1, record.getKey()) ; if ( recordFactory.hasValue() ) Bytes.setInt(10*i+1, record.getValue()) ; originaldata.add(record) ; } return originaldata ; }
currentIdx++ ; if ( maxRec != null && Bytes.compare(keySlot, maxRec.getKey()) >= 0 ) { close() ; return false ;
r = recordFactory.create(r.getKey()) ;
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) ;